huggingface / diarizers

246 stars 16 forks source link

How can I save the model locally before pushing it to the Hub ?! #11

Closed ma-mohsen closed 3 months ago

kamilakesbi commented 3 months ago

Hi @ma-mohsen,

Thanks for this question! You can save your model locally by specifying output_dir in the TrainingArguments of the Trainer:

from transformers import TrainingArguments

training_args = TrainingArguments(
+    output_dir='./speaker-segmentation-fine-tuned-callhome-jpn',
    save_strategy="epoch",
    learning_rate=1e-3,
    num_train_epochs=5,
    lr_scheduler_type="cosine",
    per_device_train_batch_size=32,
    per_device_eval_batch_size=32,
    evaluation_strategy="epoch",
    gradient_accumulation_steps=1,
    dataloader_num_workers=2,
    logging_steps=25,
    load_best_model_at_end=True,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=train_set,
    data_collator=data_collator,
    eval_dataset=val_set,
    compute_metrics=metrics,
)
trainer.train()

Hope it will help you!

ma-mohsen commented 3 months ago

Thank you @kamilakesbi for your quick response. I appreciate that. so then for further use, we will do this ?!

from diarizers import SegmentationModel

# Path to the directory where the model is saved
model_directory = './speaker-segmentation-fine-tuned-callhome-jpn/checkpoint-XXXX'

# Load the fine-tuned model
fine_tuned_model = SegmentationModel.from_pretrained(model_directory)

# convert it to a pyannote format 
model = fine_tuned_model.to_pyannote_model()
kamilakesbi commented 3 months ago

Exactly :)