ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Getting Started with Local LLMs
Chapter 1: Introduction to Large Language Models
What Is a Large Language Model (LLM)?
A Simple View of How LLMs Work
Understanding Tokens and Text Generation
Why Run LLMs Locally?
Local vs. Cloud-Based LLMs
Quiz for Chapter 1
Chapter 2: Preparing Your Local Environment
Hardware Considerations: CPU
Hardware Considerations: RAM
Hardware Considerations: GPU and VRAM
Checking Your System Specifications
Operating System Compatibility
Installing Python (Optional but Recommended)
Introduction to the Command Line / Terminal
Quiz for Chapter 2
Chapter 3: Finding and Selecting Local LLMs
Where to Find LLM Models: Hugging Face Hub
Understanding Model Sizes and Parameters
Model Formats: GGUF and Others
Quantization: Making Models Smaller
Reading Model Cards for Information
Model Licenses and Usage Restrictions
Choosing Your First Model
Quiz for Chapter 3
Chapter 4: Running Your First Local LLM
Introduction to Local LLM Runners
Setting up Ollama
Downloading a Model with Ollama
Running a Model with Ollama (Command Line)
Setting up LM Studio
Finding and Downloading Models in LM Studio
Loading and Chatting with a Model in LM Studio
Introduction to llama.cpp (Concept)
Hands-on Practical: Running a Model
Quiz for Chapter 4
Chapter 5: Basic Interaction and Prompting
What is a Prompt?
Your First Prompt: Simple Questions
Giving Instructions
Understanding Context Window
Basic Prompt Formatting Tips
Temperature and Creativity
Common Interaction Patterns
Practice: Simple Prompting Techniques
Quiz for Chapter 5
Building a Customized Local AI Assistant

Understanding Tokens and Text Generation

Large Language Models are powerful tools for processing and generating human-like text. But how exactly does a computer model, which fundamentally works with numbers, handle something as complex as language? It doesn't read words or sentences like we do. Instead, it operates on units called tokens.

What Are Tokens?

Think of tokens as the basic building blocks of text for an LLM. Instead of processing text character by character (which would be very inefficient) or word by word (which struggles with variations like "run", "running", "ran" or punctuation), LLMs break text down into carefully chosen pieces. A token is often a whole word, but it can also be a part of a word (a subword), a single character, or punctuation.

For example, the sentence "Hello world!" might be broken down into tokens like this: ["Hello", " ", "!"]

Notice the space before the term is included in the token. A more complex word like "unbelievably" might be split differently depending on the model: ["un", "believe", "ably"] or perhaps ["unbeliev", "ably"]

This subword approach allows the model to handle variations and new words more effectively. It learns relationships between common word parts (un-, -ly, -ing) rather than having to learn every single word form from scratch.

The Tokenizer: Translator Between Text and Numbers

The component responsible for converting raw text into tokens and back again is called a tokenizer. Every LLM is trained with a specific tokenizer. This tokenizer has a defined vocabulary, the set of all possible tokens it knows.

Here's the process:

  1. Tokenization: The tokenizer takes your input text (like a prompt) and breaks it down into a sequence of tokens based on its rules and vocabulary.
  2. ID Conversion: Each token in the vocabulary corresponds to a unique numerical ID. The tokenizer converts the sequence of tokens into a sequence of these IDs. These numbers are what the LLM actually processes.
  3. Detokenization: When the LLM generates a sequence of output IDs, the tokenizer translates these numbers back into tokens and then joins them together to form readable text.

It's important that the same tokenizer used to train the model is also used when you interact with it. Using a different tokenizer would be like trying to communicate using a mismatched dictionary, leading to nonsensical results.

A simplified view of how text flows through the tokenization and generation process with an LLM.

Text Generation: Predicting the Next Token

Now that we understand tokens, how does the LLM actually generate text? Text generation is a step-by-step prediction process.

  1. Your input prompt is tokenized into a sequence of IDs.
  2. The LLM analyzes this sequence and predicts the most likely next token ID that should follow. This prediction is based on the extensive amount of text data it was trained on, allowing it to learn patterns, grammar, facts, and even writing styles.
  3. This newly predicted token ID is added to the end of the sequence.
  4. The LLM looks at the new, slightly longer sequence and predicts the next token ID.
  5. This process repeats, adding one token at a time, until the model predicts a special "end-of-sequence" token, reaches a length limit, or is otherwise instructed to stop.

Imagine completing the sentence: "The weather today is...". You might predict "sunny", "cloudy", or "rainy" based on context. An LLM does something similar, but on a massive scale and based purely on statistical patterns learned from its training data. It calculates probabilities for all possible tokens in its vocabulary and typically chooses the one with the highest probability (though techniques like adjusting the "temperature," discussed later, can add randomness).

For example, if the input tokens represent "Once upon a time, there", the model might predict the token for " was" as the most likely next token. The sequence becomes "Once upon a time, there was". Then, looking at this new sequence, it might predict " a". The sequence grows token by token: "Once upon a time, there was a...".

This iterative, token-by-token prediction is the fundamental mechanism behind how LLMs generate coherent and often complex text based on your input. The model's ability to make good predictions relies on the knowledge encoded within its parameters, which is why larger models with more parameters can often capture more intricate language patterns.

  • Neural Machine Translation of Rare Words with Subword Units, Rico Sennrich, Barry Haddow, and Alexandra Birch, 2016 ACL 2016 DOI: 10.48550/arXiv.1508.07909 - Introduces Byte Pair Encoding (BPE) for subword tokenization, a foundational method used in many LLMs.
  • Tokenization, Lewis Tunstall, Leandro von Werra, and Thomas Wolf, 2022 (O'Reilly Media) - Chapter 3 of 'Natural Language Processing with Transformers', explaining various tokenization algorithms and their implementation.
  • A Survey of Large Language Models, Wayne Xin Zhao, Kun Zhou, Junyi Li, Tianyi Tang, Xiaolei Wang, Yupeng Hou, Yingqian Min, Beichen Zhang, Junjie Zhang, Zican Dong, Yifan Du, Chen Yang, Yushuo Chen, Zhipeng Chen, Jinhao Jiang, Ruiyang Ren, Yifan Li, Xinyu Tang, Zikang Liu, Peiyu Liu, Jian-Yun Nie, Ji-Rong Wen, 2023 arXiv preprint arXiv:2303.18223 DOI: 10.48550/arXiv.2303.18223 - A comprehensive review of LLMs, including discussions on tokenization methods and the autoregressive generation process.

© 2026 ApX Machine Learning