Skip to content

Commit

Permalink
update classify finetuning snippets (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: trentfowlercohere <[email protected]>
Signed-off-by: Meor Amer <[email protected]>
Co-authored-by: trentfowlercohere <[email protected]>
  • Loading branch information
mrmer1 and trentfowlercohere authored Sep 24, 2024
1 parent 2da76e7 commit c822e9c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ Here are some example code snippets for you to use.

```python PYTHON
# create dataset
single_label_dataset = co.datasets.create(name="single-label-dataset",
data=open("path/to/train.csv, "rb"),
type="single-label-finetune-input",
parse_info=ParseInfo(delimiter=",")) # parse_info is optional
print(single_label_dataset.await_validation())
single_label_dataset = co.datasets.create(
name="single-label-dataset",
data=open("single_label_dataset.jsonl", "rb"),
type="single-label-classification-finetune-input",
)

print(co.wait(single_label_dataset).dataset.validation_status)

# start the fine-tuning job using this dataset
create_response = co.finetuning.create_finetuned_model(
# start the fine-tune job using this dataset
from cohere.finetuning.finetuning import BaseModel, FinetunedModel, Settings

single_label_finetune = co.finetuning.create_finetuned_model(
request=FinetunedModel(
name="single-label-ft",
name="single-label-finetune",
settings=Settings(
base_model=BaseModel(
base_type="BASE_TYPE_CLASSIFICATION",
Expand All @@ -115,33 +119,37 @@ create_response = co.finetuning.create_finetuned_model(
),
)

print(f"fine-tuned model ID: {create_response.finetuned_model.id}, fine-tuned model status: {create_response.finetuned_model.status}")
print(f"fine-tune ID: {single_label_finetune.finetuned_model.id}, fine-tune status: {single_label_finetune.finetuned_model.status}")
```

### Starting a multi-label fine-tuning job

```python PYTHON
# create dataset
multi_label_dataset = co.create_dataset(name="multi-label-dataset",
data=open("path/to/train.jsonl", "rb"),
dataset_type="multi-label-finetune-input")

print(multi_label_dataset.await_validation())
multi_label_dataset = co.datasets.create(
name="multi-label-dataset",
data=open("multi_label_dataset.jsonl", "rb"),
type="multi-label-classification-finetune-input",
)

print(co.wait(multi_label_dataset).dataset.validation_status)

# start the fine-tuning job using this dataset
create_response = co.finetuning.create_finetuned_model(
# start the fine-tune job using this dataset
from cohere.finetuning.finetuning import BaseModel, FinetunedModel, Settings

multi_label_finetune = co.finetuning.create_finetuned_model(
request=FinetunedModel(
name="single-label-ft",
name="multi-label-finetune",
settings=Settings(
base_model=BaseModel(
base_type="BASE_TYPE_CLASSIFICATION",
),
dataset_id=single_label_dataset.id,
dataset_id=multi_label_dataset.id,
),
),
)

print(f"fine-tuned model ID: {create_response.finetuned_model.id}, fine-tuned model status: {create_response.finetuned_model.status}")
print(f"fine-tune ID: {multi_label_finetune.finetuned_model.id}, fine-tune status: {multi_label_finetune.finetuned_model.status}")
```

### Calling a fine-tuned model
Expand All @@ -150,14 +158,15 @@ print(f"fine-tuned model ID: {create_response.finetuned_model.id}, fine-tuned mo
import cohere

co = cohere.Client('Your API key')
get_response = co.finetuning.get_finetuned_model(create_response.finetuned_model.id)
# get the custom model object (replace with your finetune name e.g. multi_label_finetune)
model_id = single_label_finetune.finetuned_model.id


response = client.classify(
response = co.classify(
inputs=["classify this!"],
model=get_response.finetuned_model.id+"-ft",
model=model_id+"-ft"
)

# Printing the model's response.
print(response)
```

Expand Down
2 changes: 1 addition & 1 deletion fern/v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ navigation:
contents:
- page: Preparing the Classify Fine-tuning data
path: pages/fine-tuning/classify-fine-tuning/classify-preparing-the-data.mdx
- page: Trains and deploys a fine-tuned model
- page: Training and deploying a fine-tuned model
path: pages/fine-tuning/classify-fine-tuning/classify-starting-the-training.mdx
- page: Understanding the Classify Fine-tuning Results
path: pages/fine-tuning/classify-fine-tuning/classify-understanding-the-results.mdx
Expand Down

0 comments on commit c822e9c

Please sign in to comment.