如何在 .npy 文件中加载预先训练的词嵌入

问题描述 投票:0回答:1

我正在尝试使用斯坦福 NLP 团队在 HistWords Project 中预先训练的单词嵌入。但是当我从 GitHub 网站运行文档 example.py 时,出现错误: ModuleNotFoundError: No module named 'representations.sequentialembedding'。 我该如何解决这个问题?

我已经安装了“表示”模块,但它不起作用。预训练的词嵌入是“.npy”格式,有没有基于Python的方法来上传它们?

python nlp word-embedding
1个回答
0
投票

要进行设置,您可以在 shell 中执行以下操作:

cd <path you want to store your project>
git clone https://github.com/williamleif/histwords.git
cd histwords

# ----- Set up Python2.7 -----
## Python2.7 via conda is quite easy
conda create -y -n <env_name> python=2.7
conda activate <env_name>

## Else install/locate a python 2 version
### Check python -V (maybe its python2.7)
### Maybe you have python2 or python2.7 executables
### On linux you could look for ls /usr/bin/python* 
python2 -m venv <env_name>
source <env_name>/bin/activate # if you use linux
bin/Scripts/activate # on Windows

# ---- Now with Python2.7 ----
pip install -r requirements.txt

# ---- Download & Move your embedding from https://nlp.stanford.edu/projects/histwords/
# to embeddings/<category> subfolders

python examples.py
# Outputs the similarities
© www.soinside.com 2019 - 2024. All rights reserved.