CRF++ 條件隨機場訓練,Anaconda的centos環境搭建
一、安裝Anaconda環境(最好到官網下載最新版本)
1、檢視系統的型別:file /sbin/init (檢視系統是32位的,還是64位的,本人是32位的)
2、下載安裝包,並上傳,比如:Anaconda3-5.2.0-Linux-x86.sh
3、安裝命令:bash Anaconda3-5.2.0-Linux-x86.sh
4、配置環境變數:vi /root/.bashrc
如圖:LD_LIBRARY_PATH
1.安裝gcc-c++,# yum install gcc-c++
2.cd到CRF目錄,執行configure ./configure
3.make
編譯的時候,會報一個說是taager.cpp 中 std 中找不到to_string()函式,這個函式是在C++11中才有的特性,可以如下解決:
自己寫一個std::to_string() 首先寫一個 stdtostring.h 檔案:把下面這段程式碼copy到stdtostring.h檔案中儲存
函式程式碼如下:
#ifndef STDTOSTRING_H
#define STDTOSTRING_H
#include <string>
#include <sstream>
using namespace std;
namespace std
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
#endif
把該檔案上傳到/opt/CRF++-0.58目錄中。
編輯 tagger.cpp檔案,標頭檔案處,增加 #include "stdtostring.h",儲存。
編輯 tagger.h 檔案,標頭檔案處,增加 #include "stdtostring.h",儲存。
4.make install 一般都會安裝成功
5.cd CRF++-0.53/example/basenp
6.測試執行 crf_learn template train.data model
7.安裝CRFPP(用於結合python來用)
cd /usr/local/CRF++-0.58/python
python setup.py build
python setup.py install
8.測試CRFPP
python狀態下,import CRFPP 看是否能成功
一般會報:ImportError: libcrfpp.so.0: cannot open shared object file: No such file or directory
原因:crf安裝後該庫檔案生成到了usr/local/lib目錄了,連結到/usr/lib目錄,不然後面裝CRFPP提示找不到
ln -s /usr/local/lib/libcrfpp.so.0 /usr/lib