A Large Language Model (LLM) is a neural network trained on enormous amounts of text to do one thing extremely well: predict the next token in a sequence[reference:0]. Tokens are pieces of words β for example, "unbelievable" might become ["un", "believ", "able"].
That single objective β next-token prediction β is powerful enough to produce coherent essays, working code, translations, and conversations. The model learns the statistical patterns of language so thoroughly that it can generate text that feels intelligent, even though it has no conscious understanding[reference:1].
Before anything else, text is split into tokens. A token can be a whole word, a subword, or even a single character. On average, 100 tokens β 75 English words[reference:3]. Every token is mapped to an integer ID, then to a vector (a list of numbers) called an embedding.
The breakthrough architecture behind modern LLMs is the Transformer (introduced in the 2017 paper "Attention Is All You Need")[reference:4]. Its key innovation is self-attention: when processing each token, the model looks at every other token in the sequence and learns which ones matter most for predicting what comes next[reference:5].
Think of it this way: in the sentence "The bank wouldn't approve the loan because it was too risky," attention lets the model connect "it" to "loan" rather than "bank." Early RNNs processed text word-by-word and forgot earlier context; Transformers process the whole sequence in parallel and keep everything relevant in view.
| Stage | What happens | Analogy |
|---|---|---|
| Pre-training | Model reads trillions of tokens (web pages, books, code) and learns to predict the next token. This is the most compute-intensive phase. | Reading every book in a library |
| Supervised Fine-tuning (SFT) | Model is trained on questionβanswer pairs to learn the format of helpful dialogue. | Learning to answer exam questions |
| RLHF | Humans rank model outputs; the model learns to produce answers that people prefer β safer, more helpful, more natural. | Getting feedback from a writing tutor |
These stages are described in detail in beginner-oriented LLM literature[reference:6].
When you send a prompt, the model runs inference β it generates one token at a time, feeding each new token back into the context to produce the next one. This loop repeats until a stop condition is met[reference:7].
Your prompt β tokenize β Transformer β pick next token β append β repeat β detokenize β your answer
| Parameter | What it does | Typical values |
|---|---|---|
| Temperature | Controls randomness. Low (0.0β0.3) = focused, deterministic. High (0.7β1.0+) = creative, varied. | 0.2 for factual Q&A, 0.9 for brainstorming |
| Max tokens | Limits how long the response can be. | 500β4000 depending on task |
| Top-p | Alternative to temperature; restricts sampling to the most probable tokens whose cumulative probability reaches p. | 0.9 |
Temperature is the most widely used generation setting, and understanding it is essential for getting useful outputs[reference:8].
Prompt engineering is the practice of designing your input to get better outputs. It requires no extra training data or infrastructure β just clearer thinking[reference:9].
Don't assume the model will infer what you want. State it directly, with action verbs and concrete requirements[reference:10].
Vague: Make a dashboard.
Explicit: Create an analytics dashboard. Include at least five metrics, a date-range filter, and a bar chart showing weekly trends.
A system message sets the model's role, tone, boundaries, and output format. It's the highest-level instruction and should come first[reference:11].
You are a friendly travel advisor for Margie's Travel.
Answer only travel-related questions.
Use a warm, conversational tone.
If you lack information, ask a clarifying question.
Format hotel recommendations as a bulleted list.
Source: Microsoft Learn prompt engineering guide[reference:12].
Explain why you want something β not just what. This helps modern models reason about your underlying goal[reference:13].
Without: NEVER use bullet points.
With: I prefer natural paragraph form rather than bullet points because flowing prose is easier for me to read when learning.
| Pattern | How to use it | When to use it |
|---|---|---|
| Persona | "You are a senior software engineer reviewing this codeβ¦" | When you want expert-level tone or domain-specific reasoning. |
| Few-shot | Provide 2β3 input/output examples before your actual request. | When the desired format is hard to describe but easy to show. |
| Chain-of-thought | "Think step by step before giving the final answer." | Reasoning, math, logic problems. |
| Format template | Specify exact output structure (JSON, markdown table, etc.). | When downstream code needs to parse the response. |
These patterns are documented in Microsoft's prompt engineering training module[reference:14].
| Limitation | What it means | Mitigation |
|---|---|---|
| Knowledge cutoff | The model only knows what it was trained on up to a certain date. | Use RAG (retrieval-augmented generation) to inject current data. |
| Hallucination | The model confidently generates false information. | Ask for sources; verify critical facts; use groundedness detection. |
| Context window limit | The model can only "see" a fixed number of tokens at once. | Summarise long conversations; use larger-context models for big documents. |
| No learning from interaction | The model doesn't remember previous chats unless you send history each time. | Include relevant prior context in your prompt. |
These limitations are discussed in Microsoft's generative AI concepts guide[reference:15].
tiktoken help estimate token counts[reference:18].You can interact with LLMs through several different channels. Each has different trade-offs in cost, privacy, latency, and capability.
| Environment | How it works | Best for |
|---|---|---|
| Chat UI (ChatGPT, Claude, Gemini) | Web interface; you type messages and read responses. | Exploration, brainstorming, learning. |
| Cloud API (OpenAI, Anthropic, Google) | You send HTTP requests from your code; the provider runs the model. | Apps, automation, production systems. |
| Local runtime (Ollama, llama.cpp, LM Studio) | Model runs on your own machine. No data leaves your device. | Privacy, offline use, experimentation. |
| Hybrid / SDK (xlocllm, Foundry Local) | Local inference behind an OpenAI-compatible API, so existing code works unchanged. | Development with privacy and cost control. |
The most common approach for applications. You call a REST endpoint, pay per token, and the provider handles scaling. Example using the OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(api_key="sk-...")
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain attention in simple terms."}
],
temperature=0.3
)
print(response.choices[0].message.content)
Tools like Ollama let you run open-weight models (e.g. Llama, Mistral, Qwen) on your own hardware. This avoids per-token costs and keeps data private, but you need sufficient RAM/VRAM and accept lower speed.
# Example with Ollama
ollama run llama3.2
# Then chat with the model in your terminal
Some SDKs bridge local and remote inference. For instance, xlocllm exposes an OpenAI-compatible endpoint on localhost while running model weights in a browser via WebGPU. Your existing OpenAI client code works without changes[reference:19].
API β Application Programming Interfaceopenai.chat.completions.create(), you're using an API[reference:20].AttentionBase ModelChain-of-Thought (CoT)Context WindowEmbeddingFine-tuningHallucinationInferenceLLM β Large Language ModelLLMOps β LLM OperationsLoRA β Low-Rank AdaptationMoE β Mixture of ExpertsMultimodalParametersPrompt EngineeringRAG β Retrieval-Augmented GenerationRLHF β Reinforcement Learning from Human FeedbackSystem MessageTemperatureTokenTransformer