简体   繁体   English

在Gensim中为我的词汇计算tf-idf

[英]Calculate tf-idf in Gensim for my vocabulary

I have a set of words (n-grams) where I need to calculate tf-idf values. 我有一组需要计算tf-idf值的单词(n-gram)。 These words are; 这些话是;

myvocabulary = ['tim tam', 'jam', 'fresh milk', 'chocolates', 'biscuit pudding']

My corpus looks as follows. 我的语料库如下。

corpus = {1: "making chocolates biscuit pudding easy first get your favourite biscuit chocolates", 2: "tim tam drink new recipe that yummy and tasty more thicker than typical milkshake that uses normal chocolates", 3: "making chocolates drink different way using fresh milk egg"}

I am currently getting tf-idf values for my n-grams in myvocabulary using sklearn as follows. 我目前得到的TF-IDF值,我正克myvocabulary使用sklearn如下。

tfidf = TfidfVectorizer(vocabulary = myvocabulary, ngram_range = (1,3))
tfs = tfidf.fit_transform(corpus.values())

However, I am interested in doing the same in Gensim. 但是,我有兴趣在Gensim中进行相同的操作。 Forall the examples I came across in Gensim; 我在Gensim中遇到的所有例子都是如此。

  1. uses only unigrams ( iwant it for bigrams and trigrams as well) 仅使用字母组合(也适用于双字母组和三字母组合)
  2. calculated for all the words (I only want to calculate for the words in myvocabulary ) 为所有单词计算(我只想为myvocabulary的单词计算)

Hence, please help me to find out how to do the above two things in Gensim. 因此,请帮助我找出如何在Gensim中完成以上两件事。

In gensim, for a dictionary, you should use gensim.corpora.Dictionary class, look at examples 在gensim中,对于字典,应使用gensim.corpora.Dictionary类,查看示例

Unfortunately, we have no support ngrams in general, only bigrams for words with Phrases class 不幸的是,我们一般不支持ngram,而短语类的单词仅支持双字母

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM