Skip to main content

Parse Text Using NLU Models

Run in Postman

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.
  • 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

You can parse your model in NeuralSpace's format using the CLI as well as APIs.

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.

Request
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.

Response
{
"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
}
]
}
}

Multilingual Parse Text

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.

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.

Request
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?\"
}"
FieldsOptionalDescription
modelIdfalseID of the NLU model you want to use
textfalseThe text you want to parse
textLanguagetrueThe 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.

Response
{
"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": []
}
}