New cohort: Agentic AI & LLM Engineering remote internship. Limited seats.Apply now
Lesson 16 of 21 22 minFree

Open-Source Models and Hugging Face

What open models are, how to find and choose them on Hugging Face, how to read a model card and licence, and how to run them yourself.

By the end of this lesson you will be able to:

  • Explain what "open source", "open weights" and "open model" mean, and why the difference matters.
  • Find, compare and choose models on the Hugging Face Hub.
  • Read a model card: size, licence, intended use and limitations.
  • Run an open model with the transformers library, an inference API or a local tool.

Why open models?

So far most of our study buddy runs on hosted, proprietary APIs. That's quick to start with, but some schools ask hard questions: "Can student data stay on our own servers?", "Can it work offline in a village school?", "Can we customise the model for Telugu?". Open models make all of that possible. You download the model and run it wherever you want.

  • Control and privacy: data never leaves your infrastructure.
  • Customisation: fine-tune freely on your own data (Lesson 18).
  • Cost at scale: no per-token fees, though you pay for hardware.
  • Transparency: you can inspect, test and benchmark the exact model you ship.

"Open" means different things

  • Open source (in the strict sense): code, weights and training data or recipe available, under a licence allowing use, study, modification and sharing. Fully open models are still relatively rare.
  • Open weights: the trained weights are downloadable, but the training data usually isn't, and the licence may add conditions. Many popular "open" models are in this group.

Always read the licence. Apache 2.0 and MIT allow commercial use with few conditions. Others, such as the Llama and Gemma licences, allow most uses but add their own terms. Check before you build a product on a model.

Hugging Face: the home of open models

Hugging Face is the largest hub for open models, datasets and demos ("Spaces"). You can search and filter models by task, language, size and licence, and every model has a model card describing it. Explore a small galaxy of well-known models below.

Reading a model card

Before using any model, check its card for:

  1. Task and modality: text generation, speech-to-text, embeddings, image generation.
  2. Size: parameter count, which decides the hardware you need (Lesson 19).
  3. Licence: commercial use, attribution, restrictions.
  4. Training data and languages: does it handle Hindi, Tamil or your domain?
  5. Evaluation results: benchmarks are useful hints, but test on your own task (Lesson 14).
  6. Intended use, limitations and biases: what the authors say it should not be used for.

Three ways to run an open model

1. In Python with transformers

# pip install transformers torch
from transformers import pipeline

generator = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct")
messages = [{"role": "user", "content": "Explain gravity to a Class 6 student in 2 lines."}]
print(generator(messages, max_new_tokens=80)[0]["generated_text"])

The first run downloads the weights (several GB), and a GPU makes it much faster.

2. Hosted inference

Hugging Face Inference Endpoints, Azure AI Foundry's model catalogue and similar services run open models for you behind an API, with no hardware to manage.

3. Locally with one command

Tools like Ollama, LM Studio and llama.cpp run quantised open models on a laptop: ollama run llama3.2 and you're chatting offline.

Hands-on

Your task: the school needs a text model, with a licence of Apache 2.0 or MIT, and at most 8B parameters so it runs on their GPU. Complete fits(), then the code prints the shortlist, smallest first. Expected: Shortlist: Phi-3-mini, Qwen2.5 7B, Mistral 7B.

catalog = [
    {"name": "Llama 3.1 8B",   "task": "text",   "params_b": 8,    "license": "Llama licence"},
    {"name": "Mistral 7B",     "task": "text",   "params_b": 7.3,  "license": "Apache 2.0"},
    {"name": "Mixtral 8x7B",   "task": "text",   "params_b": 46.7, "license": "Apache 2.0"},
    {"name": "Phi-3-mini",     "task": "text",   "params_b": 3.8,  "license": "MIT"},
    {"name": "Qwen2.5 7B",     "task": "text",   "params_b": 7,    "license": "Apache 2.0"},
    {"name": "Whisper large",  "task": "speech", "params_b": 1.55, "license": "MIT"},
]
OK_LICENSES = {"Apache 2.0", "MIT"}

def fits(model):
    # TODO: True when task is "text", the licence is in OK_LICENSES and params_b <= 8
    return True

shortlist = sorted((m for m in catalog if fits(m)), key=lambda m: m["params_b"])
print("Shortlist:", ", ".join(m["name"] for m in shortlist))
Show solution
def fits(model):
    return model["task"] == "text" and model["license"] in OK_LICENSES and model["params_b"] <= 8

Your task: before approving a model, the team checks that its card has every required section. Complete missing_sections() and fill in the gaps in card (add a license and limitations) until it prints Card complete: True.

REQUIRED = ["task", "params", "license", "languages", "intended_use", "limitations"]

card = {
    "task": "text-generation",
    "params": "3.8B",
    "languages": ["English"],
    "intended_use": "Chat and reasoning in English",
    # TODO: add "license": "MIT" and "limitations": "May produce inaccurate facts; weaker on non-English text"
}

def missing_sections(card):
    # TODO: return a list of REQUIRED keys that are missing or empty in card
    return ["(not checked yet)"]

missing = missing_sections(card)
print("Missing:", missing if missing else "nothing")
print("Card complete:", not missing)
Show solution
card["license"] = "MIT"
card["limitations"] = "May produce inaccurate facts; weaker on non-English text"

def missing_sections(card):
    return [key for key in REQUIRED if not card.get(key)]

Check your understanding

What's the difference between "open weights" and fully "open source" models?

  1. There is no difference
  2. Open weights share the trained weights, but usually not the training data or full recipe
  3. Open-weight models can't be downloaded
  4. Open source models are always smaller

Many popular "open" models release weights only, often under custom licences.

Before building a paid product on an open model, what must you check?

  1. Its number of likes
  2. Its release date
  3. The colour of its logo
  4. Its licence terms in the model card

Licences decide whether, and how, you can use a model commercially.

A school wants an assistant that works offline on teachers' laptops. Which option fits?

  1. A small open model run locally with a tool like Ollama
  2. The largest hosted proprietary model
  3. A model that only runs on an 8-GPU server
  4. Any model, with a higher temperature

Small open models run locally and offline. Lesson 19 covers them in depth.

Key takeaways

  • Open models give control, privacy and customisation. You trade convenience for hardware and responsibility.
  • "Open" ranges from open weights to fully open source, so always read the licence.
  • Use Hugging Face to search, compare and read model cards.
  • Run models with transformers, hosted endpoints or local tools like Ollama, and evaluate on your own task.

Next: AI agents, models that plan and use tools to finish multi-step tasks.

Your progress is saved in this browser.

Adapted from Lesson 16 of Microsoft's "Generative AI for Beginners" (MIT License), rewritten and extended by Aiprojects4U. View source