# bag of words in an online configuration, for classification / clustering

I have a set of image documents. I extract text keywords from this images using OCR to represent each image as a bag of words (a vector where each value is the number of occurrence of a word in the document). Then I can apply a classification or clustering algorithm on the obtained dataset.

However, this vector representation as bag of words is possible only if I have the entire set of documents (to be able to have the entire vocabulary, i.e. all words). How can I do that (i.e. extract my bag of words) if I'm in an online configuration (using an online clustering) where the documents are available one by one (for a data stream) and each document should be processed as soon as it is available ?

If you use sparse vector formats, it should not be a problem to add new dimensions later on. In sparse vectors, unset dimensions default to 0, usually. Since that is "word not present" it should be fine.

So, have you tried it? Where exactly does the problem arise?

• Is there any other formats for bag of words than the "sparse vector formats" ? If I add a new dimension each time I find a new word, we will have an unbounded dimensionality. is it possible to dynamically keep only the significant words, as we go ?
– shn
Oct 30, 2012 at 15:43
• Why do you need a finite dimension for a sparse vector format? Oct 30, 2012 at 15:49
• Because the classical distances become weakly discriminant when we have a highly multidimensional and sparse data
– shn
Oct 30, 2012 at 15:57
• Pretending that you have fewer dimensions does not change this at all. It does not actually change the distance values if you leave away zeros! Plus, you can keep a global list of dimensions to skip, i.e. project your data to some subspace. This does not at all collide with sparse vectors. Oct 30, 2012 at 16:00
• Ok, then I'll use sparse vector format. Another question would be: is it more difficult (compared with low dimensional dense data) to learn a distance metric function (say a vector of weights for a weighted euclidean distance) using some labelled data, when the data-points are actually bag of words (multidimensional and sparse vectors) ?
– shn
Oct 30, 2012 at 18:17