小编Aks*_*ala的帖子

嵌入时出错:无法将字符串转换为浮点数:'ng'

我正在使用 GloVe 方法进行预训练的词向量。数据包含维基百科数据上的向量。嵌入数据时,我收到错误消息,指出无法将字符串转换为浮点数:'ng'

我尝试浏览数据,但找不到符号“ng”

# load embedding as a dict
def load_embedding(filename):
    # load embedding into memory, skip first line
    file = open(filename,'r', errors = 'ignore')
    # create a map of words to vectors
    embedding = dict()
    for line in file:
        parts = line.split()
        # key is string word, value is numpy array for vector
        embedding[parts[0]] = np.array(parts[1:], dtype='float32')
    file.close()
    return embedding
Run Code Online (Sandbox Code Playgroud)

这是错误报告。请进一步指导我。

runfile('C:/Users/AKSHAY/Desktop/NLP/Pre-trained GloVe.py', wdir='C:/Users/AKSHAY/Desktop/NLP')
C:\Users\AKSHAY\AppData\Local\conda\conda\envs\py355\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is …
Run Code Online (Sandbox Code Playgroud)

python nlp machine-learning glove

2
推荐指数
1
解决办法
4661
查看次数

标签 统计

glove ×1

machine-learning ×1

nlp ×1

python ×1