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

Commit 73670e2

Browse files
wizeng23parthea
andauthored
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 <[email protected]>
1 parent 3ba5c56 commit 73670e2

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

samples/v1/language_classify_text.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ def sample_classify_text(text_content):
3232
Classifying Content in a String
3333
3434
Args:
35-
text_content The text content to analyze. Must include at least 20 words.
35+
text_content The text content to analyze.
3636
"""
3737

3838
client = language_v1.LanguageServiceClient()
3939

40-
# text_content = 'That actor on TV makes movies in Hollywood and also stars in a variety of popular new TV shows.'
40+
# text_content = "That actor on TV makes movies in Hollywood and also stars in a variety of popular new TV shows."
4141

4242
# Available types: PLAIN_TEXT, HTML
4343
type_ = language_v1.Document.Type.PLAIN_TEXT
@@ -48,7 +48,16 @@ def sample_classify_text(text_content):
4848
language = "en"
4949
document = {"content": text_content, "type_": type_, "language": language}
5050

51-
response = client.classify_text(request = {'document': document})
51+
content_categories_version = (
52+
language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2)
53+
response = client.classify_text(request = {
54+
"document": document,
55+
"classification_model_options": {
56+
"v2_model": {
57+
"content_categories_version": content_categories_version
58+
}
59+
}
60+
})
5261
# Loop through classified categories returned from the API
5362
for category in response.categories:
5463
# Get the name of the category representing the document.

samples/v1/test/classifying_content.test.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ test:
1616

1717
- name: language_classify_text - Classifying Content of a text string (*custom value*)
1818
spec:
19-
# Custom value: "Let's drink coffee and eat bagels at a coffee shop. I want muffins, croisants, coffee and baked goods."
19+
# Custom value: "Dungeons and dragons and loot, oh my!"
2020
- call:
2121
sample: language_classify_text
2222
params:
23-
text_content: {literal: "Let's drink coffee and eat bagels at a coffee shop. I want muffins, croisants, coffee and baked goods."}
23+
text_content: {literal: "Dungeons and dragons and loot, oh my!"}
2424
- assert_contains_any:
25-
- {literal: "Food"}
26-
- {literal: "Drink"}
27-
- {literal: "Coffee"}
25+
- {literal: "Games"}
26+
- {literal: "Roleplaying"}
27+
- {literal: "Computer"}
2828

2929
- name: language_classify_gcs - Classifying Content of text file in GCS (default value)
3030
spec:

0 commit comments

Comments
 (0)