Hugging Face
Hugging Face Inc.
An AI community platform providing models, datasets, applications, and a complete toolchain.
Overview
Hugging Face is the world's largest AI community platform, known as the 'GitHub of AI'. It provides a model hub (500k+ models), a dataset hub (100k+ datasets), application Spaces, and more. The Transformers library is the most popular NLP library, supporting 100+ models such as BERT, GPT, Llama, and Mistral. Hugging Face also provides tools such as Tokenizers, Diffusers, PEFT, and Accelerate, covering the entire AI development workflow. Whether for research or production, Hugging Face is a core platform for AI developers.
Models Hub
Models Hub is the core of Hugging Face, hosting 500k+ models. It covers fields such as NLP, computer vision, speech, and multimodal. Each model has a model card describing its use, performance, limitations, and more. It supports filtering by task, language, license, and more. Models can be downloaded and used with one click.
# Browse models
# https://huggingface.co/models
# Download a model
from huggingface_hub import snapshot_download
snapshot_download(repo_id="meta-llama/Llama-3.1-8B")
# Use the CLI
huggingface-cli download meta-llama/Llama-3.1-8B
# Upload a model
huggingface-cli upload my-model ./model_filesDatasets
Datasets Hub hosts 100k+ datasets, covering text, images, audio, and more. It provides a unified data loading interface, supporting streaming loading of large datasets. Datasets have dataset cards describing their content, format, license, and more. Dataset visualization preview is supported.
# Load a dataset
from datasets import load_dataset
# Load well-known datasets
dataset = load_dataset("squad")
dataset = load_dataset("imdb")
# Stream loading (large datasets)
dataset = load_dataset("oscar", streaming=True)
for example in dataset:
print(example)
break
# Upload a dataset
from huggingface_hub import HfApi
api = HfApi()
api.upload_folder(folder_path="./data", repo_id="my-dataset", repo_type="dataset")Transformers Library
Transformers is Hugging Face's core library, providing 100+ pre-trained models. It supports tasks such as text classification, generation, translation, and question answering. It provides a unified API that is easy to use. It supports PyTorch, TensorFlow, and JAX backends.
from transformers import pipeline
# Text classification
classifier = pipeline("sentiment-analysis")
result = classifier("I love AI!")
# Text generation
generator = pipeline("text-generation", model="gpt2")
text = generator("Once upon a time", max_length=50)
# Question answering
qa = pipeline("question-answering")
answer = qa(question="Who invented AI?", context="...")
# Use a specific model
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B")
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B")Tokenizers
The Tokenizers library provides high-performance tokenization tools. It supports algorithms such as BPE, WordPiece, and SentencePiece. Implemented in Rust, it is extremely fast. It supports training custom tokenizers, saving and loading.
from tokenizers import Tokenizer
from tokenizers.models import BPE
from tokenizers.trainers import BpeTrainer
from tokenizers.pre_tokenizers import Whitespace
# Train a tokenizer
tokenizer = Tokenizer(BPE(unk_token="[UNK]"))
trainer = BpeTrainer(special_tokens=["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]"])
tokenizer.pre_tokenizer = Whitespace()
tokenizer.train(files=["data.txt"], trainer=trainer)
# Use it
output = tokenizer.encode("Hello, world!")
print(output.tokens)
# Save
tokenizer.save("tokenizer.json")Spaces
Spaces is Hugging Face's application hosting platform. You can deploy ML applications, demos, and interactive visualizations. It supports frameworks such as Gradio, Streamlit, and Docker. It provides free CPU/GPU resources, suitable for showcasing and sharing ML applications.
# Gradio Space example
import gradio as gr
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
def predict(text):
return classifier(text)[0]
demo = gr.Interface(fn=predict, inputs="text", outputs="json")
demo.launch()
# Create a Space
# 1. Visit https://huggingface.co/new-space
# 2. Select an SDK (Gradio/Streamlit/Docker)
# 3. Upload code
# 4. Auto deployInference API
Hugging Face provides an Inference API, allowing you to use models without deployment. The free version has rate limits, and the paid version provides higher quotas. It also provides Inference Endpoints, allowing you to deploy dedicated inference services. Multiple task types are supported.
# Use the Inference API
import requests
API_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased-finetuned-sst-2-english"
headers = {"Authorization": "Bearer YOUR_API_TOKEN"}
response = requests.post(API_URL, headers=headers, json={
"inputs": "I love AI!"
})
print(response.json())
# Use huggingface_hub
from huggingface_hub import InferenceClient
client = InferenceClient()
result = client.text_classification("I love AI!")Fine-tuning
Hugging Face provides a complete fine-tuning toolchain. The PEFT library supports efficient fine-tuning methods such as LoRA and QLoRA. The TRL library supports alignment training such as RLHF and DPO. The Accelerate library simplifies distributed training. Transformers Trainer provides a unified training interface.
# Fine-tune with PEFT
from peft import LoraConfig, get_peft_model
from transformers import AutoModelForCausalLM, TrainingArguments, Trainer
model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B")
peft_config = LoraConfig(
r=8, lora_alpha=32, lora_dropout=0.1,
target_modules=["q_proj", "v_proj"]
)
model = get_peft_model(model, peft_config)
# Train
training_args = TrainingArguments(output_dir="./results", num_train_epochs=3)
trainer = Trainer(model=model, args=training_args, train_dataset=dataset)
trainer.train()Deployment
Hugging Face provides multiple deployment solutions. Inference Endpoints provides managed inference services, supporting auto-scaling. Transformers.js supports running models in the browser. Export to formats such as ONNX and TensorRT is supported for deployment to production environments.
# Create an Inference Endpoint
from huggingface_hub import HfApi
api = HfApi()
api.create_inference_endpoint(
name="my-endpoint",
repository="meta-llama/Llama-3.1-8B",
framework="pytorch",
accelerator="gpu",
instance_type="nvidia-a10g",
region="us-east-1"
)
# Export to ONNX
from transformers import AutoModelForSequenceClassification
from optimum.onnxruntime import ORTModelForSequenceClassification
model = ORTModelForSequenceClassification.from_pretrained("model", export=True)Community
Hugging Face has an active community. Communication happens via Discord, GitHub Discussions, and forums. Events such as model competitions, hackathons, and online sharing sessions are held regularly. The community contributes models, datasets, and applications, promoting the democratization of AI. Hugging Face also provides learning resources such as courses, tutorials, and blogs.
Configuration
Hugging Face is configured through environment variables, the huggingface-cli, and library-level settings. HF_TOKEN authenticates gated-model downloads and the Inference API; HF_HOME sets the cache root (default ~/.cache/huggingface); and transformers.from_pretrained accepts local paths, repo ids, and revision pins. Spaces are configured through a README.md front-matter (SDK, hardware, secrets) and a requirements.txt. The Hub supports private repos, organizations, and access tokens with scoped permissions.
# Environment variables
export HF_TOKEN=hf_xxx # authenticate gated models & API
export HF_HOME=/data/hf-cache # move the model cache off the home disk
export HF_HUB_DOWNLOAD_TIMEOUT=60 # per-request timeout
# CLI
huggingface-cli login --token $HF_TOKEN
huggingface-cli whoami
huggingface-cli download meta-llama/Llama-3.1-8B --local-dir ./llama
# Python - pin a revision and pick a cache dir
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.1-8B",
revision="refs/pr/42",
cache_dir="/data/hf-cache",
token=os.environ["HF_TOKEN"]
)
# Spaces config (README.md front-matter)
# ---
# title: My Space
# sdk: gradio
# hardware: a10g-small
# app_file: app.py
# ---Use 'huggingface-cli scan-cache' to list cached models and free disk space with 'huggingface-cli delete-cache'.
FAQ
Common questions cover gated models, cache location, private repos, Spaces billing, and the Inference API. Gated models require accepting a license on the model page before download, then a HF_TOKEN. The cache lives under ~/.cache/huggingface by default and can grow large. Spaces have free CPU tiers and paid GPU tiers billed per hour. The Inference API returns JSON and is rate-limited per token.
Q: How do I download a gated model?
A: Visit the model page, accept the license, then run
'huggingface-cli login' and 'huggingface-cli download <repo>'.
Q: Where is the model cache?
A: Under ~/.cache/huggingface by default. Change it with HF_HOME or
cache_dir= in from_pretrained. Scan it with 'huggingface-cli scan-cache'.
Q: Can I host private models?
A: Yes—create a private repo on the Hub or use a private Space; share it
with org members or via read-only tokens.
Q: How much do Spaces cost?
A: Free CPU Spaces are available; GPU hardware (A10G, A100) is billed
per hour. Stop the Space when you are not using it.
Q: What is the Inference API?
A: A hosted endpoint for popular models—POST to
api-inference.huggingface.co/models/<repo> with your HF_TOKEN. It is
rate-limited and not meant for production serving.For production serving, self-host the model with vLLM or TGI instead of relying on the shared Inference API.
More AI Guides
Claude Code
A terminal-native AI coding agent from Anthropic that autonomously understands codebases, edits files, runs commands, and completes multi-step development tasks.
OpenAI Codex
An official command-line AI coding assistant from OpenAI, built on the GPT model family and optimized for code generation and development workflows.
Trae
ByteDance's AI-native IDE—the first of its kind in China—deeply integrates LLMs such as Doubao and DeepSeek, supporting natural-language interaction and multimodal collaboration.
Cursor
A next-generation AI code editor from Anysphere with a built-in Composer agent that can run multiple coding tasks in parallel.
GitHub Copilot
An AI coding assistant co-developed by GitHub and OpenAI, offering code completion, chat, and an Agent mode.
Windsurf
An AI-native IDE from Codeium with a built-in Cascade agent that deeply couples the terminal and editor.