【发布时间】:2019-01-08 01:16:25
【问题描述】:
我已在此处 (GoogleNews-vectors-negative300.bin.gz) 将 Google 的预训练词嵌入作为二进制文件下载。我希望能够根据一些词汇过滤嵌入。
我首先尝试将 bin 文件加载为 KeyedVector 对象,然后创建一个字典,将其词汇表与另一个词汇表一起用作过滤器。但是,这需要很长时间。
# X is the vocabulary we are interested in
embeddings = KeyedVectors.load_word2vec_format('GoogleNews-vectors-
negative300.bin.gz', binary=True)
embeddings_filtered = dict((k, embeddings[k]) for k in X if k in list(embeddings.wv.vocab.keys()))
运行需要很长时间。我不确定这是否是最有效的解决方案。我应该先在 load_word2vec_format 步骤中过滤掉它吗?
【问题讨论】: