我正在使用如下所示的node-nlp模块。
const { NlpManager } = require('node-nlp');
const manager = new NlpManager({ languages: ['en'] });
// 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("./model.nlp", true);
const response = await manager.process('en', 'I should go now');
console.log(response);
})();
此代码可以生成“ model.nlp”文件,并且效果很好。
但是我想反复训练这个'model.nlp'文件,并再次保存在另一个js文件中。
如何读取model.nlp文件并将其与'.process()一起使用?
非常感谢您阅读它。
答案 0 :(得分:1)
const fs = require('fs');
const { NlpManager } = require('node-nlp');
const data = fs.readFileSync('model.nlp', 'utf8');
const manager = new NlpManager();
manager.import(data);
来源:https://github.com/axa-group/nlp.js/blob/master/docs/v3/nlp-manager.md#importexport