axa-group / nlp.js

An NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Threshold for intent detection

LightYagami200 opened this issue · comments

Is there any way to change threshold/sensitivity for intent detection?

Currently I trained a model on these messages:

// "message.delete" intent
Delete last message by %user%
Delete last %count% messages by %user%
Delete last message in %channel%
Delete last message from %user% in %channel%
Delete last %count% messages from %user% in %channel%

Now any prompt containing the word "message" is marked with "message.delete" intent

Is there any way to change sensitivity so it doesn't mark intents that aggressively?

yeah... this is pretty crucial. i just poked around for an hour trying to find anything, NER has a threshold setting, but it appears no way to set it in Nlp manager... which makes this library useless for my application of passing the message on to a LLM when intent is not recognized.

[WORK-AROUND] result.score on each message ... result.action also exists.
this pattern did the trick to perform a function on intent with fine-tuned score, or define a single variable:
await nlp.process('en', message).then(async result => { const intent = result.intent; const score = result.score; if (intent==='greetings.hello' && score>=0.99) { } else if (intent==='greetings.bye' && score>=0.99) { } else if (intent==='greetings.name' && score>=0.99) { } else if (intent==='weather' && score>=0.99) { } else { //default when intent:none }

this worked for passing the response registered to each intent in corpus:
if (intent!='None' && score>=0.9) { console.log(result.answer); } else { //default intent:none console.log('Message passed to LLM. Awaiting...'); };

There is also an object filled with scores for each intent, which may be checked against any specific intent for the score it ranked in the message. should provide some flexible trigger logic.
result.classifications: [ { intent: 'weather', score: 0.6301063890655614 }, { intent: 'greetings.name', score: 0.3698936109344386 }, { intent: 'greetings.bye', score: 0 }, { intent: 'greetings.hello', score: 0 }

SIDE NOTE: loading just the initial test intents gave lots of false-positives which i resolved by adding more phrases and intents to score against so its less likely anything would score '1'. huggingface has some intent datasets you can extract into corpus for noise or initial intents.