For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
Guides and conceptsAPI ReferenceRelease NotesLLMUCookbooks
  • Get Started
    • Introduction
    • Installation
    • Creating a client
    • Playground
    • FAQs
  • Models
    • An Overview of Cohere's Models
    • Aya
    • Embed
    • Rerank
  • Text Generation
    • Introduction to Text Generation at Cohere
    • Using the Chat API
    • Reasoning
    • Image Inputs
    • Streaming Responses
    • Predictable Outputs
    • Advanced Generation Parameters
    • Tool Use
    • Tokens and Tokenizers
    • Summarizing Text
    • Safety Modes
  • Embeddings (Vectors, Search, Retrieval)
    • Introduction to Embeddings at Cohere
    • Semantic Search with Embeddings
    • Multimodal Embeddings
    • Batch Embedding Jobs
  • Going to Production
    • API Keys and Rate Limits
    • Going Live
    • Deprecations
    • How Does Cohere's Pricing Work?
  • Integrations
    • Integrating Embedding Models with Other Tools
    • Cohere and LangChain
    • LlamaIndex and Cohere
  • Deployment Options
    • Overview
    • SDK Compatibility
  • Tutorials
    • Cookbooks
    • LLM University
    • Build Things with Cohere!
    • Agentic RAG
    • Cohere on Azure
  • Responsible Use
    • Security
    • Usage Policy
    • Command A Technical Report
    • Command R and Command R+ Model Card
  • Cohere Labs
    • Cohere Labs Acceptable Use Policy
  • More Resources
    • Cohere Toolkit
    • Datasets
    • Improve Cohere Docs
    • Programmatic Fine-tuning
LogoLogodocs
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
On this page
  • Datasets
  • Starting a Fine-tuning Job
  • Fine-tuning results

Programmatic Fine-tuning with Cohere’s Python SDK

Was this page helpful?
Edit this page
Previous
Built with

In addition to using the Web UI for fine-tuning models, customers can also kick off fine-tuning jobs programmatically using the Fine-tuning API or via the Cohere Python SDK. This can be useful for fine-tunes that happen on a regular cadence, such as fine-tuning nightly on newly-acquired data.

Datasets

Before a fine-tune job can be started, users must upload a Dataset with training and (optionally) evaluation data. The contents and structure of the dataset will vary depending on the type of fine-tuning. Read more about preparing the training data for Chat, Classify, and Rerank fine-tuning.

The snippet below creates a dataset for fine-tuning a model on records of customer service interactions.

PYTHON
1# create a dataset
2co = cohere.ClientV2("Your API key")
3
4my_dataset = co.datasets.create(
5 name="customer service logs",
6 type="chat-finetune-input",
7 data=open("./customer-chat.jsonl", "rb"),
8 eval_data=open("./customer-chat-eval.jsonl", "rb"),
9)
10
11result = co.wait(my_dataset)

Starting a Fine-tuning Job

Below is an example of starting a fine-tune job of a generative model for Chat using a dataset of conversational data.

PYTHON
1from cohere.finetuning import FinetunedModel, Settings, BaseModel
2
3# start training a custom model using the dataset
4finetuned_model = co.finetuning.create_finetuned_model(
5 request=FinetunedModel(
6 name="customer-service-chat-model",
7 settings=Settings(
8 base_model=BaseModel(
9 base_type="BASE_TYPE_CHAT",
10 ),
11 dataset_id=my_dataset.id,
12 ),
13 ),
14)

Fine-tuning results

When the fine-tune model is ready you will receive an email notification. You can explore the evaluation metrics using the Dashboard and try out your model using one of our APIs on the Playground.