google.generativeai.create_tuned_model

Launches a tuning job to create a TunedModel.

Since tuning a model can take significant time, this API doesn't wait for the tuning to complete. Instead, it returns a google.api_core.operation.Operation object that lets you check on the status of the tuning job, or wait for it to complete, and check the result.

After the job completes you can either find the resulting TunedModel object in Operation.result() or palm.list_tuned_models or palm.get_tuned_model(model_id).

my_id = "my-tuned-model-id"
operation = palm.create_tuned_model(
  id = my_id,
  source_model="models/text-bison-001",
  training_data=[{'text_input': 'example input', 'output': 'example output'},...]
)
tuned_model=operation.result()      # Wait for tuning to finish

palm.generate_text(f"tunedModels/{my_id}", prompt="...")

source_model The name of the model to tune.
training_data The dataset to tune the model on. This must be either:

  • A glm.Dataset, or
  • An Iterable of: *glm.TuningExample,

    'text_input': text_input, 'output': output

    dicts, or
    • (text_input, output) tuples.
  • A Mapping of Iterable[str] - use input_key and output_key to choose which columns to use as the input/output
  • A csv file (will be read with pd.read_csv and handles as a Mapping above). This can be:
    • A local path as a str or pathlib.Path.
    • A url for a csv file.
    • The url of a Google Sheets file.
  • A JSON file - Its contents will be handled either as an Iterable or Mapping above. This can be:
    • A local path as a str or pathlib.Path.
id The model identifier, used to refer to the model in the API tunedModels/{id}. Must be unique.
display_name A human-readable name for display.
description A description of the tuned model.
temperature The default temperature for the tuned model, see types.Model for details.
top_p The default top_p for the model, see types.Model for details.
top_k The default top_k for the model, see types.Model for details.
epoch_count The number of tuning epochs to run. An epoch is a pass over the whole dataset.
batch_size The number of examples to use in each training batch.
learning_rate The step size multiplier for the gradient updates.
client Which client to use.

A google.api_core.operation.Operation