8000 docs: update classification sample to use v2 model by wizeng23 · Pull Request #378 · googleapis/python-language · GitHub
[go: up one dir, main page]

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

docs: update classification sample to use v2 model #378

Merged
merged 3 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions samples/v1/language_classify_text.py
8000
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