我需要从文本中获取最流行的ngram。Ngram长度必须介于1到5个单词之间。
我知道如何得到二元模型和三元模型。例如:
bigram_measures = nltk.collocations.BigramAssocMeasures()
finder = nltk.collocations.BigramCollocationFinder.from_words(words)
finder.apply_freq_filter(3)
finder.apply_word_filter(filter_stops)
matches1 = finder.nbest(bigram_measures.pmi, 20)
然而,我发现scikit-learn可以得到不同长度的ngram。例如,我可以得到长度从1到5的ngram。
v = CountVectorizer(analyzer=WordNGramAnalyzer(min_n=1, max_n=5))
但WordNGramAnalyzer现在已被弃用。我的问题是:我如何从我的文本中获得N个最佳的单词搭配,搭配长度从1到5。我还需要获得这个搭配/ngram的FreqList。
我能用nltk/scikit做到这一点吗?我需要从一个文本中获得不同长度的ngram组合?
例如,使用NLTK二元和三元语法,其中许多情况下我的三元语法包括我的位图,或者我的三元语法是更大的四元语法的一部分。例如:
你好我的三元组:你好我的名字
我知道如何从三元语法中排除二元语法,但我需要更好的解决方案。
https://stackoverflow.com/questions/11763613
复制相似问题