FastText预训练模型是如何读取词向量的?
- 内容介绍
- 文章标签
- 相关推荐
本文共计136个文字,预计阅读时间需要1分钟。
pythonfrom gensim.models import FastText, KeyedVectorsimport pandas as pd
读取数据data=pd.read_excel(level_2_table(1).xlsx)content=data['内容'].valuesaspect=data['1_aspect'].values
输出1_aspect的内容print(aspect)
from gensim.models import KeyedVectors
import pandas as pd
data=pd.read_excel("level_2_table(1).xlsx")
data_neirong=data['内容'].values
data_1_aspect=data['1_aspect'].values
print(data_1_aspect)
FASTTEXTFILE = "wiki-news-300d-1M.vec"
ft_model = KeyedVectors.load_word2vec_format(FASTTEXTFILE)
with open ("1_aspect_vec.txt","a+",encoding="utf-8") as f:
for word in data_1_aspect:
temp_vec=ft_model.get_vector(str(word))
print(temp_vec)
f.write(str(word) + " ")
for i in temp_vec:
f.write(str(i)+" ")
f.write("\n")
f.close()
本文共计136个文字,预计阅读时间需要1分钟。
pythonfrom gensim.models import FastText, KeyedVectorsimport pandas as pd
读取数据data=pd.read_excel(level_2_table(1).xlsx)content=data['内容'].valuesaspect=data['1_aspect'].values
输出1_aspect的内容print(aspect)
from gensim.models import KeyedVectors
import pandas as pd
data=pd.read_excel("level_2_table(1).xlsx")
data_neirong=data['内容'].values
data_1_aspect=data['1_aspect'].values
print(data_1_aspect)
FASTTEXTFILE = "wiki-news-300d-1M.vec"
ft_model = KeyedVectors.load_word2vec_format(FASTTEXTFILE)
with open ("1_aspect_vec.txt","a+",encoding="utf-8") as f:
for word in data_1_aspect:
temp_vec=ft_model.get_vector(str(word))
print(temp_vec)
f.write(str(word) + " ")
for i in temp_vec:
f.write(str(i)+" ")
f.write("\n")
f.close()

