axa-group / nlp.js

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

SlotFilling no longer works in V4 or documentation is incorrect #702

Closed MattRiddell closed 1 year ago

MattRiddell commented 4 years ago

In the documentation on the home page slot filling is linked to but goes to a document in the v3 folder:

https://github.com/axa-group/nlp.js/blob/master/docs/v3/slot-filling.md

NlpManager no longer contains slotManager or addTrimEntity?

More specifically it says this:

  const manager = new NlpManager({ languages: ['en'] });
  const fromEntity = manager.addTrimEntity('fromCity');
  fromEntity.addBetweenCondition('en', 'from', 'to');
  fromEntity.addAfterLastCondition('en', 'from');
  const toEntity = manager.addTrimEntity('toCity');
  toEntity.addBetweenCondition('en', 'to', 'from', { skip: ['travel'] });
  toEntity.addAfterLastCondition('en', 'to');

  manager.slotManager.addSlot('travel', 'fromCity', true, { en: 'From where you are traveling?' });
  manager.slotManager.addSlot('travel', 'toCity', true, { en: 'Where do you want to go?' });
  manager.slotManager.addSlot('travel', 'date', true, { en: 'When do you want to travel?' });

  manager.addDocument('en', 'I want to travel from %fromCity% to %toCity% %date%', 'travel');
  await manager.train();
  const result = await manager.process('en', 'I want to travel to Madrid tomorrow', {});
  console.log(JSON.stringify(result, null, 2));

The problem is that the slot manager stuff doesn't seem to be in NLPManager anymore so I'm guessing the code has to change?

I saw that by adding %name% in greetings.hello intent such as hello my name is %name% it does get added to the slot manager when I train it, but it doesn't appear to get parsed when I feed it "hello my name is matt".

This is also discussed in #561

MattRiddell commented 4 years ago

Also, if I can understand how this should work I can help update documentation.

I see the code has been split out but don't see how you would combine the slots manager into the above example.

Apollon77 commented 2 years ago

@MattRiddell Did you manage to get slot filling somehow working with v4?

Apollon77 commented 2 years ago

oook ... I got it working ... maybe I find time to post a PR for documentation soon.

In fact all the methods have changed and are now on "nlp" class.

e.g.

And the entities are automatically registered via addDocument, so you just add them using the above methods.

nlp.slotManager.addSlot stays as before.

I just wonder why all these Ner Rules can not also being parsed out of the utterances from addDocument because also here we can see words before, after, in between and such ... nbut I assume this would be a new feature request :-)

Apollon77 commented 2 years ago

new examples and documentation and fixes will be in #1171 and other PRs

aigloss commented 1 year ago

Closing due to inactivity. Please, re-open if you think the topic is still alive.