Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
docs: update classification sample to use v2 model (#378)
Browse files Browse the repository at this point in the history
* docs: update classification sample to use v2 model

* fix: update classification test to use v2 model

Co-authored-by: Anthonios Partheniou <[email protected]>
  • Loading branch information
wizeng23 and parthea authored Sep 27, 2022
1 parent 3ba5c56 commit 73670e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 12 additions & 3 deletions samples/v1/language_classify_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions samples/v1/test/classifying_content.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 73670e2

Please sign in to comment.