Επεξεργασία

Κοινή χρήση μέσω


How to: Use Sentiment analysis and Opinion Mining

Sentiment analysis and opinion mining are two ways of detecting positive and negative sentiment. Using sentiment analysis, you can get sentiment labels (such as "negative", "neutral" and "positive") and confidence scores at the sentence and document-level. Opinion Mining provides granular information about the opinions related to words (such as the attributes of products or services) in the text.

Sentiment Analysis

Sentiment Analysis applies sentiment labels to text, which are returned at a sentence and document level, with a confidence score for each.

The labels are positive, negative, and neutral. At the document level, the mixed sentiment label also can be returned. The sentiment of the document is determined below:

Sentence sentiment Returned document label
At least one positive sentence is in the document. The rest of the sentences are neutral. positive
At least one negative sentence is in the document. The rest of the sentences are neutral. negative
At least one negative sentence and at least one positive sentence are in the document. mixed
All sentences in the document are neutral. neutral

Confidence scores range from 1 to 0. Scores closer to 1 indicate a higher confidence in the label's classification, while lower scores indicate lower confidence. For each document or each sentence, the predicted scores associated with the labels (positive, negative, and neutral) add up to 1. For more information, see the Responsible AI transparency note.

Opinion Mining

Opinion Mining is a feature of Sentiment Analysis. Also known as Aspect-based Sentiment Analysis in Natural Language Processing (NLP), this feature provides more granular information about the opinions related to attributes of products or services in text. The API surfaces opinions as a target (noun or verb) and an assessment (adjective).

For example, if a customer leaves feedback about a hotel such as "The room was great, but the staff was unfriendly.", Opinion Mining will locate targets (aspects) in the text, and their associated assessments (opinions) and sentiments. Sentiment Analysis might only report a negative sentiment.

A diagram of the Opinion Mining example

If you're using the REST API, to get Opinion Mining in your results, you must include the opinionMining=true flag in a request for sentiment analysis. The Opinion Mining results will be included in the sentiment analysis response. Opinion mining is an extension of Sentiment Analysis and is included in your current pricing tier.

Development options

To use sentiment analysis, you submit raw unstructured text for analysis and handle the API output in your application. Analysis is performed as-is, with no additional customization to the model used on your data. There are two ways to use sentiment analysis:

Development option Description
Language studio Language Studio is a web-based platform that lets you try entity linking with text examples without an Azure account, and your own data when you sign up. For more information, see the Language Studio website or language studio quickstart.
REST API or Client library (Azure SDK) Integrate sentiment analysis into your applications using the REST API, or the client library available in a variety of languages. For more information, see the sentiment analysis quickstart.
Docker container Use the available Docker container to deploy this feature on-premises. These docker containers enable you to bring the service closer to your data for compliance, security, or other operational reasons.

Determine how to process the data (optional)

Specify the sentiment analysis model

By default, sentiment analysis will use the latest available AI model on your text. You can also configure your API requests to use a specific model version.

Input languages

When you submit documents to be processed by sentiment analysis, you can specify which of the supported languages they're written in. If you don't specify a language, sentiment analysis will default to English. The API may return offsets in the response to support different multilingual and emoji encodings.

Submitting data

Sentiment analysis and opinion mining produce a higher-quality result when you give it smaller amounts of text to work on. This is opposite from some features, like key phrase extraction which performs better on larger blocks of text.

To send an API request, you'll need your Language resource endpoint and key.

Note

You can find the key and endpoint for your Language resource on the Azure portal. They will be located on the resource's Key and endpoint page, under resource management.

Analysis is performed upon receipt of the request. Using the sentiment analysis and opinion mining features synchronously is stateless. No data is stored in your account, and results are returned immediately in the response.

When using this feature asynchronously, the API results are available for 24 hours from the time the request was ingested, and is indicated in the response. After this time period, the results are purged and are no longer available for retrieval.

Getting sentiment analysis and opinion mining results

When you receive results from the API, the order of the returned key phrases is determined internally, by the model. You can stream the results to an application, or save the output to a file on the local system.

Sentiment analysis returns a sentiment label and confidence score for the entire document, and each sentence within it. Scores closer to 1 indicate a higher confidence in the label's classification, while lower scores indicate lower confidence. A document can have multiple sentences, and the confidence scores within each document or sentence add up to 1.

Opinion Mining will locate targets (nouns or verbs) in the text, and their associated assessment (adjective). For example, the sentence "The restaurant had great food and our server was friendly" has two targets: food and server. Each target has an assessment. For example, the assessment for food would be great, and the assessment for server would be friendly.

The API returns opinions as a target (noun or verb) and an assessment (adjective).

Service and data limits

For information on the size and number of requests you can send per minute and second, see the service limits article.

See also