Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nlpjs/lang-tl

axa-group38.4kMIT4.26.1

Core

readme

NLPjs logo

NLP.js

Coverage Status NPM version NPM downloads Sonarcloud Status Maintainability Rating Reliability Rating Security Rating

If you're looking for the version 3 docs, you can find them here Version 3

"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, multi-language support, and acceptance of similar strings, so the introduced text does not need to be exact.
  • Natural Language Processing Classifier, to classify an utterance into intents.
  • NLP Manager: a tool able to manage several languages, the Named Entities for each language, the utterances, 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 natively supported, 104 languages supported with BERT integration
  • Any other language is supported through tokenization, even fantasy languages

Hybrid bot

New in version 4!

Version 4 is very different from previous versions. Before this version, NLP.js was a monolithic library. The big changes:

  • Now the library is split into small independent packages.
  • So every language has its own package
  • It provides a plugin system, so you can provide your own plugins or replace the existing ones.
  • It provides a container system for the plugins, settings for the plugins and also pipelines
  • A pipeline is code defining how the plugins interact. Usually it is linear: there is an input into the plugin, and this generates the input for the next one. As an example, the preparation of a utterance (the process to convert the utterance to a hashmap of stemmed features) is now a pipeline like this: normalize -> tokenize -> removeStopwords -> stem -> arrToObj
  • There is a simple compiler for the pipelines, but they can also be built using a modified version of javascript and python (compilers are also included as plugins, so other languages can be added as a plugin).
  • NLP.js now includes connectors, a connector is understood to be something that has at least 2 methods: hear and say. Examples of connectors included: Console Connector, Microsoft Bot Framework Connector and a Direct Line Offline Connector (this one allows you to build a web chatbot using the Microsoft Webchat, but without having to deploy anything in Azure).
  • Some plugins can be registered by language, so for different languages different plugins will be used. Also some plugins, like NLU, can be registered not only by language but also by domain (a functional set of intents that can be trained separately)
  • As an example of per-language/domain plugins, a Microsoft LUIS NLU plugin is provided. You can configure your chatbot to use the NLU from NLP.js for some languages/domains, and LUIS for other languages/domains.
  • Having plugins and pipelines makes it possible to write chatbots by only modifying the configuration and the pipelines file, without modifying the code.

TABLE OF CONTENTS

Installation

If you're looking to use NLP.js in your Node application, you can install via NPM like so:

    npm install node-nlp

React Native

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 the internet. You can install it via NPM:

    npm install node-nlp-rn

Some limitations:

  • No Chinese
  • The Japanese stemmer is not the complete one
  • No Excel import
  • No loading from a file, or saving to a file, but it can still import from JSON and export to JSON.

Example of use

You can see a great example of use in the folder /examples/02-qna-classic. 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 being trained again.

You can start to build your NLP from scratch with a few lines:

const { NlpManager } = require('node-nlp');

const manager = new NlpManager({ languages: ['en'], forceNER: true });
// Adds the utterances and intents for the NLP
manager.addDocument('en', 'goodbye for now', 'greetings.bye');
manager.addDocument('en', 'bye bye take care', 'greetings.bye');
manager.addDocument('en', 'okay see you later', 'greetings.bye');
manager.addDocument('en', 'bye for now', 'greetings.bye');
manager.addDocument('en', 'i must go', 'greetings.bye');
manager.addDocument('en', 'hello', 'greetings.hello');
manager.addDocument('en', 'hi', 'greetings.hello');
manager.addDocument('en', 'howdy', 'greetings.hello');

// Train also the NLG
manager.addAnswer('en', 'greetings.bye', 'Till next time');
manager.addAnswer('en', 'greetings.bye', 'see you soon!');
manager.addAnswer('en', 'greetings.hello', 'Hey there!');
manager.addAnswer('en', 'greetings.hello', 'Greetings!');

// Train and save the model.
(async() => {
    await manager.train();
    manager.save();
    const response = await manager.process('en', 'I should go now');
    console.log(response);
})();

