github 地址如下:https://github.com/facebookresearch/DrQA
Ps:(DrQA要求使用python3,因為作者使用的 virtualenv 就是python3娃循,所以讀者在使用python或者pip的時候可以用python3和pip3)
1.下載:git clone https://github.com/facebookresearch/DrQA.git
2.進(jìn)入 DrQA文件夾舆逃,cd DrQA
3.安裝依賴 pip install -r requirements.txt
4 安裝DrQA python setup.py develop
說明:如果讀者事先沒有安裝pytorch可以去官網(wǎng)查找安裝方法
有以下兩種方法比較方便
1: conda方式
? ? ? ? conda install pytorch torchvision cuda80 -c soumith
2: pip方式
? ? ? ? pip install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl
? ? ? ? pip install torchvision
5.安裝stanfordNLP庫(建議使用vpn 不然太慢)
? ? ? ? ./install_corenlp.sh
它會幫我們下載 stanfordnlp 的 jar 包 并配置環(huán)境變量黎休,環(huán)境變量配置在~/.bashrc
檢驗nlp 庫是否安裝好:
? ? ?shell 檢驗:
? ? ? ? ? ?1. 方式一:
? ? ? ? ? ? ? ?vim test.py 輸入以下內(nèi)容:
? ? ? ? ? ? ? ? ? ? from drqa.tokenizers import CoreNLP?
? ? ? ? ? ? ? ? ? ? Tokenizertok=CoreNLPTokenizer()
? ? ? ? ? ? ? ? ? ? print (tok.tokenize('hello world').words() ) #Should complete immediately
? ? ? ? ? ? ? ?保存输钩,并執(zhí)行python test.py
? ? ? ? ? ? ? ?不報錯就成功了床玻。
? ? ? ? ? ? ? ?如果報錯了翼虫,可以執(zhí)行以下執(zhí)令
? ? ? ? ? ? ? ? ? ? cat ~/.bashrc
? ? ? ? ? ? ? ?將里面的內(nèi)容 比如
? ? ? ? ? ? ? ? ? ?export CLASSPATH=$CLASSPATH:/Users/yourpath/*
? ? ? ? ? ? ? ?執(zhí)行一遍
? ? ? ? ? 2.方式二:
? ? ? ? ? ? ? vim test.py 輸入以下內(nèi)容:
? ? ? ? ? ? ? ? ? ? from drqa.tokenizers import CoreNLP
? ? ? ? ? ? ? ? ? ? Tokenizertok=CoreNLPTokenizer(classpath='/Users/yourpath/*')
? ? ? ? ? ? ? ? ? ? ?print (tok.tokenize('hello world').words() ) #Should complete immediately
? ? ? ? ? ? ? ?保存徒像,并執(zhí)行python test.py
? ? ? ? ? ? ? ?其中classpath為下載的jar包的位置
6.下載模型(7.5G 最好也開vpn在aws上,速度非常慢蛙讥,可能會斷,可以多下幾次)
? ? ? ? ? ./download.sh
7.執(zhí)行demo
? ? ? ? ?python scripts/pipeline/interactive.py
然后就可以輸入想要問的問題了灭衷。
比如:
? ? ? ? ?process('What is question answering?')
但是目前不是很支持中文次慢。所以最好用英文。
然后會返回一個答案
? ? ? ? ?answer:a computer science discipline within the fields of information retrieval and natural language processing