nlp.js icon indicating copy to clipboard operation
nlp.js copied to clipboard

Slot filling takes anything as missing entities

Open vccortez opened this issue 4 years ago • 5 comments

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()
  1. Input the following:
I want to ban someone
kick
  1. Check out the "entities" object, you should see the correct action of ban, kick, and an incorrect member kick;
  2. 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.

vccortez avatar Mar 24 '20 22:03 vccortez

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

obaid avatar Sep 25 '20 04:09 obaid

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

Gauhar avatar Oct 14 '20 14:10 Gauhar

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

Gauhar avatar Nov 13 '20 14:11 Gauhar

Did you have any corrections regarding this?

igoruehara123 avatar Jan 29 '22 00:01 igoruehara123

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.

Apollon77 avatar Aug 08 '22 19:08 Apollon77