question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with NLP manager Export-Import

See original GitHub issue

Describe the bug

If I train/build the NlpManager fresh from scratch with some fixed training phrases, it is working fine ( the results are as expected ). But if i am exporting that agent into JSON file and importing the same, the results of .process method are different depending upon in which order the training phrases are added to the manager ( before exporting ).

To Reproduce

Test 1:

  1. Run nlp-test-export-1.js. It will export the model and create an nlpModel.json file. Also check logs, the response1, response2 should have intent names as email.extraction
  2. Run nlp-test-import.js. It will import the model, process the msg and log the response. Check logs, the response1, response2 should have intent names as None.

Test 2:

  1. Run nlp-test-export-2.js. It will export the model and create an nlpModel.json file. Also check logs, the response1, response2 should have intent names as email.extraction
  2. Run nlp-test-import.js. It will import the model and give log the response. Check logs, the response1, response2 should have intent names as email.extraction.

Conclusion: Bot output is depending upon the order in which training phrases are feeded in the model.

Files

nlp-test-export-1.js

const { NlpManager } = require('node-nlp');
let manager = new NlpManager({ languages: ["en"] });

// SET 1 - not working as expected
manager.addDocument('en', 'number 91919919119', 'number.extraction.test');
manager.addDocument('en', 'price', 'pricing');
manager.addDocument('en', 'pricing?', 'pricing');
manager.addDocument('en', 'what is your pricing?', 'pricing');
manager.addDocument('en', ',', 'random.stuff');
manager.addDocument('en', 'adad', 'random.stuff');
manager.addDocument('en', 'kalda', 'random.stuff');
manager.addDocument('en', 'contact me at %email%', 'email.extraction');
manager.addDocument('en', 'my email is %email%', 'email.extraction');

(async() => {
    await manager.train();

    const response1 = await manager.process('en', 'my email is shantnu@gmail.com');
    const response2 = await manager.process('en', 'contact me at shantnu@gmail.com');
    
    const minified = true;
    const nlpModel = manager.export(minified);
    const fs = require('fs');
    fs.writeFile('nlpModel.json', nlpModel, 'utf8', ()=>{});

    console.log(response1.intent);
    console.log(response2.intent);
})();

nlp-test-export-2.js

const { NlpManager } = require('node-nlp');
let manager = new NlpManager({ languages: ["en"] });

// SET 2 - working fine
manager.addDocument('en', 'number 91919919119', 'number.extraction.test');
manager.addDocument('en', 'what is your pricing?', 'pricing');
manager.addDocument('en', 'pricing?', 'pricing');
manager.addDocument('en', 'price', 'pricing');
manager.addDocument('en', 'my email is %email%', 'email.extraction');
manager.addDocument('en', 'contact me at %email%', 'email.extraction');
manager.addDocument('en', ',', 'random.stuff');
manager.addDocument('en', 'kalda', 'random.stuff');
manager.addDocument('en', 'adad', 'random.stuff');

(async() => {
    await manager.train();

    const response1 = await manager.process('en', 'my email is shantnu@gmail.com');
    const response2 = await manager.process('en', 'contact me at shantnu@gmail.com');
    
    const minified = true;
    const nlpModel = manager.export(minified);
    const fs = require('fs');
    fs.writeFile('nlpModel.json', nlpModel, 'utf8', ()=>{});

    console.log(response1.intent);
    console.log(response2.intent);
})();

nlp-test-import.js

const { NlpManager } = require('node-nlp');
let manager = new NlpManager({ languages: ["en"] });

(async() => {
    const nlpModel = require('./nlpModel.json');
    manager.import(nlpModel);

    const response1 = await manager.process('en', 'my email is shantnu@gmail.com');
    const response2 = await manager.process('en', 'contact me at shantnu@gmail.com');
    
    console.log(response1.intent);
    console.log(response2.intent);
})();

Expected behavior

Since Training phrases are same, .process method should give same results.

Desktop (please complete the following information):

Desktop (please complete the following information):

  • OS: macOS
  • Package version - “4.10.4”
  • Node version - v12.18.4

Additional context

It was not working in my personal project, so after some debugging came to the conclusion that same training phrase added in different order are giving different results.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jesus-seijas-spcommented, Jan 12, 2021

Hello,

What is really happening: The real bug is that the slot filling is not loading correctly, when the slot filling is recovered it recovers the slots, but the property isEmpty is still true. So it does not generate the optional utterance. What is the optional utterance? When you provide a sentence like “my email is blablabla@gmail.com” two utterances are generated: “my email is blablabla@gmail.com” and “my email is %email%”. With this, we have a signature to calculate exact sentences.

So I will fix this one, that is the bug.

But more things:

  • Your corpus is too small and with no so many examples. In this case I recommend you to deactivate the useNoneFeature property
let manager = new NlpManager({ languages: ["en"], nlu: { useNoneFeature: false } });

Because your corpus is so small that this feature is causing noise. Or perhaps I should put it to false by default.

  • Your corpus is using the intent random.stuff it the way that the default fallback intent (None) is defined, so you will have None and random.stuff fighting between them… I suggest to replace random.stuff with None

  • About the order of the intents in the training: this is normal that different sort of items generates different weights on the neural network, in fact, almost every single Neural Network in the world will return to you different scores even training with the same data, because usually they initialize to gaussian noise.

1reaction
jesus-seijas-spcommented, Jan 12, 2021

Hello, try updating to version 4.9.0, it solves the issue with slots and also set the useNoneFeature to false by default.

@jesus-seijas-sp I hope here you are referring to 4.19.0 😃

Yes, sorry, 4.19.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Policy to focus on export, import logistics - The Economic Times
New Delhi: The National Logistics Policy (NLP), notified by the government on Thursday, has proposed to develop a national trade ...
Read more >
How the Finance Industry Is Using the Predictive Power of NLP
The use of natural language processing (NLP) to analyze textual data is opening a whole new frontier for central banks, asset managers% etc....
Read more >
Other Export/Import Options for Business Intelligence
Describes additional options for exporting and importing Business Intelligence elements.
Read more >
Major Challenges of Natural Language Processing (NLP)
Natural language processing limitations & problems – Undertsanding context · Irony and sarcasm · Ambiguity of human language.
Read more >
Export / Import a Folder: /Documentation - LabKey Support
For example, Biologics and Sample Manager folder types are not supported for migration in ... Learn more about sample status export/import in this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found