[Learn](https://codetrain.ai/learn/) / [How LLMs Actually Work](https://codetrain.ai/learn/llm-foundations/)

# Training, generation & fine-tuning

Assemble a GPT, learn the loss, sample text, and see how assistants are aligned. A class in How LLMs Actually Work. Free to start, no card.

[Start free, no card](https://codetrain.ai/app/) 10 lessons a month on the free tier.

## Curated lessons in this class

### Stack blocks into a GPT (forward pass)

python · 3 steps · free

Assemble the full model and read out next-token scores.

1. Embed and add position
2. Run through the blocks
3. Final norm and unembed to logits

[Start this lesson](https://codetrain.ai/app/study/?lesson=llm-gpt-forward)

### The training objective

python · 4 steps · free

Cross-entropy, and watching a loss actually go down.

1. Logits to probabilities
2. Cross-entropy for one token
3. Average over a batch
4. Watch a loss go down

[Start this lesson](https://codetrain.ai/app/study/?lesson=llm-loss)

### Sampling: how text comes out

python · 4 steps · free

Greedy, temperature, top-k and top-p decoding.

1. Greedy: always the top token
2. Temperature
3. Top-k
4. Top-p (nucleus)

[Start this lesson](https://codetrain.ai/app/study/?lesson=llm-sampling)

### From base model to assistant

python · 1 steps · free

How next-token predictors become ChatGPT: SFT and RLHF.

1. The last mile: alignment

[Start this lesson](https://codetrain.ai/app/study/?lesson=llm-sft-rlhf)

## How CodeTrain teaches this

No videos and no multiple-choice quiz at the end. Each lesson is a handful of small steps in a real editor. You type the code yourself, it runs, and the tutor reviews what you actually wrote. It will not hand you the answer, and the step doesn't advance until your code passes. What you get at the end is a record of which steps you wrote unaided, not a completion percentage.

## These curated courses are the starting point, not the product

Everything in this catalog is a **curated** course we wrote by hand. They exist so there is something to start on. What CodeTrain actually does is build a lesson on demand: name **any topic** you want to understand and it writes one for you on the spot, or paste **any public repository** and it teaches you that codebase from the code that is really in it. You are not limited to the list below, and most people stop using it within a session or two.

## The rest of How LLMs Actually Work

[Neural-net foundations](https://codetrain.ai/learn/llm-foundations/llm-foundations-1/)[Tokens & embeddings](https://codetrain.ai/learn/llm-foundations/llm-foundations-2/)[The Transformer block](https://codetrain.ai/learn/llm-foundations/llm-foundations-3/)

[Start this class free](https://codetrain.ai/app/) [Browse every curated course](https://codetrain.ai/learn/)

---

Source: https://codetrain.ai/learn/llm-foundations/llm-foundations-4/

This is the markdown twin of the page above. Every public CodeTrain page serves one on `Accept: text/markdown`. Start at https://codetrain.ai/llms.txt for the full map, or https://codetrain.ai/developers/ for the API.
