Blenderbot FineTuning
Asked Answered
J

1

6

I have been trying to fine-tune a conversational model of HuggingFace: Blendebot. I have tried the conventional method given on the official hugging face website which asks us to do it using the trainer.train() method. I tried it using the .compile() method. I have tried fine-tuning using PyTorch as well as TensorFlow on my dataset. Both methods seem to fail and give us an error saying that there is no method called compile or train for the Blenderbot model. I have even looked everywhere online to check how Blenderbot could be fine-tuned on my custom data and nowhere does it mention properly that runs without throwing an error. I have gone through Youtube tutorials, blogs, and StackOverflow posts but none answer this question. Hoping someone would respond here and help me out. I am open to using other HuggingFace Conversational Models as well for fine-tuning.

Here is a link I am using to fine-tune the blenderbot model.

Fine-tuning methods: https://huggingface.co/docs/transformers/training

Blenderbot: https://huggingface.co/docs/transformers/model_doc/blenderbot

from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
mname = "facebook/blenderbot-400M-distill"
model = BlenderbotForConditionalGeneration.from_pretrained(mname)
tokenizer = BlenderbotTokenizer.from_pretrained(mname)


#FOR TRAINING: 

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=small_train_dataset,
    eval_dataset=small_eval_dataset,
    compute_metrics=compute_metrics,
)
trainer.train()

#OR

model.compile(
    optimizer=tf.keras.optimizers.Adam(learning_rate=5e-5),
    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
    metrics=tf.metrics.SparseCategoricalAccuracy(),
)

model.fit(tf_train_dataset, validation_data=tf_validation_dataset, epochs=3)

None of these work.

Jeanne answered 27/6, 2022 at 18:30 Comment(1)
How are you passing the dataset?Thurible
B
1

Maybe try using the TFBlenderbotForConditionalGeneration class for Tensorflow. It has what you need:

import tensorflow as tf
from transformers import BlenderbotTokenizer, TFBlenderbotForConditionalGeneration

mname = "facebook/blenderbot-400M-distill"
model = TFBlenderbotForConditionalGeneration.from_pretrained(mname)
tokenizer = BlenderbotTokenizer.from_pretrained(mname)

model.compile(
    optimizer=tf.keras.optimizers.Adam(learning_rate=5e-5),
    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
    metrics=tf.metrics.SparseCategoricalAccuracy(),
)
....

See the docs for more information.

Beane answered 28/6, 2022 at 6:46 Comment(2)
It works well till model.compile(), but again does not work once I try to do model.fit(). Do you have an idea why that would be happening?Jeanne
Posting the picture below!Jeanne

© 2022 - 2024 — McMap. All rights reserved.