Skip to content

Commit 2dab4d0

Browse files
feat: Add support for V1 and V2 classification models (#376)
* feat: Add support for V1 and V2 classification models for the V1 API PiperOrigin-RevId: 475599241 Source-Link: googleapis/googleapis@05b99f9 Source-Link: googleapis/googleapis-gen@3dcdbed Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiM2RjZGJlZDhkOTY4ZjYzNGJlMGEyZDMxMDcyMzdkMjMyZWU4YjA2MSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Add support for V1 and V2 classification models for the V1Beta2 API PiperOrigin-RevId: 475604619 Source-Link: googleapis/googleapis@044a15c Source-Link: googleapis/googleapis-gen@410020a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDEwMDIwYWY5MzRjNzI0OGY3ODA0NzcwZDZmOGVjNDU3MWJmYTU1MSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * docs: fix docstring formatting Committer: @parthea PiperOrigin-RevId: 476410563 Source-Link: googleapis/googleapis@7f579ee Source-Link: googleapis/googleapis-gen@ae0240e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWUwMjQwZTA5N2ExOTZjMDcwZTE1ZGVhYWU2NjQ2NGI0MmM4ZTAxNCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 546f758 commit 2dab4d0

File tree

15 files changed

+227
-28
lines changed

15 files changed

+227
-28
lines changed

packages/google-cloud-language/google/cloud/language/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
AnnotateTextRequest,
3333
AnnotateTextResponse,
3434
ClassificationCategory,
35+
ClassificationModelOptions,
3536
ClassifyTextRequest,
3637
ClassifyTextResponse,
3738
DependencyEdge,
@@ -60,6 +61,7 @@
6061
"AnnotateTextRequest",
6162
"AnnotateTextResponse",
6263
"ClassificationCategory",
64+
"ClassificationModelOptions",
6365
"ClassifyTextRequest",
6466
"ClassifyTextResponse",
6567
"DependencyEdge",

packages/google-cloud-language/google/cloud/language_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
AnnotateTextRequest,
2828
AnnotateTextResponse,
2929
ClassificationCategory,
30+
ClassificationModelOptions,
3031
ClassifyTextRequest,
3132
ClassifyTextResponse,
3233
DependencyEdge,
@@ -54,6 +55,7 @@
5455
"AnnotateTextRequest",
5556
"AnnotateTextResponse",
5657
"ClassificationCategory",
58+
"ClassificationModelOptions",
5759
"ClassifyTextRequest",
5860
"ClassifyTextResponse",
5961
"DependencyEdge",

packages/google-cloud-language/google/cloud/language_v1/services/language_service/async_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def sample_analyze_sentiment():
248248
The request object. The sentiment analysis request
249249
message.
250250
document (:class:`google.cloud.language_v1.types.Document`):
251-
Input document.
251+
Required. Input document.
252252
This corresponds to the ``document`` field
253253
on the ``request`` instance; if ``request`` is provided, this
254254
should not be set.
@@ -367,7 +367,7 @@ async def sample_analyze_entities():
367367
request (Union[google.cloud.language_v1.types.AnalyzeEntitiesRequest, dict]):
368368
The request object. The entity analysis request message.
369369
document (:class:`google.cloud.language_v1.types.Document`):
370-
Input document.
370+
Required. Input document.
371371
This corresponds to the ``document`` field
372372
on the ``request`` instance; if ``request`` is provided, this
373373
should not be set.
@@ -485,7 +485,7 @@ async def sample_analyze_entity_sentiment():
485485
The request object. The entity-level sentiment analysis
486486
request message.
487487
document (:class:`google.cloud.language_v1.types.Document`):
488-
Input document.
488+
Required. Input document.
489489
This corresponds to the ``document`` field
490490
on the ``request`` instance; if ``request`` is provided, this
491491
should not be set.
@@ -603,7 +603,7 @@ async def sample_analyze_syntax():
603603
request (Union[google.cloud.language_v1.types.AnalyzeSyntaxRequest, dict]):
604604
The request object. The syntax analysis request message.
605605
document (:class:`google.cloud.language_v1.types.Document`):
606-
Input document.
606+
Required. Input document.
607607
This corresponds to the ``document`` field
608608
on the ``request`` instance; if ``request`` is provided, this
609609
should not be set.
@@ -717,7 +717,7 @@ async def sample_classify_text():
717717
The request object. The document classification request
718718
message.
719719
document (:class:`google.cloud.language_v1.types.Document`):
720-
Input document.
720+
Required. Input document.
721721
This corresponds to the ``document`` field
722722
on the ``request`` instance; if ``request`` is provided, this
723723
should not be set.
@@ -829,12 +829,12 @@ async def sample_annotate_text():
829829
annotation API, which can perform multiple analysis
830830
types (sentiment, entities, and syntax) in one call.
831831
document (:class:`google.cloud.language_v1.types.Document`):
832-
Input document.
832+
Required. Input document.
833833
This corresponds to the ``document`` field
834834
on the ``request`` instance; if ``request`` is provided, this
835835
should not be set.
836836
features (:class:`google.cloud.language_v1.types.AnnotateTextRequest.Features`):
837-
The enabled features.
837+
Required. The enabled features.
838838
This corresponds to the ``features`` field
839839
on the ``request`` instance; if ``request`` is provided, this
840840
should not be set.

packages/google-cloud-language/google/cloud/language_v1/services/language_service/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def sample_analyze_sentiment():
453453
The request object. The sentiment analysis request
454454
message.
455455
document (google.cloud.language_v1.types.Document):
456-
Input document.
456+
Required. Input document.
457457
This corresponds to the ``document`` field
458458
on the ``request`` instance; if ``request`` is provided, this
459459
should not be set.
@@ -562,7 +562,7 @@ def sample_analyze_entities():
562562
request (Union[google.cloud.language_v1.types.AnalyzeEntitiesRequest, dict]):
563563
The request object. The entity analysis request message.
564564
document (google.cloud.language_v1.types.Document):
565-
Input document.
565+
Required. Input document.
566566
This corresponds to the ``document`` field
567567
on the ``request`` instance; if ``request`` is provided, this
568568
should not be set.
@@ -670,7 +670,7 @@ def sample_analyze_entity_sentiment():
670670
The request object. The entity-level sentiment analysis
671671
request message.
672672
document (google.cloud.language_v1.types.Document):
673-
Input document.
673+
Required. Input document.
674674
This corresponds to the ``document`` field
675675
on the ``request`` instance; if ``request`` is provided, this
676676
should not be set.
@@ -778,7 +778,7 @@ def sample_analyze_syntax():
778778
request (Union[google.cloud.language_v1.types.AnalyzeSyntaxRequest, dict]):
779779
The request object. The syntax analysis request message.
780780
document (google.cloud.language_v1.types.Document):
781-
Input document.
781+
Required. Input document.
782782
This corresponds to the ``document`` field
783783
on the ``request`` instance; if ``request`` is provided, this
784784
should not be set.
@@ -882,7 +882,7 @@ def sample_classify_text():
882882
The request object. The document classification request
883883
message.
884884
document (google.cloud.language_v1.types.Document):
885-
Input document.
885+
Required. Input document.
886886
This corresponds to the ``document`` field
887887
on the ``request`` instance; if ``request`` is provided, this
888888
should not be set.
@@ -984,12 +984,12 @@ def sample_annotate_text():
984984
annotation API, which can perform multiple analysis
985985
types (sentiment, entities, and syntax) in one call.
986986
document (google.cloud.language_v1.types.Document):
987-
Input document.
987+
Required. Input document.
988988
This corresponds to the ``document`` field
989989
on the ``request`` instance; if ``request`` is provided, this
990990
should not be set.
991991
features (google.cloud.language_v1.types.AnnotateTextRequest.Features):
992-
The enabled features.
992+
Required. The enabled features.
993993
This corresponds to the ``features`` field
994994
on the ``request`` instance; if ``request`` is provided, this
995995
should not be set.

packages/google-cloud-language/google/cloud/language_v1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
AnnotateTextRequest,
2626
AnnotateTextResponse,
2727
ClassificationCategory,
28+
ClassificationModelOptions,
2829
ClassifyTextRequest,
2930
ClassifyTextResponse,
3031
DependencyEdge,
@@ -51,6 +52,7 @@
5152
"AnnotateTextRequest",
5253
"AnnotateTextResponse",
5354
"ClassificationCategory",
55+
"ClassificationModelOptions",
5456
"ClassifyTextRequest",
5557
"ClassifyTextResponse",
5658
"DependencyEdge",

packages/google-cloud-language/google/cloud/language_v1/types/language_service.py

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"EntityMention",
3030
"TextSpan",
3131
"ClassificationCategory",
32+
"ClassificationModelOptions",
3233
"AnalyzeSentimentRequest",
3334
"AnalyzeSentimentResponse",
3435
"AnalyzeEntitySentimentRequest",
@@ -728,12 +729,76 @@ class ClassificationCategory(proto.Message):
728729
)
729730

