"NLP.js" is a general natural language utility for nodejs. Currently supporting:
- Guess the language of a phrase
- Fast levenshtein distance of two strings
- Search the best substring of a string with less levenshtein distance to a given pattern.
- Get stemmers and tokenizers for several languages.
- Sentiment Analysis for phrases (with negation support).
- Named Entity Recognition and management, multilanguage, and accepting similar strings, so the introduced text does not need to be exact.
- Natural Language Processing Classifier, to classify utterance into intents.
- Natural Language Generation Manager, so from intents and conditions it can generate an answer.
- NLP Manager: a tool able to manage several languages, the Named Entities for each language, the utterance, and intents for the training of the classifier, and for a given utterance return the entity extraction, the intent classification and the sentiment analysis. Also, it is able to maintain a Natural Language Generation Manager for the answers.
- 40 languages with stemmers supported: Arabic (ar), Armenian (hy), Bengali (bn), Basque (eu), Catala (ca), Chinese (zh), Czech (cs), Danish (da), Dutch (nl), English (en), Farsi (fa), Finnish (fi), French (fr), Galician (gl), German (de), Greek (el), Hindi (hi), Hungarian (hu), Indonesian (id), Irish (ga), Italian (it), Japanese (ja), Korean (ko), Lithuanian (lt), Malay (ms), Nepali (ne), Norwegian (no), Polish (pl), Portuguese (pt), Romanian (ro), Russian (ru), Serbian (sr), Slovene (sl), Spanish (es), Swedish (sv), Tagalog (tl), Tamil (ta), Thai (th), Turkish (tr), Ukrainian (uk)
- Any other language is supported through tokenization, even fantasy languages
New in version 3!
The version 3 comes with some important changes, mainly focused on improving performance:
- NlpClassifier no longer exists, in favor of NluManager as the manager of several NLU classes, and is able to manage several languages and several domains inside each language.
- Now by default, each domain of a language has it's own neural network classifier. When a language has more than 1 domain, a master neural network is trained that instead of classifying into the intent, classify into de domain. That way the models are faster to train and have a better score.
- The language guesser is now trained with the trigrams from the utterances used to train. That means that has the best guessing, and also that non-existing languages are guessed (example, klingon).
- Added Tagalog and Galician languages.
- The console-bot example training time in version 2.x in my laptop was 108 seconds, in the version 3.x the training time went down to 3 seconds, so the improvement in performance is notable.
- Also the size of the model.nlp files are decreased, the console-bot example went from 1614KB down to 928KB.
- The browser version has decreased from 5.08MB down to 2.3MB
TABLE OF CONTENTS
- React Native
- Example of use
- False Positives
- Log Training Progress
- Language Support
- Language Guesser
- Similar Search
- NER Manager
- Integration with Duckling
- Builtin Entity Extraction
- Sentiment Analysis
- NLP Manager
- Slot Filling
- Loading from Excel
- Microsoft Bot Framework
- Code of Conduct
- Who is behind it
If you're looking to use NLP.js in your node application, you can install via NPM like so:
npm install node-nlp
There is a version of NLP.js that works in React Native, so you can build chatbots that can be trained and executed on the mobile even without internet. You can install it via NPM:
npm install node-nlp-rn
- No Chinese
- Japanese stemmer is not the complete one
- No excel import
- No load from file neither save to file, but it still has import form json and export to json.
Example of use
You can see a great example of use at the folder
/examples/console-bot. This example is able to train the bot and save the model to a file, so when the bot is started again, the model is loaded instead of trained again.
You can start to build your NLP from scratch with few lines:
const NlpManager = ;const manager = languages: 'en' ;// Adds the utterances and intents for the NLPmanager;manager;manager;manager;manager;manager;manager;manager;// Train also the NLGmanager;manager;manager;manager;// Train and save the model.asyncawait manager;manager;const response = await manager;console;;
This will show this result in console:
By default, the neural network tries to avoid false positives. To achieve that, one of the internal processes is that words never seen by the network, are represented as a feature that gives some weight into the None intent. So if you try the previous example with "I have to go" it will return the None intent because 2 of the 4 words have been never seen while training. If you don't want to avoid those false positives, and you feel more comfortable with classifications into the intents that you declare, then you can disable this behavior with the useNoneFeature setting to false:
const manager = languages: 'en' nlu: useNoneFeature: false ;
Log Training Progress
You can also add a log progress, so you can trace what is happening during the training. You can log the progress into console:
const nlpManager = languages: 'en' nlu: log: true ;
Or you can provide your own log function:
const logfn = console;const nlpManager = languages: 'en' nlu: log: logfn ;
You can read the guide of how to contribute at Contributing.
Made with contributors-img.
Code of Conduct
You can read the Code of Conduct at Code of Conduct.
Who is behind it
This project is developed by AXA Group Operations Spain S.A.
If you need to contact us, you can do it at the email firstname.lastname@example.org
Copyright (c) AXA Group Operations Spain S.A.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.