如何解决带有两个单词的tfidf tokenizer始终返回第一个值
我试图用这个语料库创建一个令牌:
from sklearn.feature_extraction.text import TfidfVectorizer
corpus = [["ALZHEIMER'S DISEASE"],["LFACTORY"],["AGING"],["EEG"],["COGNITIVE CONTROL"]]
该语料库有单字和双字短语。 TfidfVectorizer不适用于双词短语,所以我尝试了以下方法:
def identity_tokenizer(text): return text
tfidf = TfidfVectorizer(tokenizer=identity_tokenizer,lowercase=False)
txt_fitted = tfidf.fit(corpus)
尽管我试图使用语料库中的单词,但它总是返回第一个值。
i = 2
print('index: ' + str(i))
feature_name = tfidf.get_feature_names()[i]
print('value in index: ' + feature_name)
a = txt_fitted.transform([feature_name]).toarray()
print('argmax: ' + str(a.argmax()))
print('argmax value: ' + tfidf.get_feature_names()[a.argmax()])
结果:
index: 2
value in index: COGNITIVE CONTROL
argmax: 0
argmax value: AGING
我该怎么办?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。