730731

732+
class ClassificationModelOptions(proto.Message):
733+
r"""Model options available for classification requests.
734+
735+
This message has `oneof`_ fields (mutually exclusive fields).
736+
For each oneof, at most one member field can be set at the same time.
737+
Setting any member of the oneof automatically clears all other
738+
members.
739+
740+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
741+
742+
Attributes:
743+
v1_model (google.cloud.language_v1.types.ClassificationModelOptions.V1Model):
744+
Setting this field will use the V1 model and
745+
V1 content categories version. The V1 model is a
746+
legacy model; support for this will be
747+
discontinued in the future.
748+
749+
This field is a member of `oneof`_ ``model_type``.
750+
v2_model (google.cloud.language_v1.types.ClassificationModelOptions.V2Model):
751+
Setting this field will use the V2 model with
752+
the appropriate content categories version. The
753+
V2 model is a better performing model.
754+
755+
This field is a member of `oneof`_ ``model_type``.
756+
"""
757+
758+
class V1Model(proto.Message):
759+
r"""Options for the V1 model."""
760+
761+
class V2Model(proto.Message):
762+
r"""Options for the V2 model.
763+
764+
Attributes:
765+
content_categories_version (google.cloud.language_v1.types.ClassificationModelOptions.V2Model.ContentCategoriesVersion):
766+
The content categories used for
767+
classification.
768+
"""
769+
770+
class ContentCategoriesVersion(proto.Enum):
771+
r"""The content categories used for classification."""
772+
CONTENT_CATEGORIES_VERSION_UNSPECIFIED = 0
773+
V1 = 1
774+
V2 = 2
775+
776+
content_categories_version = proto.Field(
777+
proto.ENUM,
778+
number=1,
779+
enum="ClassificationModelOptions.V2Model.ContentCategoriesVersion",
780+
)
781+
782+
v1_model = proto.Field(
783+
proto.MESSAGE,
784+
number=1,
785+
oneof="model_type",
786+
message=V1Model,
787+
)
788+
v2_model = proto.Field(
789+
proto.MESSAGE,
790+
number=2,
791+
oneof="model_type",
792+
message=V2Model,
793+
)
794+
795+
731796
class AnalyzeSentimentRequest(proto.Message):
732797
r"""The sentiment analysis request message.
733798
734799
Attributes:
735800
document (google.cloud.language_v1.types.Document):
736-
Input document.
801+
Required. Input document.
737802
encoding_type (google.cloud.language_v1.types.EncodingType):
738803
The encoding type used by the API to
739804
calculate sentence offsets.
@@ -789,7 +854,7 @@ class AnalyzeEntitySentimentRequest(proto.Message):
789854
790855
Attributes:
791856
document (google.cloud.language_v1.types.Document):
792-
Input document.
857+
Required. Input document.
793858
encoding_type (google.cloud.language_v1.types.EncodingType):
794859
The encoding type used by the API to
795860
calculate offsets.
@@ -838,7 +903,7 @@ class AnalyzeEntitiesRequest(proto.Message):
838903
839904
Attributes:
840905
document (google.cloud.language_v1.types.Document):
841-
Input document.
906+
Required. Input document.
842907
encoding_type (google.cloud.language_v1.types.EncodingType):
843908
The encoding type used by the API to
844909
calculate offsets.
@@ -887,7 +952,7 @@ class AnalyzeSyntaxRequest(proto.Message):
887952
888953
Attributes:
889954
document (google.cloud.language_v1.types.Document):
890-
Input document.
955+
Required. Input document.
891956
encoding_type (google.cloud.language_v1.types.EncodingType):
892957
The encoding type used by the API to
893958
calculate offsets.
@@ -943,14 +1008,22 @@ class ClassifyTextRequest(proto.Message):
9431008
9441009
Attributes:
9451010
document (google.cloud.language_v1.types.Document):
946-
Input document.
1011+
Required. Input document.
1012+
classification_model_options (google.cloud.language_v1.types.ClassificationModelOptions):
1013+
Model options to use for classification.
1014+
Defaults to v1 options if not specified.
9471015
"""
9481016

