Home Knowledge Base Hugging Face Hub

Hugging Face Hub is the central repository for open-source machine learning models, datasets, and applications — hosting hundreds of thousands of models with versioning, access control, and serving infrastructure, making it the GitHub of machine learning and the primary distribution channel for open-source AI.

What Is Hugging Face Hub?

Why Hub Matters

Using Hub Models

Basic Model Loading:

from transformers import AutoModelForCausalLM, AutoTokenizer

# Load model and tokenizer
model_name = "meta-llama/Llama-3.1-8B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

Inference with Pipeline:

from transformers import pipeline

# Quick inference
generator = pipeline("text-generation", model="gpt2")
output = generator("Hello, I am", max_length=50)
print(output[0]["generated_text"])

# Sentiment analysis
classifier = pipeline("sentiment-analysis")
result = classifier("I love this product!")
# [{"label": "POSITIVE", "score": 0.99}]

Model Card:

Every model page includes:
- Model description and capabilities
- Usage examples
- Training details
- Limitations and biases
- Evaluation results
- License

Uploading Models

Via Python:

from huggingface_hub import HfApi

api = HfApi()

# Create repo
api.create_repo("my-username/my-model", private=False)

# Upload model files
api.upload_folder(
    folder_path="./model_output",
    repo_id="my-username/my-model",
)

Via Transformers:

# After training
model.push_to_hub("my-username/my-model")
tokenizer.push_to_hub("my-username/my-model")

Via CLI:

# Login first
huggingface-cli login

# Upload
huggingface-cli upload my-username/my-model ./model_output

Dataset Hub

from datasets import load_dataset

# Load dataset
dataset = load_dataset("squad")

# Load specific split
train_data = load_dataset("squad", split="train")

# Load from Hub
custom_data = load_dataset("my-username/my-dataset")

# Preview
print(dataset["train"][0])

Spaces (ML Apps)

Create Gradio Demo:

import gradio as gr

def predict(text):
    return f"You said: {text}"

demo = gr.Interface(fn=predict, inputs="text", outputs="text")
demo.launch()

# Deploy to Space
# Create Space on HF, push this code

Popular Space Types:

Type        | Framework   | Use Case
------------|-------------|------------------------
Gradio      | gradio      | Interactive demos
Streamlit   | streamlit   | Dashboards
Docker      | Docker      | Custom apps
Static      | HTML/JS     | Simple pages

Model Discovery

Search Filters:

- Task: text-generation, image-classification, etc.
- Library: transformers, diffusers, timm
- Dataset: Models trained on specific data
- Language: en, zh, multilingual
- License: MIT, Apache, commercial

API Access:

from huggingface_hub import HfApi

api = HfApi()

# Search models
models = api.list_models(
    filter="text-generation",
    sort="downloads",
    limit=10
)

for model in models:
    print(f"{model.modelId}: {model.downloads} downloads")

Inference API

import requests

API_URL = "https://api-inference.huggingface.co/models/gpt2"
headers = {"Authorization": "Bearer YOUR_TOKEN"}

response = requests.post(
    API_URL,
    headers=headers,
    json={"inputs": "Hello, I am"}
)
print(response.json())

Best Practices

Hugging Face Hub is the infrastructure backbone of open-source AI — providing the discovery, distribution, and collaboration tools that enable the community to share and build upon each other's work, democratizing access to state-of-the-art models.

hugging facemodel hubtransformersdatasetsspacesopen source modelsmodel hosting

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.