Hugging Face Tutorial
This Hugging Face tutorial shows you how to find, run, adapt and share open-weight AI models using Python. Hugging Face is a company and a community platform that hosts hundreds of thousands of machine learning models, datasets and demo apps, plus the open-source libraries that make them easy to use.
If you have used a hosted chatbot API and wondered how to run a model on your own machine, or how to build a search engine from embeddings, or how to fine-tune a model on your own data, Hugging Face is where most of that work starts.
What is Hugging Face?
Think of Hugging Face as two things working together.
The Hub (huggingface.co) is like GitHub for machine learning. Every model, dataset and Space (a hosted demo app) lives in a Git-based repository with a model card, files, version history and a license.
The libraries are Python packages that download those repositories and run them: transformers for models, tokenizers for fast text splitting, datasets for loading and processing data, peft for parameter-efficient fine-tuning, huggingface_hub for talking to the Hub, and gradio for building quick web demos.
Why Learn Hugging Face?
- It is the default place where open-weight models such as Llama, Qwen, Mistral, Gemma and Phi are published.
- One consistent API covers text, vision, audio and multimodal models.
- You can run models locally for privacy and zero per-token cost.
- Fine-tuning a small model on your own data is achievable on a single GPU with LoRA.
- Spaces let you share a working AI demo with a public URL in minutes.
Your First Hugging Face Model
The quickest way in is the pipeline function from transformers. It picks a sensible default model for a task, downloads it once, and handles all the pre- and post-processing for you:
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
print(classifier("I finally understand how transformers work!"))[{'label': 'POSITIVE', 'score': 0.9997}]The first run downloads the model weights into a local cache (usually ~/.cache/huggingface). Later runs load from disk and are much faster. The score is the model's confidence; your exact number may differ slightly between library versions.
What This Tutorial Covers
- Installing the libraries and logging in to the Hub
- Exploring models, datasets and Spaces on the Hub
- Pipelines, tokenizers and the AutoModel / AutoTokenizer classes
- Text generation with open-weight chat models
- Embeddings and semantic search with sentence-transformers
- The datasets library, fine-tuning with Trainer and LoRA with PEFT
- Quantization with bitsandbytes and GGUF files
- Hosted inference, Gradio Spaces and open model licenses
Prerequisites
You should be comfortable with basic Python: variables, functions, lists and dictionaries, and installing packages with pip. Knowing a little PyTorch helps for the fine-tuning chapters, but it is not required to get started. A GPU is optional for most lessons; small models run fine on a laptop CPU.
Frequently asked questions
Is Hugging Face free to use?
Yes. Creating an account, downloading public models and using the open-source libraries is free. Paid plans cover things like private storage limits, more compute for Spaces, dedicated Inference Endpoints and team features.
Is Hugging Face the same as transformers?
No. Hugging Face is the company and platform; transformers is its most popular open-source Python library. The library downloads models from the Hugging Face Hub, but the Hub also hosts models for other libraries.
Do I need a GPU to use Hugging Face?
Not to get started. Small models for classification, embeddings and even small chat models run on a CPU. Larger language models and fine-tuning are much faster on a GPU.