Giter VIP home page Giter VIP logo

jcrfsuite's Introduction

This is a Java interface for crfsuite, a fast implementation of Conditional Random Fields, using SWIG and class injection technique (the same technique used in 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

<dependency>
  <groupId>com.github.vinhkhuc</groupId>
  <artifactId>jcrfsuite</artifactId>
  <version>0.6.1-TLND</version>
</dependency>

Building

git clone https://github.com/vinhkhuc/jcrfsuite
cd jcrfsuite
mvn clean package

How to use

Model training

import com.github.jcrfsuite.CrfTrainer;
...
String trainFile = "data/tweet-pos/train-oct27.txt";
String modelFile = "twitter-pos.model";
CrfTrainer.train(trainFile, modelFile);

Sequential tagging

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<List<Pair<String, Double>>> 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.

jcrfsuite's People

Contributors

vinhkhuc avatar juharris avatar tanhv90 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.