bigframes.ml.llm.GeminiTextGenerator.predict#

GeminiTextGenerator.predict(X: DataFrame | Series | DataFrame | Series, *, temperature: float = 0.9, max_output_tokens: int = 8192, top_k: int = 40, top_p: float = 1.0, ground_with_google_search: bool = False, max_retries: int = 0, prompt: Iterable[str | Series] | None = None, output_schema: Mapping[str, str] | None = None) DataFrame[source]#

Predict the result from input DataFrame.

Parameters:
  • X (bigframes.dataframe.DataFrame or bigframes.series.Series or pandas.core.frame.DataFrame or pandas.core.series.Series) – Input DataFrame or Series, can contain one or more columns. If multiple columns are in the DataFrame, the “prompt” column, or created by “prompt” parameter, is used for prediction. Prompts can include preamble, questions, suggestions, instructions, or examples.

  • temperature (float, default 0.9) – The temperature is used for sampling during the response generation, which occurs when topP and topK are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a more deterministic and less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of 0 is deterministic: the highest probability response is always selected. Default 0.9. Possible values [0.0, 1.0].

  • max_output_tokens (int, default 8192) – Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. Specify a lower value for shorter responses and a higher value for potentially longer responses. Default 8192. Possible values are in the range [1, 8192].

  • top_k (int, default 40) – Top-K changes how the model selects tokens for output. A top-K of 1 means the next selected token is the most probable among all tokens in the model’s vocabulary (also called greedy decoding), while a top-K of 3 means that the next token is selected from among the three most probable tokens by using temperature. For each token selection step, the top-K tokens with the highest probabilities are sampled. Then tokens are further filtered based on top-P with the final token selected using temperature sampling. Specify a lower value for less random responses and a higher value for more random responses. Default 40. Possible values [1, 40].

  • top_p (float, default 0.95) – Top-P changes how the model selects tokens for output. Tokens are selected from the most (see top-K) to least probable until the sum of their probabilities equals the top-P value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-P value is 0.5, then the model will select either A or B as the next token by using temperature and excludes C as a candidate. Specify a lower value for less random responses and a higher value for more random responses. Default 1.0. Possible values [0.0, 1.0].

  • ground_with_google_search (bool, default False) – Enables Grounding with Google Search for the Vertex AI model. When set to True, the model incorporates relevant information from Google Search results into its responses, enhancing their accuracy and factualness. This feature provides an additional column, ml_generate_text_grounding_result, in the response output, detailing the sources used for grounding. Note: Using this feature may impact billing costs. Refer to the pricing page for details: https://cloud.google.com/vertex-ai/generative-ai/pricing#google_models The default is False.

  • max_retries (int, default 0) – Max number of retries if the prediction for any rows failed. Each try needs to make progress (i.e. has successfully predicted rows) to continue the retry. Each retry will append newly succeeded rows. When the max retries are reached, the remaining rows (the ones without successful predictions) will be appended to the end of the result.

  • prompt (Iterable of str or bigframes.series.Series, or None, default None) –

    Note

    BigFrames Blob 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).

    Construct a prompt struct column for prediction based on the input. The input must be an Iterable that can take string literals, such as “summarize”, string column(s) of X, such as X[“str_col”], or blob column(s) of X, such as X[“blob_col”]. It creates a struct column of the items of the iterable, and use the concatenated result as the input prompt. No-op if set to None.

  • output_schema (Mapping[str, str] or None, default None) – The schema used to generate structured output as a bigframes DataFrame. The schema is a string key-value pair of <column_name>:<type>. Supported types are int64, float64, bool, string, array<type> and struct<column type>. If None, output text result.

Returns:

DataFrame of shape (n_samples, n_input_columns + n_prediction_columns). Returns predicted values.

Return type:

bigframes.dataframe.DataFrame