fasttext训练模型与调用模型的代码
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=8, 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'))
#保存模型
model.save('result.bin', separately=[])
#加载模型
loaded_model = FastText.load('result.bin')
print(loaded_model)