https://github.com/vinhkhuc/jcrfsuite
Java interface for CRFsuite: http://www.chokkan.org/software/crfsuite/
https://github.com/vinhkhuc/jcrfsuite
crf crfsuite java jni machine-learning nlp
Last synced: 6 months ago
JSON representation
Java interface for CRFsuite: http://www.chokkan.org/software/crfsuite/
- Host: GitHub
- URL: https://github.com/vinhkhuc/jcrfsuite
- Owner: vinhkhuc
- License: apache-2.0
- Created: 2014-02-10T04:55:15.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-08-15T07:12:55.000Z (almost 9 years ago)
- Last Synced: 2025-07-26T06:31:08.378Z (12 months ago)
- Topics: crf, crfsuite, java, jni, machine-learning, nlp
- Language: Java
- Homepage:
- Size: 8.76 MB
- Stars: 43
- Watchers: 6
- Forks: 36
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-java - JCRFsuite
README
This is a Java interface for [crfsuite](http://www.chokkan.org/software/crfsuite/),
a fast implementation of Conditional Random Fields, using SWIG and class
injection technique (the same technique used in [snappy-java](https://github.com/xerial/snappy-java)).
Jcrfsuite provides API for loading trained model into memory and do sequential tagging in memory.
Model training is done via command line interface.
The library is designed for building Java applications for fast text sequential tagging
such as Part-Of-Speech (POS) tagging, phrase chunking, Named-Entity Recognition (NER), etc.
Jcrfsuite can be dropped into any Java web applications and run without problem with JVM's class loader.
### Maven dependency
```xml
com.github.vinhkhuc
jcrfsuite
0.6.1
```
### Building
```bash
git clone https://github.com/vinhkhuc/jcrfsuite
cd jcrfsuite
mvn clean package
```
### How to use
#### Model training
```java
import com.github.jcrfsuite.CrfTrainer;
...
String trainFile = "data/tweet-pos/train-oct27.txt";
String modelFile = "twitter-pos.model";
CrfTrainer.train(trainFile, modelFile);
```
#### Sequential tagging
```java
import com.github.jcrfsuite.CrfTagger;
import com.github.jcrfsuite.util.Pair;
...
String modelFile = "twitter-pos.model";
String testFile = "data/tweet-pos/test-daily547.txt";
CrfTagger crfTagger = new CrfTagger(modelFile);
List>> tagProbLists = crfTagger.tag(testFile);
```
### Example on Twitter Part-Of-Speech tagging
#### Training
To train a POS model from Twitter POS data, run
java -cp target/jcrfsuite-*.jar com.github.jcrfsuite.example.Train data/tweet-pos/train-oct27.txt twitter-pos.model
#### Tagging
To test the trained POS model against the test set, run
java -cp target/jcrfsuite-*.jar com.github.jcrfsuite.example.Tag twitter-pos.model data/tweet-pos/test-daily547.txt
The output should be as follows:
Gold Predict Probability
........................
N N 0.99
P P 1.00
Z ^ 0.59
$ $ 0.97
N N 1.00
P P 0.98
A N 0.80
$ $ 1.00
N N 0.99
U U 1.00
Accuracy = 92.99%
Note that the accuracy might be slightly different than in the above output.
### License
Jcrfsuite is released under the Apache License 2.0. The original crfsuite is distributed under the BSD License.