Haga fine-tuning de un modelo de Hugging Face
Adapte un transformer preentrenado a sus datos
Haga fine-tuning de un modelo de Hugging Face es una lección gratuita de Deep Learning Academy en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Deep Learning Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Deep Learning Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
A Hub of Pretrained Models
Hugging Face hosts thousands of ready-to-use transformers for text, vision, and audio. You can fine-tune one on your own data in minutes. 🤗
Install Transformers
The transformers library gives you models, tokenizers, and training tools in one package.
pip install transformers datasetsLoad a Tokenizer
Text must become numbers first. The tokenizer that ships with each model knows exactly how to split and encode your text.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained('bert-base-uncased')Load a Model With a New Head
Pick a class for your task. AutoModelForSequenceClassification loads the backbone and attaches a fresh classifier head for your labels.
from transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)Tokenize Your Dataset
Run every example through the tokenizer with padding and truncation so all inputs share the same length.
def encode(b):
return tok(b['text'], truncation=True, padding='max_length')TrainingArguments
TrainingArguments bundles your hyperparameters: learning rate, batch size, epochs, and where to save checkpoints.
from transformers import TrainingArguments
args = TrainingArguments(output_dir='out', learning_rate=2e-5, num_train_epochs=3)Keep That Rate Low
Notice the rate is just 2e-5. As with any fine-tune, a small learning rate protects the pretrained weights from being wrecked.
The Trainer
The Trainer class wraps the whole loop: forward pass, loss, backward, step, and evaluation. You skip writing it by hand.
from transformers import Trainer
trainer = Trainer(model=model, args=args, train_dataset=train_ds)Train in One Call
Once everything is wired up, kick off fine-tuning with a single train call and watch the loss fall.
trainer.train()Evaluate and Predict
After training, call evaluate for metrics on held-out data, then use predict to score brand-new examples.
trainer.evaluate()Save and Share
Persist your tuned model with save_pretrained, then reload it anywhere or push it to the Hub for others to use.
model.save_pretrained('my-classifier')Quick Check
Which Hugging Face class runs the full training loop for you so you don't write it by hand?
Recap
You tokenized data, loaded a model with a fresh head, set a low rate in TrainingArguments, and fine-tuned it with the Trainer. 🎯
Preguntas frecuentes
¿La lección «Haga fine-tuning de un modelo de Hugging Face» es gratis?
Sí — el texto completo de «Haga fine-tuning de un modelo de Hugging Face» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Deep Learning Academy, actualiza a CoddyKit PRO. El curso de Deep Learning Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Haga fine-tuning de un modelo de Hugging Face»?
Adapte un transformer preentrenado a sus datos Practicas Deep Learning Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Deep Learning Academy?
No se requiere experiencia previa. Deep Learning Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Haga fine-tuning de un modelo de Hugging Face»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Deep Learning Academy?
Sí. Cada lección de Deep Learning Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Congele el backbone y entrene el head
- Haga fine-tuning con una tasa de aprendizaje menor
- Tasas discriminativas por capa
- Haga fine-tuning de un modelo de Hugging Face