When the model is trained and loaded into the flow, NLP.js Process can be used to analyse the sentences from the chatbot users.

Train model

Train model

If, for example, the user writes “Turn on lights in the kitchen”, the output of the NLPjs Process will be

{ 
	payload: {   
		type: 'intent,   
		intent: 'switch.on',   
		score: 0.7,   
		isFallback: false,   
		language: 'en',   
		variables: {     
			room: 'kitchen'   
		} 
	}
}

The output of the NLP.js Process node can be chained directly to a Context node to store the extracted variables in the chat context.

Enable the debug option to have an insight of what the NLP model is doing trying to classify the user’s intent, this what is visible in the system console

[NLP] Processing model lights
  Input: "Turn on lights in the kitchen" (en)
  Score threshold: 90 %
  Language guessed: false
  Intent: switch.on
  Domain: default
  Score: 95.0 %
  Sentiment: positive score 50.0 %

Which means that the sentence “Turn on lights in the kitchen” was correctly classified in the intent switch.on using the language en with a probability of 95%. Use the threshold option in the Process node to adjust the sensitivity of NLP.js, if it’s too low it can match sentences not relevant, is it’s too high it could miss sentences that differ a little from the ones entered in the NLPjs Intent node .

The NLPjs Process can also be used standalone to process any kind of string, just put the text in msg.payload. Unless specified in the configuration, the node will try to guess the language from the same text.

Debugging

What to do if it doesn’t match the user sentence? If the NLP.js is not detecting the right intent for some user input (in the example above, suppose the user entered a slightly different utterance “Turn on the lights in my kitchen”):

  1. first check that the context language is the same of the trained model language (trying to classify the above sentence in the “it” language will return nothing)

  2. update the list of utterances in the NLPjs Intent node , more training means more accurate classification, this is the recommended approach

  3. or, check the system console and check the score if the classification, if the detected intent is right but the score is too low, lower the threshold value in the NLP Process node configuration