Hi, could anyone share the python code on how to get natural language API to use version 2 classify text categories?
I can get it working well with the default (version 1) categories but can't figure out where to adapt the standard code (as here: https://cloud.google.com/natural-language/docs/samples/language-classify-text-tutorial-classify?hl=e...) to use model version 2.
Many thanks
Solved! Go to Solution.
From the Classifying Content guide, you can include classification_model_options within the request dictionary argument to the classify_text() function. In these options, you can define the model and version to use for content categories.
// ...
content_categories_version = (
language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2) // Assigning the v2 model type
response = client.classify_text(request = {
"document": document,
"classification_model_options": {
"v2_model": {
"content_categories_version": content_categories_version
}
}
})
// ...
You can also check ClassificationModelOptions reference for available options.
From the Classifying Content guide, you can include classification_model_options within the request dictionary argument to the classify_text() function. In these options, you can define the model and version to use for content categories.
// ...
content_categories_version = (
language_v1.ClassificationModelOptions.V2Model.ContentCategoriesVersion.V2) // Assigning the v2 model type
response = client.classify_text(request = {
"document": document,
"classification_model_options": {
"v2_model": {
"content_categories_version": content_categories_version
}
}
})
// ...
You can also check ClassificationModelOptions reference for available options.