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
    • Train and deploy a fine-tuned model
LogoLogodocs
DASHBOARDPLAYGROUNDDOCSCOMMUNITYLOG IN
On this page
  • Web UI
  • Choose the Classify Option
  • Upload Your Data
  • Preview Your Data
  • Start Training
  • Calling the Fine-tuned Model
  • Python SDK
  • Create a New Fine-tuned Model
  • Examples
  • Starting a single-label fine-tuning job
  • Starting a multi-label fine-tuning job
  • Calling a fine-tuned model

Train and deploy a fine-tuned model.

Was this page helpful?
Edit this page
Previous
Built with

In this section, we will walk through how you can start training a fine-tuning model for Classification with both the Web UI and the Python SDK.

Web UI

Creating a fine-tuned model for Classification with the Web UI consists of a few simple steps, which we’ll walk through now.

Choose the Classify Option

Go to the fine-tuning page and click on ‘Create a Classify model’.

Upload Your Data

Upload your custom dataset data by going to ‘Training data’ and clicking on the upload file button. Your data should be in csv or .jsonl format with exactly two columns—the first column consisting of the examples, and the second consisting of the labels.

You also have the option of uploading a validation dataset. This will not be used during training, but will be used for evaluating the model’s performance post-training. To upload a validation set, go to ‘Upload validation set (optional)’ and repeat the same steps you just went through with the training dataset. If you don’t upload a validation dataset, the platform will automatically set aside part of the training dataset to use for validation.

At this point in time, if there are labels in the training set with less than five unique examples, those labels will be removed.

set.
The 'Area' label had fewer than five examples, so it has been removed from the training set.

Once done, click ‘Next’.

Preview Your Data

The preview window will show a few samples of your custom training dataset, and your validation dataset (if you uploaded it).

Toggle between the ‘Training’ and ‘Validation’ tabs to see a sample of your respective datasets.

At the bottom of this page, the distribution of labels in each respective dataset is shown.

If you are happy with how the samples look, click ‘Continue’.

Start Training

Now, everything is set for training to begin! Click ‘Start training’ to proceed.

Calling the Fine-tuned Model

Once your model completes training, you can call it via the API. See here for an example using the Python SDK.

Python SDK

Text classification is one of the most common language understanding tasks. A lot of business use cases can be mapped to text classification. Examples include:

  • Evaluating the tone and sentiment of an incoming customer message (e.g. classes: ‘positive’ and ‘negative’).
  • Routing incoming customer messages to the appropriate agent (e.g. classes: ‘billing’, ‘tech support’, ‘other’).
  • Evaluating if a user comment needs to be flagged for moderator attention (e.g. classes: ‘flag for moderation’, ‘neutral’).
  • Evaluating which science topic a given piece of text is related to (e.g. classes: ‘biology’, ‘physics’). Since a given piece of text might be germane to more than one topic, this is an example of ‘multilabel’ classification, which is discussed in more detail at the end of this document.

Create a New Fine-tuned Model

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

Using co.finetuning.create_finetuned_model(), you can create a fine-tuned model using either a single-label or multi-label dataset.

Examples

Here are some example code snippets for you to use.

Starting a single-label fine-tuning job

PYTHON
1# create dataset
2single_label_dataset = co.datasets.create(
3 name="single-label-dataset",
4 data=open("single_label_dataset.jsonl", "rb"),
5 type="single-label-classification-finetune-input",
6)
7
8print(co.wait(single_label_dataset).dataset.validation_status)
9
10# start the fine-tune job using this dataset
11from cohere.finetuning.finetuning import (
12 BaseModel,
13 FinetunedModel,
14 Settings,
15)
16
17single_label_finetune = co.finetuning.create_finetuned_model(
18 request=FinetunedModel(
19 name="single-label-finetune",
20 settings=Settings(
21 base_model=BaseModel(
22 base_type="BASE_TYPE_CLASSIFICATION",
23 ),
24 dataset_id=single_label_dataset.id,
25 ),
26 ),
27)
28
29print(
30 f"fine-tune ID: {single_label_finetune.finetuned_model.id}, fine-tune status: {single_label_finetune.finetuned_model.status}"
31)

Starting a multi-label fine-tuning job

PYTHON
1# create dataset
2multi_label_dataset = co.datasets.create(
3 name="multi-label-dataset",
4 data=open("multi_label_dataset.jsonl", "rb"),
5 type="multi-label-classification-finetune-input",
6)
7
8print(co.wait(multi_label_dataset).dataset.validation_status)
9
10# start the fine-tune job using this dataset
11from cohere.finetuning.finetuning import (
12 BaseModel,
13 FinetunedModel,
14 Settings,
15)
16
17multi_label_finetune = co.finetuning.create_finetuned_model(
18 request=FinetunedModel(
19 name="multi-label-finetune",
20 settings=Settings(
21 base_model=BaseModel(
22 base_type="BASE_TYPE_CLASSIFICATION",
23 ),
24 dataset_id=multi_label_dataset.id,
25 ),
26 ),
27)
28
29print(
30 f"fine-tune ID: {multi_label_finetune.finetuned_model.id}, fine-tune status: {multi_label_finetune.finetuned_model.status}"
31)

Calling a fine-tuned model

PYTHON
1import cohere
2
3co = cohere.ClientV2("Your API key")
4# get the custom model object (replace with your finetune name e.g. multi_label_finetune)
5model_id = single_label_finetune.finetuned_model.id
6
7
8response = co.classify(
9 inputs=["classify this!"], model=model_id + "-ft"
10)
11
12print(response)

We can’t wait to see what you start building! Share your projects or find support on our Discord.