搭建LexDecomp环境

来源:互联网 发布:散热器转速控制软件 编辑:程序博客网 时间:2024/05/17 02:06

最近在实验室开始学习NLP和机器学习相关的东西,老师推荐了一篇《sentence similarity learning by lexical decomposition and composition》(pdf),读完后顺便想搭一下lexdecomp的环境,然而过程报了许多错。在此做下记录来自我提醒,如果能帮到各位,不胜荣幸。

本人在Ubuntu 14.04 LTS进行实验,亲测其他版本可能会出错

1.Python3配置

网上有教程,安装完后在终端输入"python3",出现版本号

2.LexDecomp下载

下载LexDecomp


3.第三方库下载

requirements.txt 显示需要下载的第三方库

1)numpy>=1.11

1].安装pip

$ apt-get install python3-dev$ apt-get install python3-pip

2].安装numpy>=1.11

pip3 install numpy

3].检验numpy版本

python3>>>import numpy as tf>>>tf.__version__


2)tensorflow>=0.12.1

sudo pip3 install --upgrade http://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp34-cp34m-linux_x86_64.whl //安装tensorflow-0.12.1
检验tensorflow版本

python3>>>import tensorflow as tf>>>tf.__version__

3)h5py>=2.21

sudo pip3 install cythonsudo apt-get install libhdf5-devsudo pip3 install h5py

检验h5py版本

python3>>>import h5py as tf>>>tf.__version__

4)scikit-learn>=0.18.1

官方的要求

  • Python (>= 2.6 or >= 3.3),
  • NumPy (>= 1.6.1),
  • SciPy (>= 0.9)

pip3 install scipy
pip3 install scikit-learn

检验scikit-learn版本

python3>>>import sklearn as tf>>>tf.__version__


5)nltk>=3.1

pip3 install nltknltk.download()

检验nltk版本

python3>>>import nltk as tf>>>tf.__version__


4.word2vec

1).bin文件

In this example, word2vec vectors pre-trained in Google News were used (availablehere).

2).voc和.npy文件

You can use the scripts in tools directory to get both the NumPy matrix and the vocabulary file from the original word2vec file (.bin).


1] 将.bin文件转换为文本文件

python word2vec2text.py GoogleNews-vectors-negative300.bin GoogleNews-vectors-300d.txt
2]将文本文件转换为.voc和.npy文件

python text2numpy.py GoogleNews-vectors-300d.txt 300

5.其他

按照Lexdecomp github的实验步骤即可模拟实验(验证其模型的两个实验)

若单纯需要计算两个句子的相似度,需要阅读decomp.py和commodel.py。

自行编写python。随后会附上本人写的.py文件