【发布时间】:2021-05-13 06:41:27
【问题描述】:
我已经使用我自己的数据集使用 Python 的 sklearn 库拟合了一个 TF-IDF 模型:
tfidf_featuriser = sklearn.feature_extraction.text.TfidfVectorizer(stop_words=None)
tfidf_featuriser.fit(documents)
tfidf_docterm_matrix = tfidf_featuriser.transform(documents)
我正在尝试解决单词类比问题(man::king as woman::queen),因为这可能与 gensim 的 Word2Vec 模型有关。到目前为止,我已经尝试了以下方法:
vec1 = tfidf_docterm_matrix.transpose()[tfidf_featuriser.vocabulary_['man'], :]
vec2 = tfidf_docterm_matrix.transpose()[tfidf_featuriser.vocabulary_['woman'], :]
vec3 = tfidf_docterm_matrix.transpose()[tfidf_featuriser.vocabulary_['king'], :]
vec4 = vec2 + vec3 - vec1
如何检索与 vec4 相似的向量,希望其中一个词向量是“queen”?
【问题讨论】:
标签: python scikit-learn nlp