# google.generativeai.create_tuned_model
Calls the API to initiate a tuning process that optimizes a model for specific data, returning an operation object to track and manage the tuning progress.
google.generativeai.create_tuned_model(
source_model: model_types.AnyModelNameOptions,
training_data: model_types.TuningDataOptions,
*,
id: (str | None) = None,
display_name: (str | None) = None,
description: (str | None) = None,
temperature: (float | None) = None,
top_p: (float | None) = None,
top_k: (int | None) = None,
epoch_count: (int | None) = None,
batch_size: (int | None) = None,
learning_rate: (float | None) = None,
input_key: str = 'text_input',
output_key: str = 'output',
client: (glm.ModelServiceClient | None) = None,
request_options: (helper_types.RequestOptionsType | None) = None
) -> operations.CreateTunedModelOperation
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="...")
```
Args |
`source_model`
|
The name of the model to tune.
|
`training_data`
|
The dataset to tune the model on. This must be either:
* A protos.Dataset , or
* An `Iterable` of:
*protos.TuningExample ,
* `{'text_input': text_input, 'output': output}` dicts
* `(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.
|
`request_options`
|
Options for the request.
|
Returns |
A [`google.api_core.operation.Operation`](https://googleapis.dev/python/google-api-core/latest/operation.html)
|