9491017
document = proto.Field(
9501018
proto.MESSAGE,
9511019
number=1,
9521020
message="Document",
9531021
)
1022+
classification_model_options = proto.Field(
1023+
proto.MESSAGE,
1024+
number=3,
1025+
message="ClassificationModelOptions",
1026+
)
9541027

9551028

9561029
class ClassifyTextResponse(proto.Message):
@@ -975,9 +1048,9 @@ class AnnotateTextRequest(proto.Message):
9751048
9761049
Attributes:
9771050
document (google.cloud.language_v1.types.Document):
978-
Input document.
1051+
Required. Input document.
9791052
features (google.cloud.language_v1.types.AnnotateTextRequest.Features):
980-
The enabled features.
1053+
Required. The enabled features.
9811054
encoding_type (google.cloud.language_v1.types.EncodingType):
9821055
The encoding type used by the API to
9831056
calculate offsets.
@@ -1000,6 +1073,10 @@ class Features(proto.Message):
10001073
sentiment.
10011074
classify_text (bool):
10021075
Classify the full document into categories.
1076+
classification_model_options (google.cloud.language_v1.types.ClassificationModelOptions):
1077+
The model options to use for classification. Defaults to v1
1078+
options if not specified. Only used if ``classify_text`` is
1079+
set to true.
10031080
"""
10041081

10051082
extract_syntax = proto.Field(
@@ -1022,6 +1099,11 @@ class Features(proto.Message):
10221099
proto.BOOL,
10231100
number=6,
10241101
)
1102+
classification_model_options = proto.Field(
1103+
proto.MESSAGE,
1104+
number=10,
1105+
message="ClassificationModelOptions",
1106+
)
10251107

10261108
document = proto.Field(
10271109
proto.MESSAGE,

packages/google-cloud-language/google/cloud/language_v1beta2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
AnnotateTextRequest,
2828
AnnotateTextResponse,
2929
ClassificationCategory,
30+
ClassificationModelOptions,
3031
ClassifyTextRequest,
3132
ClassifyTextResponse,
3233
DependencyEdge,
@@ -54,6 +55,7 @@
5455
"AnnotateTextRequest",
5556
"AnnotateTextResponse",
5657
"ClassificationCategory",
58+
"ClassificationModelOptions",
5759
"ClassifyTextRequest",
5860
"ClassifyTextResponse",
5961
"DependencyEdge",

packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ async def analyze_syntax(
568568
metadata: Sequence[Tuple[str, str]] = (),
569569
) -> language_service.AnalyzeSyntaxResponse:
570570
r"""Analyzes the syntax of the text and provides sentence
571-
boundaries and tokenization along with part-of-speech
571+
boundaries and tokenization along with part of speech
572572
tags, dependency trees, and other properties.
573573
574574
.. code-block:: python

packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def analyze_syntax(
743743
metadata: Sequence[Tuple[str, str]] = (),
744744
) -> language_service.AnalyzeSyntaxResponse:
745745
r"""Analyzes the syntax of the text and provides sentence
746-
boundaries and tokenization along with part-of-speech
746+
boundaries and tokenization along with part of speech
747747
tags, dependency trees, and other properties.
748748
749749
.. code-block:: python

packages/google-cloud-language/google/cloud/language_v1beta2/services/language_service/transports/grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def analyze_syntax(
331331
r"""Return a callable for the analyze syntax method over gRPC.
332332
333333
Analyzes the syntax of the text and provides sentence
334-
boundaries and tokenization along with part-of-speech
334+
boundaries and tokenization along with part of speech
335335
tags, dependency trees, and other properties.
336336
337337
Returns:

0 commit comments

Comments
 (0)