首先安装依赖:
pip install gensim
训练方法:
from gensim.models import FastText
my_train_text = [
['human', 'interface', 'computer'],
['survey', 'user', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'system'],
['system', 'human', 'system', 'eps'],
['user', 'response', 'time'],
['trees'],
['graph', 'trees'],
['graph', 'minors', 'trees'],
['graph', 'minors', 'survey']
]
model = FastText(vector_size=5, min_count=3) # instantiate
model.build_vocab(my_train_text)
model.train(my_train_text, epochs=10, total_examples=len(my_train_text)) # train
print("单词user的词向量:", model.wv.get_vector('user'))