This produces the following result in a console:

{ utterance: 'I should go now',
  locale: 'en',
  languageGuessed: false,
  localeIso2: 'en',
  language: 'English',
  domain: 'default',
  classifications:
   [ { label: 'greetings.bye', value: 0.698219120207268 },
     { label: 'None', value: 0.30178087979273216 },
     { label: 'greetings.hello', value: 0 } ],
  intent: 'greetings.bye',
  score: 0.698219120207268,
  entities:
   [ { start: 12,
       end: 14,
       len: 3,
       accuracy: 0.95,
       sourceText: 'now',
       utteranceText: 'now',
       entity: 'datetime',
       resolution: [Object] } ],
  sentiment:
   { score: 1,
     comparative: 0.25,
     vote: 'positive',
     numWords: 4,
     numHits: 2,
     type: 'senticon',
     language: 'en' },
  actions: [],
  srcAnswer: 'Till next time',
  answer: 'Till next time' }

False Positives

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 to 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 never been 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 by setting the useNoneFeature to false:

const manager = new NlpManager({ 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 to the console:

const nlpManager = new NlpManager({ languages: ['en'], nlu: { log: true } });

Or you can provide your own log function:

const logfn = (status, time) => console.log(status, time);
const nlpManager = new NlpManager({ languages: ['en'], nlu: { log: logfn } });

Contributing

You can read the guide for how to contribute at Contributing.

Contributors

Contributors

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 opensource@axa.com

License

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.

changelog

Changelog

All notable changes to release of this project will be documented in this file.

For detailed change-info on the commit level please see our GitHub commit history.

[3.10.0] - 2019-10-07

Added

  • Traverse for handlebars, so answers now can be arrays or objects
  • Automatic stemmer: is able to learn rules from languages without stemmer when the languages are inflected.
  • Tests of the automatic stemmer in polish
  • Spell checking: now users can write with small typos
  • Changelog
  • Portuguese sentiment analysis
  • Contributor pictures to the readme
  • Bengali sentiment analysis

Changed

  • Faster Levenshtein implementation
  • Now the browser version is generated with terser

Fixed

  • Extended NER to support datetimerange
  • Sort classifications in the NER manager
  • Use performance.now instead of process.hrtime for browser compatibility

[3.9.0] - 2019-09-15

Added

  • Support for Ukrainian language
  • Duckling support

Changed

  • General code cleanup removing dead & unused code from the project
  • Dependencies have been updated
  • README.md has been updated

Fixed

  • now using url.parse instead of new URL due to support of node version 8

[3.8.0] - 2019-09-12

Added

  • Support for Bengali language
  • Support for Greek language

[3.7.2] - 2019-09-07

Added

  • Support for Thai language

[3.7.1] - 2019-09-07

Added

  • Added examples for huge training (10k intents) and benchmark (Corpus50)

[3.7.0] - 2019-09-05

Added

  • Improved false-positive avoidance
  • Training of huge datasets is now feasible

[3.5.2] - 2019-08-20

Added

  • English tokenizer has been improved

Changed

  • Dependencies have been updated
  • Package lockfile (JS) has been updated
  • README.md has been updated

Fixed

  • Various typos in the documentation
  • Bugs regarding contraction

[3.5.1] - 2019-08-09

Added

  • Model sizes has been significantly reduced

[3.5.0] - 2019-08-09

Added

  • Emoji support 🥳
  • Sentiment analysis for the following languages: Finish, Danish, Russian
  • Added a "default" sentiment analysis

Changed

  • Documentation has been updated

[3.4.0] - 2019-07-24

Added

  • Added a default intent and score when score is less than threshold
  • Now uses decay learning rate

Changed

  • Updated license in documentation
  • Removed handlebars dependency
  • Dependencies have been updated
  • Adjustments to tests

[3.2.1] - 2019-07-16

Fixed

  • Fixed an error that occured when retrieving entites from whitelist

[3.1.1] - 2019-05-06

Changed

  • General performance update. Increaed performance over 3.1.0

[3.1.0] - 2019-05-05

Added

  • Actions
  • Japanase language stemmer

Changed

  • Now builds in node v12
  • Dependencies have been updated
  • Tweaked hyperparameters for best performance

Fixed

  • Issues with NLP Util tests have been fixed

[3.0.2] - 2019-04-19

Fixed

  • "is Alphanumeric" should now work with all most commonly used charsets

[3.0.1] - 2019-04-17

Added

  • The language guesser is now trained with the trigrams from the utterances used to train. That means that it has a best guess, and also that fictional languages can be guessed (example, klingon).
  • Added Tagalog and Galician languages.

Changed

-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 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.
  • Size of the model.nlp files is decreased, the console-bot example went from 1614KB down to 928KB.
  • The browser version has decreased from 5.08MB down to 2.3MB

[2.5.2] - 2019-03-26

Added

  • Added multiple different score calculation methods when combining LRC and Neural

Changed:

  • Default threshold (ner-manager) is now 0.8

[2.5.1] - 2019-03-07

Added

  • Reduced the filesizes of our sentiment resorces

Changes

  • Updated dependencies
  • Fixed issues with getter

[2.4.1] - 2019-01-30

Changed

  • Moved to brain.js version 1.6.0
  • Minimized the browser bundle

[2.4.0] - 2019-01-25

Added

  • Support for "any" language
  • Better documentation regarding language support

Fixed

  • NLU benchmark run

[2.3.2] - 2019-01-22

Fixed

  • Fixed a bug in the load/export and classification behaviour

[2.3.1] - 2019-01-10

Changed

  • Moved to using a non-blocking trainAsync, preventing the event loop from being blocked
  • Updted dependencies
  • LRC has been removed from the list of supported classifiers
  • Updated the classifier, manager & recognizer tests

Fixed

  • Fixed a bug where an error would be thrown when attempting to read the content's length in several stemmers
  • Fixed various prettifier bugs

[2.3.0] - 2018-11-26

Added

  • Test cases for the English aggresive tokenizer
  • Smoth tests for the bayes classifier
  • Now includes normalization tests for the following tokenizers: fr, it, nl, no, pl

Changed

  • Recognizer now recognizes microsoft bot framework v4 contexts

Fixed

  • Fixed bug prventing tests with istanbul frontend parts from running
  • English stemmer is now always the default alternative stemmer
  • English natural stemmer now always uses english aggresive tokenizer
  • Fixed contractions in the English tokenizer

[2.1.2] - 2018-10-28

Added

  • Naive Bayes Classifier

Fixed

  • Minor bugfixes in slot manager
  • Fixed fails in the language guesser for the chinese language

[2.1.0] - 2018-10-12

Added

  • Documentation for context, import and export
  • Added new Binary Relevance Neural Network Classifier

[2.0.4] - 2018-10-06

Added

  • Basic benchmarking support
  • Codebase now has precommit hooks
  • Created stemmers and tokenizers from Natural

Changed

  • NLP Classifier Train interface is now async
  • Removed Natural

[2.0.3] - 2018-10-03

Added

  • Built-in exctraction for Chinese
  • Built-in exctraction for Japanese
  • Documentation for Tamil language support
  • npmignore no longer uploads docs or testing model.nlp
  • Documentation for built-in entity extraction
  • Method for entity extraction without intent recognition in NLP Manger

Changed

  • Upgraded Microsoft recognizer to version 1.1.3
  • Tests changed from French to English

[2.0.2] - 2018-09-22

Added

  • Tamil & Armenian language support

[2.0.1] - 2018-09-21

Added

  • Catalan language
  • Arabic stemmer & documentation

Fixed

  • Errors affecting certain German stems

[2.0.0] - 2018-09-18

Added

  • Load and Save Trim Entities
  • Adding coveralls to the repo
  • Slot Filling
  • Microsoft Bot Framework Recognizer with Slot Filling