Thursday, May 2, 2024

Fine-Tune Command R+ Model on Your Own Data Locally

 This video is a simple hands-on tutorial to show how to do fine-tuning of Command R+ model from cohere locally by using your own data.


Code:

#pip install cohere
import os
import cohere
from cohere.finetuning import (
    BaseModel,
    BaseType,
    FinetunedModel,
    Settings,
)


api_key = os.getenv('COHERE_API_KEY')
co = cohere.Client(api_key)

# create a dataset
single_label_dataset = co.datasets.create(name="single-label-dataset",
                                         data=open("train.csv", "rb"),
                                         type="single-label-classification-finetune-input")

#print(co.wait(single_label_dataset))

datasetid=single_label_dataset.id

finetuned_model = co.finetuning.create_finetuned_model(
    request=FinetunedModel(
        name="test-finetuned-model",
        settings=Settings(
            base_model=BaseModel(
                base_type="BASE_TYPE_CLASSIFICATION",
            ),
            dataset_id=datasetid,
        ),
    )
)
print(finetuned_model)


No comments: