From 73670e27e2c2056f4a53d1225bb99399e8cbd05e Mon Sep 17 00:00:00 2001 From: wizeng23 Date: Tue, 27 Sep 2022 07:58:25 -0700 Subject: [PATCH] docs: update classification sample to use v2 model (#378) * docs: update classification sample to use v2 model * fix: update classification test to use v2 model Co-authored-by: Anthonios Partheniou --- samples/v1/language_classify_text.py | 15 ++++++++++++--- samples/v1/test/classifying_content.test.yaml | 10 +++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/samples/v1/language_classify_text.py b/samples/v1/language_classify_text.py index 6fe2aaa4..fe2b5671 100644 --- a/samples/v1/language_classify_text.py +++ b/samples/v1/language_classify_text.py @@ -32,12 +32,12 @@ def sample_classify_text(text_content): Classifying Content in a String Args: - text_content The text content to analyze. Must include at least 20 words. + text_content The text content to analyze. """ client = language_v1.LanguageServiceClient() - # text_content = 'That actor on TV makes movies in Hollywood and also stars in a variety of popular new TV shows.' + # text_content = "That actor on TV makes movies in Hollywood and also stars in a variety of popular new TV shows." # Available types: PLAIN_TEXT, HTML type_ = language_v1.Document.Type.PLAIN_TEXT @@ -48,7 +48,16 @@ def sample_classify_text(text_content): language = "en" document = {"content": text_content, "type_": type_, "language": language} - response = client.classify_text(request = {'document': document}) + content_categories_version = ( + language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2) + response = client.classify_text(request = { + "document": document, + "classification_model_options": { + "v2_model": { + "content_categories_version": content_categories_version + } + } + }) # Loop through classified categories returned from the API for category in response.categories: # Get the name of the category representing the document. diff --git a/samples/v1/test/classifying_content.test.yaml b/samples/v1/test/classifying_content.test.yaml index 5cfc7669..4b5f121d 100644 --- a/samples/v1/test/classifying_content.test.yaml +++ b/samples/v1/test/classifying_content.test.yaml @@ -16,15 +16,15 @@ test: - name: language_classify_text - Classifying Content of a text string (*custom value*) spec: - # Custom value: "Let's drink coffee and eat bagels at a coffee shop. I want muffins, croisants, coffee and baked goods." + # Custom value: "Dungeons and dragons and loot, oh my!" - call: sample: language_classify_text params: - text_content: {literal: "Let's drink coffee and eat bagels at a coffee shop. I want muffins, croisants, coffee and baked goods."} + text_content: {literal: "Dungeons and dragons and loot, oh my!"} - assert_contains_any: - - {literal: "Food"} - - {literal: "Drink"} - - {literal: "Coffee"} + - {literal: "Games"} + - {literal: "Roleplaying"} + - {literal: "Computer"} - name: language_classify_gcs - Classifying Content of text file in GCS (default value) spec: