bigframes.bigquery.ai.classify#

bigframes.bigquery.ai.classify(input: str | Series | Series | List[str | Series | Series] | Tuple[str | Series | Series, ...], categories: tuple[str, ...] | list[str], *, connection_id: str | None = None) Series[source]#

Classifies a given input into one of the specified categories. It will always return one of the provided categories best fit the prompt input.

Examples:

>>> import bigframes.pandas as bpd
>>> import bigframes.bigquery as bbq
>>> df = bpd.DataFrame({'creature': ['Cat', 'Salmon']})
>>> df['type'] = bbq.ai.classify(df['creature'], ['Mammal', 'Fish'])
>>> df
  creature    type
0      Cat  Mammal
1   Salmon    Fish

[2 rows x 2 columns]

Note

This product or feature is subject to the “Pre-GA Offerings Terms” in the General Service Terms section of the Service Specific Terms(https://cloud.google.com/terms/service-terms#1). Pre-GA products and features are available “as is” and might have limited support. For more information, see the launch stage descriptions (https://cloud.google.com/products#product-launch-stages).

Parameters:
  • input (str | Series | List[str|Series] | Tuple[str|Series, ...]) – A mixture of Series and string literals that specifies the input to send to the model. The Series can be BigFrames Series or pandas Series.

  • categories (tuple[str, ...] | list[str]) – Categories to classify the input into.

  • connection_id (str, optional) – Specifies the connection to use to communicate with the model. For example, myproject.us.myconnection. If not provided, the connection from the current session will be used.

Returns:

A new series of strings.

Return type:

bigframes.series.Series