Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watson NLU - Not enough text provided for language detection

I am working with Watson NLU and trying to sentiment analysis on some text. The problem is that some text is too small for it to detect what language it is (E.g: Excellent service).Is there a way for me to specify that if language detection isn't possible, it should consider it English?

The snippet of my NLU (Java) is this:

SentimentOptions sentiment = new SentimentOptions.Builder()
    .targets(targets)
    .document(true)
    .build();


Features features = new Features.Builder()
    .sentiment(sentiment)
    .build();


AnalyzeOptions parameters = new AnalyzeOptions.Builder()
    .text(text)
    .features(features)
    .build();

AnalysisResults response = service
    .analyze(parameters)
    .execute();

String mySentiment = response.getSentiment().getDocument().getLabel();
like image 438
Aurangzeb Rathore Avatar asked Jan 26 '26 15:01

Aurangzeb Rathore


1 Answers

According to the Official API Reference documentation, you need to specify the language parameter in your POST request.

See more about these parameters on Watson Developer Cloud - Github - Java SDK.

Explanation of the API Reference - NLU:

  • language (string): ISO 639-1 code indicating the language to use for the analysis. This code overrides the automatic language detection performed by the service. Valid codes are ar (Arabic), en (English), fr (French), de (German), it (Italian), pt (Portuguese), ru (Russian), es (Spanish), and sv (Swedish). For more information about which features are supported in each language, see this table.

Example of how it works:

parameters.json file example:

{
  "text": "Excelent service",
  "features": {
    "semantic_roles": {}
  },
  "language": "en"
}

The cURL example:

curl -X POST \
-H "Content-Type: application/json" \
-u "{username}":"{password}" \
-d @parameters.json \
"https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27"

Probably your example (you did not specify your programming language, so):

AnalyzeOptions parameters = new AnalyzeOptions.Builder()
    .text(text)
    .features(features)
    .language('en')
    .build();
  • Official reference Natural Language Understanding
  • Language support for use NLU.
like image 200
Sayuri Mizuguchi Avatar answered Jan 29 '26 04:01

Sayuri Mizuguchi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!