GithubHelp home page GithubHelp logo

fquirin / java-nlu-tools Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 5.0 45 KB

Java tools to do natural language processing like NER and intent classification on short sentences

License: MIT License

Java 100.00%
natural-language-processing conditional-random-fields maximum-entropy named-entity-recognition intent-classification

java-nlu-tools's Introduction

Java NLU Tools

Java tools to do natural language processing like NER and intent classification on short sentences.
These tools provide an abstraction layer to MALLET: A Machine Learning for Language Toolkit (Common Public License) and Apache OpenNLP (Apache License Version 2.0). Stanford CoreNLP is supported as well but due to their GPL license it is implemented as plugin.

How to

All training data can be stored in a common, easy to read file with the following format:

How is the weather? --- O O O O --- WEATHER
How's the weather in Berlin? --- O O O O LOCATION --- WEATHER
I need a taxi --- O O O O --- TAXI_SERVICE
I need a cap to go to Pier 39 --- O O O O O O O LOCATION LOCATION --- TAXI_SERVICE
...

Each line starts with a sentence in raw format followed by labels that are used to extract named entities and an intent connected to the sentence. Each part is separated by 3 dashes with space " --- ". The default label for unnamed words (tokens) is "O", labels can be chosen as you like. The more sentences you have the better, but 15 per intent and named-entity should be fine for testing.

To start training your model first choose your toolkit and extract the data to the required format:

//Import training data from compact custom format
Collection<CompactDataEntry> trainData = CustomDataHandler.importCompactData(compactTrainDataFile);

//Declare a tokenizer for our model
Tokenizer tokenizer = new RealLifeChatTokenizer("", "", "");

//Store train data for OpenNLP intent classification
CompactDataHandler cdh = new OpenNlpDataHandler();
List<String> trainDataLines = cdh.importTrainDataIntent(trainData, tokenizer, null);
CustomDataHandler.writeTrainData(trainFile, trainDataLines);

Then you can start training:

//Start training with intent trainer
IntentTrainer trainer = new OpenNlpIntentTrainer(null, trainFileBase, modelFileBase, languageCode);
trainer.train();

To test your model load it in a new classifier and call it like this:

IntentClassifier ic = new OpenNlpIntentClassifier(modelFileBase, tokenizer, languageCode);
Collection<IntentEntry> intentResults = ic.analyzeSentence(sentence);
IntentEntry bestResult = IntentEntry.getBestIntent(intentResults);
String bestIntent = bestResult.getIntent();
double bestCertainty = bestResult.getCertainty();

Check out the examples for each toolkit to get a complete overview of the export-train-test procedure.

java-nlu-tools's People

Contributors

fquirin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

java-nlu-tools's Issues

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.