How to Download a Model from Hugging Face (original) (raw)

Last Updated : 11 May, 2026

Hugging Face models are pre-trained machine learning models that you can directly download and plug into our applications for tasks like text classification, translation, summarization and more without training from scratch.

Importance of Using Pre-Trained Models

Pre-trained models are models that have already been trained on large datasets. Using them offers several advantages:

Downloading a Model from Hugging Face

Step 1: Environment Setup

pip install transformers pip install torch

`

Step 2: Choose a Model from the Model Hub

Screenshot-2025-12-06-101300

Models from the Model Hub

Step 3: Download the Model and Tokenizer

We use AutoModelForSequenceClassification and AutoTokenizer from transformers to download and load the model.

Python `

from transformers import AutoModelForSequenceClassification, AutoTokenizer model_name = "bert-base-uncased" model = AutoModelForSequenceClassification.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name)

`

**Output:

Screenshot-2025-12-06-104108

Downloading

Step 4: Saving and Loading the Model Locally

1. If we want to keep a copy for offline use or reuse, we can save our downloaded model into a local directory.

Python `

model.save_pretrained("./my_local_model") tokenizer.save_pretrained("./my_local_model")

`

**Output:

Screenshot-2025-12-06-104120

Saving the Model

2. To load the saved model from local directory, we perform the following step

Python `

from transformers import AutoModelForSequenceClassification, AutoTokenizer local_model = AutoModelForSequenceClassification.from_pretrained( "./my_local_model") local_tokenizer = AutoTokenizer.from_pretrained("./my_local_model")

`

Step 5: Use the Model

Let's use the model to verify if it is working or not by performing a simple text classification.

Python `

text = "I love using Hugging Face models for NLP!" inputs = local_tokenizer(text, return_tensors="pt") outputs = local_model(**inputs) print(outputs.logits)

`

**Output:

tensor([[-0.1011, 0.3558]], grad_fn=)

Applications

Limitations

While convenient, using pre trained models also comes with certain constraints.