我正在尝试使用 gensim 提供的 word2vec 模型对我的数据集进行矢量化。我面临着 scipy 提出的错误。
from gensim.models import Word2Vec
from nltk.tokenize import word_tokenize
import nltk
nltk.download('punkt')
# Sample sentences
sentences = [
"This is a sample sentence.",
"Word embeddings are cool.",
"I love natural language processing."
]
# Tokenize the sentences
tokenized_sentences = [word_tokenize(sentence.lower()) for sentence in sentences]
# Train the Word2Vec model
model = Word2Vec(sentences=tokenized_sentences, vector_size=100, window=5, min_count=1, workers=4)
# Get the vector representation of a word
word_vector = model.wv['sample']
print("Vector representation of 'sample':", word_vector)
# Get the most similar words to a given word
similar_words = model.wv.most_similar('sample')
print("Words most similar to 'sample':", similar_words)
这是代码。我想对其应用 word2vec 矢量化。
我面临着错误- ImportError:无法从 'scipy.linalg.special_matrices' 导入名称 'triu' (C:\Users\onkar naconda3\lib\site-packages\scipy\linalg\special_matrices.py)
我尝试过使用旧版本(1.10 和 1.12)以及最新版本的 scipy。请帮助我找出解决此错误的方法或建议替代方法。
如果 ImportError: Cannot import name 'triu' from 'scipy.linalg' - Gensim 中的修复对您不起作用,您可能无法在实际活跃的 Python 环境中有效回滚
scipy
版本你的代码。