[英]No such file or directory while working with Glove (Deep learning)
我目前正在尝试从 model 添加从 Glove 嵌入的预加载,并且似乎无法加载手套文本文件来解析它的数据。 我总是收到找不到文件的错误。
我的代码如下:
outname = 'glove.6B.100d.txt'
outdir = './Downloads'
if not os.path.exists(outdir):
os.mkdir(outdir)
fullname = os.path.join(outdir, outname)
def getEmbeddedMatrix(num_words, embedding_size):
embeddings_index = {}
with open(fullname, "r") as file_directory:
for line in file_directory:
values = line.split()
word = values[0]
coefs = np.asarray(values[1:], dtype='float32')
embeddings_index[word] = coefs
embedding_matrix = np.zeros((num_words, embedded_size))
for word, index in imdb.get_word_index.items():
if index >= num_words:
continue
embedding_vector = embeddings_index.get(word)
if embedding_vector is not None:
embedding_matrix[i] = embedding_vector
return embedding_matrix
我得到的错误信息如下:
[Errno 2] No such file or directory: './Downloads/glove.6B.100d.txt'
关于在这里做什么的任何建议? .txt 文件目前在我的下载中,我正在使用 Google Colab
编辑:
我也尝试过执行以下操作,但仍然会引发相同的错误
def getEmbeddedMatrix(num_words, embedding_size):
embeddings_index = {}
File_object = open(r"/Users/______/downloads/glove.6B.100d.txt","r")
with File_object as file_directory:
for line in file_directory:
values = line.split()
word = values[0]
coefs = np.asarray(values[1:], dtype='float32')
embeddings_index[word] = coefs
embedding_matrix = np.zeros((num_words, embedded_size))
for word, index in imdb.get_word_index.items():
if index >= num_words:
continue
embedding_vector = embeddings_index.get(word)
if embedding_vector is not None:
embedding_matrix[i] = embedding_vector
return embedding_matrix
您必须将文本文件上传到 google-colab 的工作文件夹,而不是桌面的下载文件夹。
请参阅此链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.