Parse Text Using NLU Models
Once a model is deployed you would like it to predict the intent and entities given a piece of text that the model has never seen before.
In this article we will walk you through the parse
command, that you can use to access any deployed model and parse text.
Prerequisites
- Getting Started: Make sure to follow Getting Started to login and install the Language Understanding service. If you are using APIs, save your authorization token in a variable called
AUTHORIZATION_TOKEN
before moving ahead. - Create a Project:
- Make sure to create a project and have the project id in a variable called
PROJECT_ID
. - Make sure to have the language for which you added training examples in a variable called
LANGUAGE
.
- Make sure to create a project and have the project id in a variable called
- Add training data: Make sure to have at least two intents with 10 examples each
- Train a model: Train a model using our training API and store the model id in a variable called
MODEL_ID
- Deploy a model: To parse text using a model you need to deploy it first. Make sure to keep it's model id in a variable called
MODEL_ID
Parse Text
- NeuralSpace
- Dialogflow
- Luis
You can parse your model in NeuralSpace's format using the CLI as well as APIs.
- API
This API returns a predicted intent as well as entities for a given text.
Additionally, it returns a ranking of intents in the order of confidence.
Confidence scores are also returned for entities along with the start
and end
character index of the entity in the given text.
curl --location --request POST 'https://platform.neuralspace.ai/api/nlu/v1/model/parse' \
--header 'Accept: application/json, text/plain, */*' \
--header 'Content-Type: application/json;charset=UTF-8' \
--header "Authorization: ${AUTHORIZATION_TOKEN}" \
--data-raw "{
\"modelId\": \"${MODEL_ID}\",
\"text\": \"Sample input text\"
}"
The API returns a json object and all it's fields are described below.
{
"success": true,
"message": "Model parsed successfully",
"timestamp": 1629438536808,
"data": {
"text": "...",
"intent": {
"name": "SOME-INTENT",
"id": 0,
"confidence": 0.9718062281608582
},
"intent_ranking": [
{
"name": "INTENT-1",
"id": 0,
"confidence": 0.9718062281608582
},
{
"name": "INTENT-2",
"id": 1,
"confidence": 0.025485942140221596
},
{
"name": "SOME-OTHER-INTENT",
"id": 2,
"confidence": 0.002707841107621789
}
],
"entities": [
{
"entity": "SOME-ENTITY",
"start": 4,
"end": 9,
"value": "ENTITY-VALUE",
"confidence": 1
},
{
"entity": "ANOTHER-ENTITY",
"start": 35,
"end": 44,
"value": "ENTITY-VALUE",
"confidence": 1
}
]
}
}
This API returns predicted intent and entities for a given text in Dialogflow's format.
curl --location --request POST 'https://platform.neuralspace.ai/api/nlu/v1/model/parse/dialogflow' \
--header 'Content-Type: application/json' \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NDM3MDg4NjMwLCJkYXRhIjp7ImVtYWlsIjoiYWtzaGF0QG5ldXJhbHNwYWNlLmFpIiwicm9sZSI6InByb3ZpZGVyIiwiYXBpa2V5IjoiMTA1NzVjOGItZjc0ZC00MjAzLWI2MmYtNjc1M2FhZWEyYTJmIiwicmVmZXJlbmNlS2V5IjoiMTA1NzVjOGItZjc0ZC00MjAzLWI2MmYtNjc1M2FhZWEyYTJmIiwicGxhblR5cGUiOiJkZWZhdWx0IiwiY291bnRyeSI6IkluZGlhIn0sImlhdCI6MTY0MzcwODUwM30.-vLSY3Y4w6HR0eU7GoT_Xb6-xbpbRcV-ULdAiG8qFcg' \
--data-raw "{
\"modelId\": \"${MODEL_ID}\",
\"text\": \"Sample input text\"
}"
The API returns a json object and all it's fields are described below.
{
"success": true,
"message": "Model parsed successfully",
"timestamp": 1643790457175,
"data": {
"responseId": "a899c159-42ef-4d71-be58-39f7b4f60168",
"queryResult": {
"queryText": "Sample input text",
"action": "SOME INTENT 1",
"parameters": [
{
"start": 46,
"end": 50,
"value": "ENTITY VALUE",
"entity": "SOME ENTITIY",
"confidence": 9.294384002685547
}
],
"fulfillmentText": "",
"fulfillmentMessages": [],
"outputContexts": [],
"intent": {
"name": "SOME INTENT",
"displayName": "SOME INTENT"
},
"intentDetectionConfidence": 0.9597373604774475
}
}
}
This API returns predicted intent and entities for a given text in Luis' format.
curl --location --request POST 'https://platform.neuralspace.ai/api/nlu/v1/model/parse/luis' \
--header 'Content-Type: application/json' \
--header 'Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NDM3MDg4NjMwLCJkYXRhIjp7ImVtYWlsIjoiYWtzaGF0QG5ldXJhbHNwYWNlLmFpIiwicm9sZSI6InByb3ZpZGVyIiwiYXBpa2V5IjoiMTA1NzVjOGItZjc0ZC00MjAzLWI2MmYtNjc1M2FhZWEyYTJmIiwicmVmZXJlbmNlS2V5IjoiMTA1NzVjOGItZjc0ZC00MjAzLWI2MmYtNjc1M2FhZWEyYTJmIiwicGxhblR5cGUiOiJkZWZhdWx0IiwiY291bnRyeSI6IkluZGlhIn0sImlhdCI6MTY0MzcwODUwM30.-vLSY3Y4w6HR0eU7GoT_Xb6-xbpbRcV-ULdAiG8qFcg' \
--data-raw "{
\"modelId\": \"${MODEL_ID}\",
\"text\": \"Sample input text\"
}"
The API returns a json object and all it's fields are described below.
{
"success": true,
"message": "Model parsed successfully",
"timestamp": 1643790619841,
"data": {
"query": "Sample input text",
"prediction": {
"normalizedQuery": "Sample input text",
"topIntent": "SOME INTENT",
"intents": {
"SOME INTENT": {
"score": 0.9597373604774475
},
"ANOTHER INTENT 1": {
"score": -0.13577112555503845
},
"ANOTHER INTENT 2": {
"score": -0.14626465737819672
},
"ANOTHER INTENT 3": {
"score": -0.1698095202445984
},
"ANOTHER INTENT 4": {
"score": -0.20615904033184052
},
"ANOTHER INTENT 5": {
"score": -0.3115690350532532
}
},
"entities": [
{
"role": "",
"type": "ENTITY TYPE",
"text": "ENTITY VALUE",
"startIndex": 46,
"length": 4,
"score": 9.294384002685547,
"modelType": null
}
]
}
}
}
Multilingual Parse Text
- NeuralSpace
Once you have trained an NLU model in any language, you can use this API and test your model any any of the 100+ supported languages.
- API
This API returns a predicted intent as well as entities for a given text.
You can choose not to pass any language preference and the API will figure it out automatically.
Additionally, it returns a ranking of intents in the order of confidence.
Confidence scores are also returned for entities along with the start
and end
character index of the entity in the given text.
You also get a list of predicted languages in case textLanguage
has not been provided.
curl --location --request POST 'https://platform.neuralspace.ai/api/nlu/v1/model/multilingual' \
--header 'Accept: application/json, text/plain, */*' \
--header 'Content-Type: application/json;charset=UTF-8' \
--header "Authorization: ${AUTHORIZATION_TOKEN}" \
--data-raw "{
\"modelId\": \"${MODEL_ID}\",
\"text\": \"Wie installiere ich den Canon MF8000C-Drucker in Ubuntu 15.10?\"
}"
Fields | Optional | Description |
---|---|---|
modelId | false | ID of the NLU model you want to use |
text | false | The text you want to parse |
textLanguage | true | The language in which the text is written. This is an optional parameter and if you have not specified it the API automatically detects the language of the text and calls the NLU model accordingly. Use language code here. |
The API returns a json object and all it's fields are described below.
{
"success": true,
"message": "Model parsed successfully",
"data": {
"detectedLanguage": {
"text": "Wie installiere ich den Canon MF8000C-Drucker in Ubuntu 15.10?",
"detected_languages": [
{
"language": "de",
"confidence": "0.9765741229057312"
},
{
"language": "nl",
"confidence": "0.009382947348058224"
},
{
"language": "bar",
"confidence": "0.005817154422402382"
},
{
"language": "ru",
"confidence": "0.0012884350726380944"
},
{
"language": "fi",
"confidence": "0.0012173647992312908"
}
]
},
"text": "Wie installiere ich den Canon MF8000C-Drucker in Ubuntu 15.10?",
"translatedText": "Hur installerar man Canon MF8000C-skrivare i Ubuntu 15.10?",
"intent": {
"id": "<INTENT-ID>",
"name": "<INTENT-NAME>",
"confidence": 0.4786706566810608
},
"inetnt_ranking": [
{
"id": "<INTENT-ID>",
"name": "<INTENT-NAME>",
"confidence": 0.4786706566810608
},
{
"id": "<INTENT-ID>",
"name": "<INTENT-NAME>",
"confidence": 0.4672465920448303
},
{
"id": "<INTENT-ID>",
"name": "<INTENT-NAME>",
"confidence": 0.38100114464759827
},
{
"id": "<INTENT-ID>",
"name": "<INTENT-NAME>",
"confidence": 0.3789636492729187
},
{
"id": "<INTENT-ID>",
"name": "<INTENT-NAME>",
"confidence": 0.37299105525016785
}
],
"model_entities": [],
"entities": []
}
}