[text analytics] opinion mining support#12542
Conversation
sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_models.py
Outdated
Show resolved
Hide resolved
| docs = _validate_batch_input(documents, "language", language) | ||
| model_version = kwargs.pop("model_version", None) | ||
| show_stats = kwargs.pop("show_stats", False) | ||
| show_aspects = kwargs.pop("show_aspects", None) |
There was a problem hiding this comment.
I think this should default to False
There was a problem hiding this comment.
I went with None to get the service default, @johanste is the policy to default to None in this case, or False to keep it static
There was a problem hiding this comment.
If we need to distinguish between "the application explicitly passed in this value" vs. "the application didn't provide a value, so we'll pick an appropriate default for them" for positional arguments, then we use a sentinel value as the default value. This is often None when None is not a valid value.
Since we are dealing with kwargs here, it would be easier/clearer to check if 'show_aspects' in kwargs: - no need for sentinel values since kwargs inherently let's you determine if the user passed the parameter or not.
There was a problem hiding this comment.
@johanste I do need to still pop kwargs in this case since the name of the parameter has changed (we have it as show_aspects, the service has it as opinion_mining). I think I'll stick with the sentinel value of None, holler if this is wrong
sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_text_analytics_client.py
Outdated
Show resolved
Hide resolved
sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_sentiment.py
Outdated
Show resolved
Hide resolved
sdk/textanalytics/azure-ai-textanalytics/tests/test_analyze_sentiment_async.py
Show resolved
Hide resolved
|
/azp run python - textanalytics - ci |
| :type documents: | ||
| list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or | ||
| list[dict[str, str]] | ||
| :keyword bool show_aspects: Whether to conduct more granular analysis around the aspects of |
There was a problem hiding this comment.
We should add a .. versionadded (or possibly a .. note) directive that indicates in which API version(s) this parameter is available. We should see what the generated docs look like for each since our docs pipelines are customized and I don't think we've used either up until now...
…into opinion_mining * 'master' of https://github.com/Azure/azure-sdk-for-python: (69 commits) [formrecognizer] renames from consistency check (Azure#12752) [text analytics] add back PII endpoint (Azure#12673) [text analytics] generate multiapi client, made v3.1-preview.1 default version (Azure#12720) Prevent AttributeError during get_certificate_version (Azure#12747) re-apply updates after resetting master (Azure#12771) Sync eng/common directory with azure-sdk-tools repository (Azure#12745) Enable bandit for servicebus (Azure#12763) Skip pypy3 for service bus CI pipeline (Azure#12732) Update CODEOWNERS (Azure#12765) updated tox file (Azure#11087) Updating to match Microsoft recommended template (Azure#11045) [text analytics] update version in master (Azure#12749) Explicitly stringify message prints in samples per manual doc pass recommendation. (Azure#12709) Run only analyse dependency step for aggregate report (Azure#12728) VSCodeCredential supports Python 2.7 on Windows (Azure#12731) Enable bandit (Azure#12722) Move InteractiveCredential to a new module (Azure#12706) Add foundations for eng/common restructure (Azure#12725) Sync eng/common directory with azure-sdk-tools repository (Azure#12730) fix flaky test (Azure#12721) ...
| pass in `v3.0` to the kwarg `api_version` when creating your TextAnalyticsClient | ||
| - We have added an API `recognize_pii_entities` which returns entities containing personal information for a batch of documents. Only available for API version v3.1-preview.1 and up. | ||
| - We now have added support for opinion mining. To use this feature, you need to make sure you are using the service's | ||
| v3.1-preview.1 API. To get this support pass `show_opinion_mining` as True when calling the `analyze_sentiment` endpoint |
There was a problem hiding this comment.
are you gloating
There was a problem hiding this comment.
no I'm smiling - like the emoji is
| is not specified, the API will default to the latest, non-preview version. | ||
| :keyword bool show_stats: If set to true, response will contain document level statistics. | ||
| .. versionadded:: v3.1-preview.1 | ||
| The *show_opinion_mining* parameter. |
There was a problem hiding this comment.
just curious if this is correct placement or if it should be under the keyword for show_opinion_mining?
There was a problem hiding this comment.
If i put it under the definition for show_opinion_mining, it's splitting up the keyword definition now in a very weird way. Speaking of.. @scbedd do you have any updates for this? no rush if not
There was a problem hiding this comment.
what if we move show_opinion_mining as the last keyword in docstring? does that help at all?
| and 1 for the sentence for all labels. | ||
| :vartype confidence_scores: | ||
| ~azure.ai.textanalytics.SentimentConfidenceScores | ||
| :ivar mined_opinions: The list of opinions mined from this sentence. |
There was a problem hiding this comment.
would it be good to add a ask.ms link to service documentation here about Opinion Mining?
| :type documents: | ||
| list[str] or list[~azure.ai.textanalytics.TextDocumentInput] or | ||
| list[dict[str, str]] | ||
| :keyword bool show_opinion_mining: Whether to mine the opinions of a sentence and conduct more |
There was a problem hiding this comment.
could we link here service docs too?
| granular analysis around the aspects of a product or service (also known as | ||
| aspect-based sentiment analysis). If set to true, the returned | ||
| :class:`~azure.ai.textanalytics.SentenceSentiment` objects | ||
| will have property `mined_opinions` containing the result of this analysis. Only available for |
There was a problem hiding this comment.
Not sure if we should say this here, as we will have to update it once service GA 3.1
We could just use the link to service docs and let them manage the versions of where the functionality is available
There was a problem hiding this comment.
Agreed that it is an extra step of maintenance, but I think we should still have this documentation is here, so it's easier for users to see off the bat that this is only available in certain versions.
Will follow your guidance and open an issue to track this for the future, thanks!
| except TypeError as error: | ||
| if "opinion_mining" in str(error): | ||
| raise NotImplementedError( | ||
| "'show_opinion_mining' is only available for API version v3.1-preview.1 and up" |
There was a problem hiding this comment.
early, but we should create an issue to update this value once service GA`s 3.1
| self.assertIsNotNone(aspect.confidence_scores.positive) | ||
| self.assertEqual(0.0, aspect.confidence_scores.neutral) | ||
| self.assertIsNotNone(aspect.confidence_scores.negative) |
There was a problem hiding this comment.
we could add an extra check where all the confidence scores need to add up to 1. That way we know for sure that not all of them are 0
There was a problem hiding this comment.
For more context, in .NET I was doing the exact checks and I missed a bug in the deserialization, so all scores always ended up in 0.0.
The adds up to check has caught those failures
There was a problem hiding this comment.
that's fair. i've created a separate issue to add this, since there are more instances in our test suite where i'd like this added: #12833
|
|
||
| @GlobalTextAnalyticsAccountPreparer() | ||
| @TextAnalyticsClientPreparer() | ||
| def test_aspect_based_sentiment_analysis(self, client): |
There was a problem hiding this comment.
Another test we could add is to turn on opinion mining with a sentence that gives us no results.
For example for the sentence: "today is a hot day"
There was a problem hiding this comment.
great suggestion, adding that to this PR. thanks!
maririos
left a comment
There was a problem hiding this comment.
Minor doc and test comments, otherwise LGTM
…into ta_opinion_mining_sample * 'master' of https://github.com/Azure/azure-sdk-for-python: (47 commits) [text analytics] opinion mining support (Azure#12542) [key vault] Regenerate keys (Azure#12101) [Tables] Azure Data Tables SDK, sync and async code (Azure#12766) fix doc, sample, docstring (Azure#12784) clean up links for PII samples (Azure#12826) [formrecognizer] renames from consistency check (Azure#12752) [text analytics] add back PII endpoint (Azure#12673) [text analytics] generate multiapi client, made v3.1-preview.1 default version (Azure#12720) Prevent AttributeError during get_certificate_version (Azure#12747) re-apply updates after resetting master (Azure#12771) Sync eng/common directory with azure-sdk-tools repository (Azure#12745) Enable bandit for servicebus (Azure#12763) Skip pypy3 for service bus CI pipeline (Azure#12732) Update CODEOWNERS (Azure#12765) updated tox file (Azure#11087) Updating to match Microsoft recommended template (Azure#11045) [text analytics] update version in master (Azure#12749) Explicitly stringify message prints in samples per manual doc pass recommendation. (Azure#12709) Run only analyse dependency step for aggregate report (Azure#12728) VSCodeCredential supports Python 2.7 on Windows (Azure#12731) ...
…into regenerate_certs * 'master' of https://github.com/Azure/azure-sdk-for-python: [key vault] Regenerate secrets (Azure#12103) [text analytics] opinion mining support (Azure#12542)
fixes #12476
fixes #12477
Will be updating the samples and readme in a subsequent PR