📚 Lesson 2.3: Overview of Hugging Face Transformers and Open LLMs

📚 Lesson 2.3: Overview of Hugging Face Transformers and Open LLMs


🤖 What Are Hugging Face Transformers?

Hugging Face is like the GitHub of AI models—a platform where you can find, share, and use pre-trained machine learning models. It’s especially popular in Natural Language Processing (NLP) for working with transformer-based models (like BERT, GPT, and others).

At the core of this platform is the 🤗 Transformers library, a Python package that allows you to:

  • Load thousands of ready-to-use language models

  • Fine-tune them on your own data

  • Use them for tasks like chat, question answering, summarization, translation, and more

It’s beginner-friendly, well-documented, and works with popular frameworks like PyTorch, TensorFlow, and JAX.


🧠 What Are Transformers?

Transformers are a type of neural network architecture designed to understand and generate human language.

Why they matter:

Before transformers, AI models struggled to understand context in long texts. Transformers introduced self-attention, which helps models focus on the important parts of a sentence or paragraph, regardless of its position.

Example:
In the sentence “The apple fell from the tree because it was ripe,” a transformer can figure out that “it” refers to “apple.”


💬 Key Features of Hugging Face Transformers

Feature What It Means
🧠 Pretrained Models Use state-of-the-art models without training from scratch
🔄 Easy Switching Swap models (like GPT, BERT, RoBERTa) in one line of code
📦 Tokenizers Converts text into tokens for the model to understand
🧪 Pipelines High-level tools for tasks like QA, chat, or summarization
🔧 Customization Fine-tune models with your own data

🔍 Common Use Cases

With Hugging Face Transformers, you can build AI tools for:

  • 🗣️ Chatbots

  • 🤖 Question Answering (QA)

  • 📝 Text Summarization

  • 🌍 Language Translation

  • 🧠 Text Classification

  • 🧾 Document Search & Retrieval


🧰 Sample Code: Loading a Model with Transformers

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_name = "mistralai/Mistral-7B-Instruct-v0.1"

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Example prompt
input_text = "What is quantum computing?"
input_ids = tokenizer.encode(input_text, return_tensors="pt")

# Generate output
output = model.generate(input_ids, max_length=100, do_sample=True)
response = tokenizer.decode(output[0], skip_special_tokens=True)

print(response)

🔓 What Are Open LLMs?

Open LLMs (Large Language Models) are language models that are:

  • Free to use

  • Open to inspect, fine-tune, and host yourself

  • Built by communities or research labs (not big tech companies)


🧠 Examples of Popular Open LLMs:

Model Name Creator Notes
LLaMA 2 Meta Open weights; strong for chat, research, and custom apps
Mistral 7B Mistral AI Lightweight, fast, and surprisingly strong for its size
DeepSeek LLM DeepSeek Good reasoning, open weights, optimized for research and coding
Falcon TII (UAE) Strong in summarization and classification
Vicuna LMSYS Fine-tuned on ChatGPT data; chat-focused
Nous Hermes, OpenChat, Zephyr Community projects Fine-tuned and trained for different tasks and tones

🧪 Where to Find These Models:

You’ll find all of these on Hugging Face Model Hub. You can filter models by:

  • Task (chat, summarization, etc.)

  • Language

  • Model size (from 1B to 70B+ parameters)

  • License (some open for commercial use, others for research only)


🤖 Open LLM vs Commercial LLM (Recap)

Feature Open LLMs Commercial LLMs (e.g., ChatGPT)
Cost Free Pay-per-use (API fees)
Customization Full (you can fine-tune or retrain) Very limited
Runs Offline Yes No
Data Privacy You control all data Data goes to company servers
Setup Required Yes (more technical) No setup required

💡 Why This Matters for You

By learning Hugging Face Transformers and using open LLMs, you’ll be able to:

✅ Build AI tools that are free to run
✅ Fine-tune or customize your chatbot’s behavior
✅ Store and retrieve your own data securely
✅ Run everything offline or on your own server


🏁 Summary

In this course, you’ll use Hugging Face Transformers and open LLMs to:

  • Load and run language models locally or in the cloud

  • Customize and connect them to your interface

  • Power your own ChatGPT-like assistant

Coming up next, we’ll explore how to choose the best LLM for your project based on speed, memory size, accuracy, and ease of use.


Absolutely! Here’s both:


📎 Hugging Face Model Cheat Sheet

🔗 Popular Open-Source LLMs for Chatbots, Reasoning, and General Use

Model Name Hugging Face Link Description
Mistral 7B Instruct 🔗 mistralai/Mistral-7B-Instruct-v0.1 Fast, small (7B), high-quality for general chatbot use
LLaMA 2 Chat (7B/13B/70B) 🔗 meta-llama/Llama-2-7b-chat Strong multitask chat model; research license only
DeepSeek LLM Chat 🔗 deepseek-ai/deepseek-llm-7b-chat Excellent for reasoning, Q&A, and programming help
OpenChat 3.5 🔗 openchat/openchat-3.5-1210 Open fine-tune of Mistral; chat-oriented, competitive with GPT-3.5
Zephyr 7B 🔗 HuggingFaceH4/zephyr-7b-beta Lightweight, instruction-tuned model for conversational agents
Nous Hermes 2 Mistral 🔗 nousresearch/nous-hermes-2-mistral-7b Polished chat model fine-tuned on open chat data
Falcon 7B Instruct 🔗 tiiuae/falcon-7b-instruct Efficient and accurate; licensed for research & commercial use
Gemma 7B (Google) 🔗 google/gemma-7b Strong multilingual base model, optimized for research use

📊 Comparison Chart of Top Open-Source LLMs (as of mid-2025)

Model Params Best For Speed (🟢=fast) Hardware Need License Hugging Face URL
Mistral 7B Instruct 7B Chat, summaries, Q&A 🟢🟢🟢🟢🟢 Medium Apache 2.0 Link
LLaMA 2 Chat 7B–70B General conversation 🟢🟢🟢 (7B) Medium–High Non-commercial Link
DeepSeek LLM Chat 7B Logic, code, Q&A 🟢🟢🟢🟢 Medium Apache 2.0 Link
OpenChat 3.5 7B GPT-3.5 level chatbot 🟢🟢🟢🟢 Medium MIT Link
Zephyr 7B 7B Instruction-following, chat 🟢🟢🟢 Low–Medium Apache 2.0 Link
Nous Hermes 2 Mistral 7B Dialogue, emotional tone 🟢🟢🟢 Medium Apache 2.0 Link
Falcon 7B Instruct 7B Summarization, Q&A 🟢🟢🟢 Medium Apache 2.0 Link
Gemma 7B 7B Base model, multilingual 🟢🟢🟢 Medium Apache 2.0 Link

 

104