axa-group / nlp.js

An NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more
MIT License
6.27k stars 620 forks source link

Using Exported Corpus from NLP.js-App within NLP.js #877

Open briward opened 3 years ago

briward commented 3 years ago

Using Exported Corpus from NLP.js-App within NLP.js

Summary

At the moment we're looking to make use of the NLP.js application (https://github.com/axa-group/nlp.js-app) to train our model via the interface and export it to JSON for external storage. Then, we hope to use this exported Corpus data within a separate NLP.js application (https://github.com/axa-group/nlp.js) to respond to the user(s).

However, we are having difficulty using the exported Corpus data within the separate NLP.js system. It appears that the exported data from the App uses "Brain" as the primary classifier, but when attempting to load this configuration into NLP.js it throws errors.

Simplest Example to Reproduce

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

const corpus = require('./neural-corpus.json');

(async () => {  
  const manager = new NlpManager({ useNeural: 'brain' });

  await manager.import(corpus);

  await manager.train();

  const response = await manager.nlp.process('en', 'Hello');

  console.log(JSON.stringify(response));
})();

Here is the supplied Corpus which was exported from the NLP.js-App (after training) using manager.export();:

neural-corpus copy.json.txt

Expected Behavior

The expected behaviour would be that we could train the data, export it and then use this exported model in the processor (NLP.js NlpManager).

Current Behavior

(node:11966) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined at NluManager.fromJSON (node_modules/@nlpjs/nlu/src/nlu-manager.js:351:38)

Possible Solution

If possible, could you supply us with the correct way to achieve this?

Your Environment

Software Version
nlp.js 4.21.3
node v12.14.0
npm 7.6.0
Operating System Mac OS BigSur v11.12.1
briward commented 3 years ago

Update

I have noticed that the App uses version 3 out of the box, this seems to be the issue I'm having - trying to import a Version 3 Corpus into a Version 4 processor. That said, my problem is solved although it would be interesting to find out if the UI is being updated to use the new V4 of NLP.js?

Thanks!

ninjamoba commented 3 years ago

After a review of the above how do we v4 nlp.js with NLP.js-App?