I have a model of a text document: Doc (content: String, title: String, date: Long, geo: array[String], persons: array[String], ...)

I need to represent this model as a vector for clustering.

How to do a feature extraction of a document for representing it as a sparse vector?


1 Answer 1


WOW, it seems that there are several different data types. If I would do it, based my experience, firstly I would go through all the data points to build a feature list for the discrete features. Here except 'date', those features are all discrete features.
And there are a lot of ways to extract the feature. The common one is like the "n-gram feature". You should choose your way depending on your task and data types. Say your 'content' is one sentence 'ten army officers were sentenced to death'. Then the unigram feature is like "content-ten, content-army,content-officers,..." Here we use the prefix because there may be same words in the other kind of data like "title". But the words in "title" and "content" should be different feature. But I don't suggest using unigram for all the typs of data. I don't think that the "persons" broken down to single words has any meaning.
After you finished the feature list. You could represent each document with a large sparse vector. Each element in the vector represent one feature in the feature list. Once you meet a new data points, use the same way as when you build the feature list to extract the features. Then set the elements representing those features to one otherwise zero. This is called the one-hot representation.
And there is still a data type we haven't resolved.The date is a continuous data. You could find the range for data then scale it to a number between 0-1. For example, the range for date is ten days from 1991-5-1 to 1991-5-11. Then the date 1991-5-6 could be 0.5. The "date" is only one element. You could concatenate this element with the sparse vector.
In fact using one-hot to model document is a traditional method. Now many people use distributed word representation and deep neural netword to model document. For example ,recent paper Recurrent Convolutional Neural Networks for Text Classification. Of course, I think different tasks involve different modelling methods. I can just give some intuitive methods.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.