CRF++ is a API that implements Conditional random field technique, it also has a Python API. It is used in one of my projects and I need to install in on server without sudo permission, the author didn’t specify how to do that in detail. So I think it might be helpful to share my experience, here is how to do this:
1. Install Python in home directory
With sudo permission one can easily install Python using one line command, but without that, Python can be installed to, just a little bit trickier, first download the specific version of Python under Python Source Releases, here I chose Python 2.7.10:
There is a configure
script under the unzipped directory and it helps generate make files and check dependencies. If execute:
There will be information like this:
Because without sudo permission one usually can’t write to /usr/local/ dir, so here I changed the prefix, notice you need to mkdir
yourself, configure won’t do that for you:
Then compile python with make files generated:
After the installation, check if success:
If want to set it as the default python version, one need to change the import path in profile(my default profile is .bash_profile
) by add line below:
Then check if success:
2. Install CRF++
First download CRF++ source file from here, I’m using version 0.58. Then go into the unzipped file, install with prefix just as described above:
$HOME/local/CRF++/bin
is where command crf_learn
and crf_test
in, so don’t forget to add local CRF++ bin path in profile file:
Then test if CRF++ is correctly installed:
3. Install CRF++ python API
After both Python and CRF++ is successfully installed, now we can install the python API, first cd
in the python dir under CRF++ install package, and there are files like these:
After reading the file setup.py
script, apparently the auther is using distutils.core.Extension to add the C-Extension files in python, the original code is like this:
However from the document Building C and C++ Extensions with distutils, the default dirs for this setup to find C include files and lib files are /usr/local/include
and /usr/local/lib
so we need to make change the setup.py
file like this:
Then we can run in the directory:
Then for the final step, we need to add our local CRF++ lib to the system shared path so Python can find it, the detailed explanation is in here, but basically, we just need to add this line to our profile:
Then again:
To test if the python API is successfully installed:
That’s it, then you can just explore the usage of CRFPP
happily. :)