Como usar o CountVectorizerand () do sklearn para obter ngrams que incluem qualquer pontuação como tokens separados?
eu usosklearn.feature_extraction.text.CountVectorizer para calcular n-gramas. Exemplo:
import sklearn.feature_extraction.text # FYI http://scikit-learn.org/stable/install.html
ngram_size = 4
string = ["I really like python, it's pretty awesome."]
vect = sklearn.feature_extraction.text.CountVectorizer(ngram_range=(ngram_size,ngram_size))
vect.fit(string)
print('{1}-grams: {0}'.format(vect.get_feature_names(), ngram_size))
saídas:
4-grams: [u'like python it pretty', u'python it pretty awesome', u'really like python it']
A pontuação é removida: como incluí-los como tokens separados?