Sharing Fine-Tuned Models on Hugging Face

Once your model is fine-tuned, you can upload it to Hugging Face Model Hub for others to download or access via API.


from transformers import AutoModelForSequenceClassification, AutoTokenizer
from huggingface_hub import login

# Log in to Hugging Face (use your token from https://huggingface.co/settings/tokens)
login(token="your_huggingface_token")

# Load your fine-tuned model and tokenizer
model = AutoModelForSequenceClassification.from_pretrained("./my_fine_tuned_model")
tokenizer = AutoTokenizer.from_pretrained("./my_fine_tuned_model")

# Push them to the Hub
repo_name = "my-awesome-finetuned-model"
model.push_to_hub(repo_name)
tokenizer.push_to_hub(repo_name)

print(f"Model uploaded to https://huggingface.co/your-username/{repo_name}")
    

This helps build community collaboration and accelerates AI development.