我的gensim模型是这样的:
class MyCorpus(object):
parametersList = []
def __init__(self,dictionary):
self.dictionary=dictionary
def __iter__(self):
#for line in open('mycorpus.txt'):
for line in texts:
# assume there's one document per line, tokens separated by whitespace
yield self.dictionary.doc2bow(line[0].lower().split())
if __name__=="__main__":
texts=[['human human interface computer'],
['survey user user computer system system system response time'],
['eps user interface system'],
['system human system eps'],
['user response time'],
['trees'],
['graph trees'],
['graph minors trees'],
['graph minors minors survey survey survey']]
dictionary = corpora.Dictionary(line[0].lower().split() for line in texts)
corpus= MyCorpus(dictionary)
自动评估每个文档中每个令牌的频率。
我还可以定义tf-idf模型并访问每个文档中每个令牌的tf-idf统计信息。
model = TfidfModel(corpus)
但是,我不知道如何计算(对内存友好的)给定单词出现的文档数量。我该怎么做? [当然...我可以使用tf-idf的值和文档频率来对其进行评估...但是,我想直接从某些计数过程中对其进行评估]
例如,对于第一个文档,我想得到类似的东西
[('human',2), ('interface',2), ('computer',2)]
因为上述每个令牌在每个文档中出现两次。
第二次。
[('survey',2), ('user',3), ('computer',2),('system',3), ('response',2),('time',2)]
答案 0 :(得分:-1)
怎么样?
calling_all_supers
我假设您所有的字符串都是不同的文档/文件。您可以进行相关更改。此外,更改代码。