← All posts
AI Security · 2 min

How large language models actually work

Pre-training, fine-tuning, transformers and self-attention. Understanding the mechanism is what lets you judge where a model breaks and where the risk sits.

Conceptual diagram of how a large language model works

Generative AI has become common knowledge, and large language models like ChatGPT are familiar to almost everyone. Far fewer people can explain what is actually happening inside one.

There is a practical reason to care. What a model is good at, where it fails, where bias enters, and how to size up the security risk — all of that depends on understanding the mechanism underneath.

The training cycle

The LLM training process

An LLM is built in three stages.

1. Pre-training

First, training on a very large body of text — books, articles, websites, a wide spread of sources. What the model acquires here is foundational: the patterns of language, grammar, vocabulary. It is not solving any particular task yet.

2. Fine-tuning

Next the model is adapted to specific tasks: translation, summarisation, question answering. This is the stage that turns a general language model into something that behaves the way you need it to.

3. Evaluation

Finally, performance is measured and tested against real tasks. The weaknesses found here drive the next round of improvement, and eventually produce the accuracy and reliability needed for complex language work.

The technology underneath

What makes this work is the transformer architecture published by Google, and the self-attention mechanism at its core.

Transformers process data in parallel, which is what made training at this scale efficient. Input text is first split into units called tokens, and each token is converted into a vector. Self-attention then computes the relationships between those vectors — capturing which words in a sentence relate to which others.

That is the technical reason a model can work with the meaning of a whole sentence rather than words in isolation.

What is still unsolved

Models are not magic, and the constraints matter in practice:

  • Compute and energy — training demands enormous resources, with an environmental cost that is not negligible
  • Bias — bias present in training data is reflected in the model. This is the most actively debated ethical problem in the field
  • Brittleness on novel input — behaviour outside the training distribution is not reliably sensible
  • Overfitting — fit the training data too closely and performance on new data degrades

The point

Generative AI is moving quickly and the possibilities keep widening. So do the obligations: bias, energy consumption, and security all need answers.

Understanding the mechanism and the training process is the most dependable footing you have for judging where this technology is actually going — rather than taking someone else’s word for it.

Originally published on Medium · Medium

Ishan Nim
Head of Penetration Testing & Cybersecurity, Cyber Crew

Let’s connect — especially if you’re into red teaming, payload engineering, or the fascinating depths of the dark web.

[email protected]linkedin.com/in/ishannim