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

Slot filling takes anything as missing entities #421

Open vccortez opened 4 years ago

vccortez commented 4 years ago

Describe the bug I added a regex entity to an NlpManager instance and some documents to capture this entity in a sentence. This is working as expected, however, once I add a slot filler (with manager.slotManager.addSlot), the process function will take any follow up text as an entity to fill the slot with high accuracy, even if the word (or sentence) has nothing to do with the regex for the entity. I have also tested this with a named entity and the slot filling also ignores the named options.

To Reproduce Steps to reproduce the behavior:

  1. Try this MWE:
    
    const { NlpManager, ConversationContext } = require('node-nlp')
    const readline = require('readline')
    const ri = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false })

const languages = ['en'] const m = new NlpManager({ languages })

m.addNamedEntityText('action', 'kick', languages, ['kick', 'to kick']) m.addNamedEntityText('action', 'ban', languages, ['ban', 'to ban']) m.addRegexEntity('member', languages, /@[0-9]+/g)

m.addDocument('en', 'I want to %action% %member%', 'member.act') m.addDocument('en', 'I wanna %action% %member%', 'member.act') m.addDocument('en', '%action% %member%', 'member.act')

m.addAnswer('en', 'member.act', 'confirm {{action}} on {{member}}?')

m.slotManager.addSlot('member.act', 'member', true, { en: 'who should I {{action}}?', }) m.slotManager.addSlot('member.act', 'action', true, { en: 'what shoud I do to {{member}}?', })

async function main() { await m.train() m.save() console.log('you may type now') const context = new ConversationContext() ri.on('line', async (line) => { if (line == 'quit') process.exit() console.log('> ' + line) try { const response = await m.process(null, line, context) console.log('BOT:', JSON.stringify(response, null, 2)) } catch (err) { console.error(err) process.exit() } }) }

main()

2. Input the following:

I want to ban someone kick


3. Check out the `"entities"` object, you should see the correct `action` of ban, kick, and an incorrect `member` kick;  
4. The wrong answer will be `"confirm kick on kick?"`.

**Expected behavior**
I expect the slot filling logic to at least obey the same entity matching that each entity defines. And to be fair, we can observe the `"classifications"` object of the reproducing example and see that in fact the model is matching the correct entities. So, why is the slot filler ignoring that?

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
 - OS: Ubuntu 18.04
 - Browser: not applicable.
 - Version: 3.10.2

**Additional context**
Add any other context about the problem here.
obaid commented 4 years ago

Any update on this? I am running into the same issue.

Gauhar commented 4 years ago

Is there any update on this issue? Any ETA on this one at least?

Gauhar commented 3 years ago

@jesus-seijas-sp - we are blocked by this issue, is there ETA on the the fix for this issue? thanks in advance

igoruehara123 commented 2 years ago

Did you have any corrections regarding this?

Apollon77 commented 2 years ago

This is a fallback logic. In fact the second answer do not contain anything which is matched and also no "member" entity was found. Thats why the slot filling logic just uses the full input as "the answer" for the currently expecting slot entry.

One idea could be to allow this behaviour to be configured. Then it would fallback to the same question again.