my city location is not available in IBM Watson api NLU

188 Views Asked by At

When I am sending text using Watson api NLU with my city which is located in India. I am getting empty entity. It should be come with data entity location. So how can i solve this problem in watson NLU.

The sentence being sent is:

mba college in bhubaneswar

where Bhubaneswar is the city

2

There are 2 best solutions below

2
On

So based on your comment sentence of:

"mba college in bhubaneswar"

Putting that into NLU and entity detection fails with:

Error: unsupported text language: unknown, Code: 400

The first issue is that because no language is specified, it tries to guess the language. But there is not enough there to guess (even if it is obvious to you).

The second issue is, even if you specify the language it will not fully recognise. This is because it's not a real sentence, it's a fragment.

NLU doesn't just do a keyword lookup, It tries to understand the parts of speech (POS) and from that, determine what the word means.

So if I give it a real sentence it will work. For example:

I go to an MBA college in Bhubaneswar

I used this sample code:

import json
from watson_developer_cloud import NaturalLanguageUnderstandingV1
from watson_developer_cloud.natural_language_understanding_v1 import Features, EntitiesOptions, RelationsOptions

ctx = {
  "url": "https://gateway.watsonplatform.net/natural-language-understanding/api",
  "username": "USERNAME",
  "password": "PASSWORD"
}
version = '2017-02-27'

text = "I go to an MBA college in Bhubaneswar"
#text = "mba college in bhubaneswar"

nlu = NaturalLanguageUnderstandingV1(version=version, username=ctx.get('username'),password=ctx.get('password'))
entities = EntitiesOptions()
relations = RelationsOptions()

response = nlu.analyze(text=text, features=Features(entities=entities,relations=relations),language='en')

print(json.dumps(response, indent=2))

That gives me the following results.

{
  "usage": {
    "text_units": 1,
    "text_characters": 37,
    "features": 2
  },
  "relations": [
    {
      "type": "basedIn",
      "sentence": "I go to an MBA college in Bhubaneswar",
      "score": 0.669215,
      "arguments": [
        {
          "text": "college",
          "location": [
            15,
            22
          ],
          "entities": [
            {
              "type": "Organization",
              "text": "college"
            }
          ]
        },
        {
          "text": "Bhubaneswar",
          "location": [
            26,
            37
          ],
          "entities": [
            {
              "type": "GeopoliticalEntity",
              "text": "Bhubaneswar"
            }
          ]
        }
      ]
    }
  ],
  "language": "en",
  "entities": [
    {
      "type": "Location",
      "text": "Bhubaneswar",
      "relevance": 0.33,
      "disambiguation": {
        "subtype": [
          "IndianCity",
          "City"
        ],
        "name": "Bhubaneswar",
        "dbpedia_resource": "http://dbpedia.org/resource/Bhubaneswar"
      },
      "count": 1
    }
  ]
}

If it's a case you are only going to get fragments to scan, then @ReeceMed solution will resolve it for you.

3
On

Screenshot of NLU Service responseIf the NLU service does not recognise the city you have entered you can create a custom model using Watson Knowledge Studio which can then be deployed to the NLU Service, giving customised entities and relationships.