【发布时间】:2018-03-21 05:51:27
【问题描述】:
我有一组单词(n-gram),我需要在其中计算 tf-idf 值。这些话是;
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"}
我目前正在使用 sklearn 在myvocabulary 中获取我的 n-gram 的 tf-idf 值,如下所示。
tfidf = TfidfVectorizer(vocabulary = myvocabulary, ngram_range = (1,3))
tfs = tfidf.fit_transform(corpus.values())
但是,我有兴趣在 Gensim 中做同样的事情。对于我在 Gensim 中遇到的所有示例;
- 仅使用一元组(我也希望它用于二元组和三元组)
- 计算所有单词(我只想计算
myvocabulary中的单词)
因此,请帮助我了解如何在 Gensim 中完成上述两件事。
【问题讨论】: