读取https://github.com/Embedding/Chinese-Word-Vectors中的中文词向量时,选择了一个有3G多的txt文件,之前在做词向量时用的是word2vec,所以直接导入模型然后indexword即可。
因为这是一个txt大文件,尝试了DataFrame,np.loadtxt等,都没有成功,其中主要遇到的问题是:
如何读取完整的大文件,而不会出现内存不足memery error等问题
将读取出来的文件,保存为npy文件
根据词找到对应的向量
解决办法:
尝试使用的代码:
代码1:
try:
lines=np.loadtxt(filepath)
catch:
感觉这块不会写了咦,,,
print(ValueError)
但这样的话,它就不会继续循环去读上边的txt了呢
代码2:
lines=[]
with open(filepath) as f:
for line in f:
lines.append()
np.save(filepath,lines)
代码3
def readEmbedFile(embedFile):
# embedId = {}
# input = open(embedFile,'r',encoding="utf-8")
# lines = []
# a&