The Watson Natural Language Processing Sentiment classification models classify the sentiment of the input text.
Supported languages
Sentiment classification is available for the following languages. For a list of the language codes and the corresponding language, see Language codes.
The sentiment of text can be positive, negative or neutral.
The sentiment model computes the sentiment for each sentence in the input document. The aggregated sentiment for the entire document is also calculated using the sentiment transformer workflow.
The classifications returned contain a probability. The sentiment score varies from -1 to 1. A score greater than 0 denotes a positive sentiment, a score less than 0 a negative sentiment, and a score of 0 a neutral sentiment.
The sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled workflow can be used on both CPUs and GPUs.
The sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled-cpu workflow is optimized for CPU-based runtimes.
Code sample using the sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled
workflow
# Load the Sentiment workflow
sentiment_model = watson_nlp.load('sentiment-aggregated_transformer-workflow_multilingual_slate.153m.distilled-cpu')
# Run the sentiment model on the result of the syntax results
sentiment_result = sentiment_model.run('The rooms are nice. But the beds are not very comfortable.')
# Print the sentence sentiment resultsprint(sentiment_result)
Targets sentiment extraction extracts sentiments expressed in text and identifies the targets of those sentiments.
It can handle multiple targets with different sentiment in one sentence as opposed to the sentiment block described above.
For example, given the input sentence The served food was delicious, yet the service was slow., the Targets sentiment block identifies that there is a positive sentiment expressed in the target "food", and a negative sentiment
expressed in "service".
The model has been fine-tuned on English data only. Although you can use the model on the other languages listed under Supported languages, the results might vary.
The targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled workflow can be used on both CPUs and GPUs.
The targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled-cpu workflow is optimized for CPU-based runtimes.
Code sample for the targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled workflow
import watson_nlp
# Load Targets Sentiment model for English
targets_sentiment_model = watson_nlp.load('targets-sentiment_transformer-workflow_multilingual_slate.153m.distilled')
# Run the targets sentiment model on the input text
targets_sentiments = targets_sentiment_model.run('The rooms are nice, but the bed was not very comfortable.')
# Print the targets with the associated sentimentprint(targets_sentiments)
About cookies on this siteOur websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising.For more information, please review your cookie preferences options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.