簡體   English   中英

在Gensim中為我的詞匯計算tf-idf

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

我有一組需要計算tf-idf值的單詞(n-gram)。 這些話是;

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

我的語料庫如下。

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"}

我目前得到的TF-IDF值,我正克myvocabulary使用sklearn如下。

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

但是,我有興趣在Gensim中進行相同的操作。 我在Gensim中遇到的所有例子都是如此。

  1. 僅使用字母組合(也適用於雙字母組和三字母組合)
  2. 為所有單詞計算(我只想為myvocabulary的單詞計算)

因此,請幫助我找出如何在Gensim中完成以上兩件事。

在gensim中,對於字典,應使用gensim.corpora.Dictionary類,查看示例

不幸的是,我們一般不支持ngram,而短語類的單詞僅支持雙字母

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM