Saving and reloading Hugging Face models
In this exercise, you’ll practice to save a Hugging Face model locally and reload it for future use. This is essential for offline access, custom modifications, or efficient deployment.
The pipeline
class has already been imported for you.
Note: the .save_pretrained()
and .from_pretrained()
functions were modified for the purpose of this exercise.
This exercise is part of the course
Working with Hugging Face
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
modelId = "distilbert-base-uncased-finetuned-sst-2-english"
my_pipeline = ____("text-classification", model=modelId)
# Save the model locally
my_pipeline.____(f"models/{modelId}")