Comments (9)
Here you go @Jayesh-Patidar! This should work! Try this out.
nlp.slotManager.addSlot('travel', 'fromCity', true, { en: 'From where you are traveling? {{fromCity}}' });
nlp.addDocument('en', 'I want to travel from @fromCity to @toCity', 'travel')
nlp.addNerRuleOptionTexts('en', 'fromCity', ["Israel", "USA"]);
nlp.addNerRuleOptionTexts('en', 'toCity', ["Israel", "USA"]);
nlp.addAnswer('en', 'greetings.hello', 'Greetings!');
await nlp.train();
const response = await nlp.process('en', 'I want to travel from Israel to USA');
console.log(response.entities[1].utteranceText);
Hope this helps 👍
ps; this is due to documentation needing a little better organizing for this project! The method of extracting slots etc - has changed over various versions of NLP.js. But this should work with your version listed in the issue.
from nlp.js.
Thanks for your reply @MarketingPip but in this case too you have defined the list of fromCity
and toCity
. Now the nlp will look for only these two cities but what if I pass anything else. Will that work?
from nlp.js.
@Jayesh-Patidar can you post the full response object of the non working call?
from nlp.js.
Thanks for your reply @MarketingPip but in this case too you have defined the list of
fromCity
andtoCity
. Now the nlp will look for only these two cities but what if I pass anything else. Will that work?
You're more than welcome! My apologizes I should have added another example to help clarify cases where a deemed entity is not defined.
I am on mobile as of right now - and can't confirm but I do think / recall there being somewhere in the documentation a symbol / way to write in your corpus a "empty slot" to be filled.
You'll have to dig deeper / or when I'm on computer later I'll dig into my treasure chest of random code snippets & see if I have anything else similar to last one I provided above. 👆
from nlp.js.
@Apollon77 Below are the responses for my code
Input: My name is John
{ locale: 'en',
utterance: 'My name is John',
settings: undefined,
languageGuessed: false,
localeIso2: 'en',
language: 'English',
nluAnswer: { classifications: [
{ intent: 'saveName', score: 1
},
{ intent: 'sawHero', score: 0
},
{ intent: 'saveDate', score: 0
}
],
entities: undefined,
explanation: undefined
},
classifications: [
{ intent: 'saveName', score: 1
},
{ intent: 'sawHero', score: 0
},
{ intent: 'saveDate', score: 0
}
],
intent: 'saveName',
score: 1,
domain: 'default',
sourceEntities: [],
entities: [],
answers: [
{ answer: 'Nice talking to you {{name}}', opts: undefined
}
],
answer: 'Nice talking to you {{name}}',
actions: [],
sentiment: { score: 0.375,
numWords: 4,
numHits: 1,
average: 0.09375,
type: 'senticon',
locale: 'en',
vote: 'positive'
}
}
Input: I will be traveling on 04 June
{ locale: 'en',
utterance: 'I will be traveling on 04 June',
settings: undefined,
languageGuessed: false,
localeIso2: 'en',
language: 'English',
nluAnswer: { classifications: [
{ intent: 'saveDate', score: 0.9927472726951043
},
{ intent: 'sawHero', score: 0.007252727304895593
}
],
entities: undefined,
explanation: undefined
},
classifications: [
{ intent: 'saveDate', score: 0.9927472726951043
},
{ intent: 'sawHero', score: 0.007252727304895593
}
],
intent: 'saveDate',
score: 0.9927472726951043,
domain: 'default',
sourceEntities: [
{ start: 23,
end: 24,
resolution: { value: '4'
},
text: '04',
typeName: 'number',
entity: 'number'
},
{ start: 23,
end: 29,
resolution: { values: [
{ timex: 'XXXX-06-04', type: 'date', value: '2023-06-04'
},
{ timex: 'XXXX-06-04', type: 'date', value: '2024-06-04'
}
]
},
text: '04 june',
typeName: 'datetimeV2.date',
entity: 'date'
}
],
entities: [
{ start: 23,
end: 24,
len: 2,
accuracy: 0.95,
sourceText: '04',
utteranceText: '04',
entity: 'number',
rawEntity: 'number',
resolution: { strValue: '4', value: 4, subtype: 'integer'
}
},
{ start: 23,
end: 29,
len: 7,
accuracy: 0.95,
sourceText: '04 June',
utteranceText: '04 June',
entity: 'date',
rawEntity: 'datetimeV2.date',
resolution: { type: 'interval',
timex: 'XXXX-06-04',
strPastValue: '2023-06-04',
pastDate: Sun Jun 04 2023 05: 30: 00 GMT+0530 (India Standard Time),
strFutureValue: '2024-06-04',
futureDate: Tue Jun 04 2024 05: 30: 00 GMT+0530 (India Standard Time)
}
}
],
answers: [
{ answer: 'Have safe journey on 04 June', opts: undefined
}
],
answer: 'Have safe journey on 04 June',
actions: [],
sentiment: { score: 0.813,
numWords: 7,
numHits: 3,
average: 0.11614285714285713,
type: 'senticon',
locale: 'en',
vote: 'positive'
}
}
Input: I saw spiderman
{ locale: 'en',
utterance: 'I saw spiderman',
settings: undefined,
languageGuessed: false,
localeIso2: 'en',
language: 'English',
explanation: [
{ token: '', stem: '##exact', weight: 1
}
],
classifications: [
{ intent: 'sawHero', score: 1
},
{ intent: 'saveName', score: 0
},
{ intent: 'saveDate', score: 0
}
],
intent: 'sawHero',
score: 1,
domain: 'default',
optionalUtterance: 'I saw %hero%',
sourceEntities: [],
entities: [
{ start: 6,
end: 14,
len: 9,
levenshtein: 0,
accuracy: 1,
entity: 'hero',
type: 'enum',
option: 'spiderman',
sourceText: 'spiderman',
utteranceText: 'spiderman'
}
],
answers: [
{ answer: 'Really you saw spiderman!', opts: undefined
}
],
answer: 'Really you saw spiderman!',
actions: [],
sentiment: { score: 0.375,
numWords: 3,
numHits: 1,
average: 0.125,
type: 'senticon',
locale: 'en',
vote: 'positive'
}
}
You can clearly see when I passed input as My name is John
then it is not able to extract entities. I want to extract the name John
from then text and return it in response in place of {{name}}
.
Thank you
from nlp.js.
@Jayesh-Patidar - here you go! A full working example of what you need.
import { containerBootstrap } from "https://cdn.skypack.dev/@nlpjs/[email protected]";
import { Nlp } from "https://cdn.skypack.dev/@nlpjs/[email protected]";
import { LangEn } from "https://cdn.skypack.dev/@nlpjs/[email protected]";
(async () => {
const container = await containerBootstrap();
container.use(Nlp);
container.use(LangEn);
const nlp = container.get('nlp');
nlp.settings.autoSave = false;
nlp.addLanguage('en');
nlp.slotManager.addSlot('travel', 'fromCity', true);
nlp.addDocument('en', 'I want to travel from %fromCity% to @toCity', 'travel')
nlp.addNerBetweenLastCondition('en', 'fromCity', 'from', 'to');
nlp.addNerAfterLastCondition('en', 'fromCity', 'from');
nlp.addNerBetweenLastCondition('en', 'toCity', 'to', 'from');
nlp.addNerAfterLastCondition('en', 'toCity', 'to');
nlp.slotManager.addSlot('travel', 'fromCity', true);
nlp.slotManager.addSlot('travel', 'toCity', true);
await nlp.train();
const response = await nlp.process('en', 'I want to travel from here to you go bro!');
console.log(response.entities[0].utteranceText); // Outputs: here
console.log(response.entities[1].utteranceText); // Outputs: you go bro!
})();
Hope this helps.
Ps; you can use Regex matches for extracting slots. But matching anything ie (.*)
- gets the library acting funny.
from nlp.js.
@MarketingPip Thanks for your reply. And sorry for being late
I tried your solution but this time it is working fine and extracting the fromCity
and toCity
entities but now suppose we have an answer for this intent which has these entities then it is not loading the entities in the answer.
const { Nlp } = require('@nlpjs/nlp');
const { LangEn } = require('@nlpjs/lang-en-min');
(async () => {
const container = await containerBootstrap();
container.use(Nlp);
container.use(LangEn);
const nlp = container.get('nlp');
nlp.settings.autoSave = false;
nlp.addLanguage('en');
nlp.slotManager.addSlot('travel', 'fromCity', true);
nlp.addDocument('en', 'I want to travel from %fromCity% to @toCity', 'travel');
nlp.addNerBetweenLastCondition('en', 'fromCity', 'from', 'to');
nlp.addNerAfterLastCondition('en', 'fromCity', 'from');
nlp.addNerBetweenLastCondition('en', 'toCity', 'to', 'from');
nlp.addNerAfterLastCondition('en', 'toCity', 'to');
nlp.slotManager.addSlot('travel', 'fromCity', true);
nlp.slotManager.addSlot('travel', 'toCity', true);
nlp.addAnswer('en', 'travel', 'Happy journey {{fromCity}} to {{toCity}}');
await nlp.train();
const response = await nlp.process('en', 'I want to travel from here to you go bro!');
console.log(response.entities[0].utteranceText); // Outputs: here
console.log(response.entities[1].utteranceText); // Outputs: you go bro!
console.log(response.answer); // Happy journey {{fromCity}} to {{toCity}}
})();
Earlier the syntax of adding answer was working fine for named entities.
Can you please help me out here?
from nlp.js.
For some reason I can't seem to get this working on my end. Tho I would try using some regex matching etc.. and replacing (tho this is inconvenient) - might be a work around until you get a answer from the maintainers of this repo. ie: @axa-group
/// Create a for loop with all your entities.
let entities = response.entities
let replacedText = response.answer
for (let item in entities){
// Regex for example {{.*}}
replacedText = replacedText.replace(regex_for_your_entities, "entity"); // Happy journey {{fromCity}} to {{toCity}}
}
Adjust that code to work with your needs and the proper regex!
Wish I could help you out more but keep in mind I am not a contributor nor maintainer of this project. Hopefully we can get some more input from them.
Maybe a tag / mention will help here - @jesus-seijas-sp
Best of luck tho & have a great weekend @Jayesh-Patidar. ✌️
from nlp.js.
Thanks for your help @MarketingPip. Waiting to listen from someone meanwhile I will try your solution.
from nlp.js.
Related Issues (20)
- ContextData can't be saved and loaded
- Can't run dockStart
- Do not remove dots from utterance in entity recognition HOT 1
- @nlpjs/xtables depends on vulnerable version of xlsx HOT 3
- [QUESTION] How to change the NLP dock logger ? HOT 2
- Bug in extractor-enum.js with original text indexes HOT 1
- Critical dependency: the request of a dependency is an expression HOT 2
- Question - How to run Entity extraction HOT 5
- [Question] How to define epoch & loss threshold? HOT 1
- How to extract date when intent is "What date is today?" HOT 3
- Provide timezone to Duckling API HOT 4
- Is it possible to filter the detection of the intent by the entity type? HOT 1
- Amend sentiment.md HOT 3
- Error when process regex with group
- get score from 1 and not less
- Simple question: can NLP.js be used for the app I describe?
- Can we document nlpmanager options better?
- Is NLP.js still maintained? HOT 11
- Language guess mistakes english for catalan
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nlp.js.