Bag of words model

Share on Facebook Share on Twitter Email
Wikipedia on Answers.com:

Bag of words model

Top

The bag-of-words model is a simplifying assumption used in natural language processing and information retrieval. In this model, a text (such as a sentence or a document) is represented as an unordered collection of words, disregarding grammar and even word order. Recently, the Bag of Words models has also been used for Computer Vision [1].

The bag-of-words model is used in some methods of document classification. When a Naive Bayes classifier is applied to text, for example, the conditional independence assumption leads to the bag-of-words model[2]. Other methods of document classification that use this model are latent Dirichlet allocation[3] and latent semantic analysis.

An early reference to "bag of words" in a linguistic context can be found in Zellig Harris's 1954 article on Distributional Structure.[4]

Contents

Example implementation of BoW model

Text Document Representation based on the BoW model

Here are two simple text documents:

   John likes to watch movies. Mary likes too.
   John also likes to watch football games.

Based on these two text documents, a dictionary is constructed as:

   dictionary={1:"John", 2:"likes", 3:"to", 4:"watch", 5:"movies", 6:"also", 7:"football", 8:"games", 9:"Mary", 10:"too"},

which has 10 distinct words. And using the indexes of the dictionary, each document is represented by a 10-entry vector:

   [1, 2, 1, 1, 1, 0, 0, 0, 1, 1]
   [1, 1, 1, 1, 0, 1, 1, 1, 0, 0],

where each entry of the vectors refers to count of the corresponding entry in the dictionary (This is also the histogram representation). As we can see, this vector representation does not preserve the order of the words in the original sentences. This kind of representation has several successful applications, for example latent Dirichlet allocation.[1]

Example usage: Spam filtering

In Bayesian spam filtering, an e-mail message is modeled as an unordered collection of words selected from one of two probability distributions: one representing spam and one representing legitimate e-mail ("ham"). Imagine that there are two literal bags full of words. One bag is filled with words found in spam messages, and the other bag is filled with words found in legitimate e-mail. While any given word is likely to be found somewhere in both bags, the "spam" bag will contain spam-related words such as "stock", "Viagra", and "buy" much more frequently, while the "ham" bag will contain more words related to the user's friends or workplace.

To classify an e-mail message, the Bayesian spam filter assumes that the message is a pile of words that has been poured out randomly from one of the two bags, and uses Bayesian probability to determine which bag it is more likely to be.

See also

References

  1. ^ Sivic, Josef (April, 2009). "Efficient visual search of videos cast as text retrieval". IEEE TRANSACTIONS ON PATTERN ANALYSIS AND MACHINE INTELLIGENCE, VOL. 31, NO. 4. IEEE. pp. 591 - 605. http://www.di.ens.fr/~josef/publications/sivic09a.pdf. 
  2. ^ Lewis, David (1998). "Naive (Bayes) at Forty: The Independence Assumption in Information Retrieval". Proceedings of ECML-98, 10th European Conference on Machine Learning. Chemnitz, DE: Springer Verlag, Heidelberg, DE. pp. 4–15. http://citeseer.ist.psu.edu/lewis98naive.html. 
  3. ^ Blei, David M.; Andrew Y. Ng and Michael I. Jordan (2003). "Latent Dirichlet Allocation". J. Mach. Learn. Res. (Cambridge, MA: MIT Press) 3: 993–1022. DOI:10.1162/jmlr.2003.3.4-5.993. 
  4. ^ Harris, Zellig (1954). "Distributional Structure". Word 10 (2/3): 146–62. "And this stock of combinations of elements becomes a factor in the way later choices are made ... for language is not merely a bag of words but a tool with particular properties which have been fashioned in the course of its use" 

Post a question - any question - to the WikiAnswers community:

Copyrights: