Back to Articles

Natural Language Processing Explained: From Raw Text to Transformers and LLM Systems

Shaswat Raj
September 21, 202618 min read
Natural Language Processing architecture from text to Transformers
Sketch

Sketch the mental model

Rebuild the system from memory. The canvas is editable and opens fullscreen when you need more room.

Natural Language Processing looks intimidating because it contains several disciplines at once: linguistics, probability, machine learning, deep learning, information retrieval and systems engineering. The cleanest way to learn it is to follow one invariant question: how does human language become a representation a machine can compute over?

This article follows the same learning path used in the StackShade NLP course: foundations first, representations second, neural sequence models third, Transformers fourth, and modern LLM systems only after the underlying mechanics are visible.

The NLP stack in five moves
Current focus: Raw text — Messy language.
Self-attention as selective context
Query
What does this token need?
Keys
Which positions look relevant?
Values
What information gets mixed in?
RAG: retrieve before you generate
Documents Search index LLM

The complete NLP architecture

01

Text

Documents, messages, speech transcripts and other language-bearing input.

02

Tokenization

Convert text into model units such as words, subwords or characters.

03

Representation

Sparse features, embeddings or contextual representations encode information.

04

Model

Statistical models, sequence models or Transformers transform the representation.

05

Task

Classify, extract, rank, retrieve, translate, summarize or generate.

06

System

Add retrieval, tools, evaluation, safety, monitoring and product constraints.

1. Text is not yet a model input

Computers receive bytes. NLP systems need discrete or continuous representations. Before a model can predict anything, the text must pass through choices about Unicode normalization, sentence boundaries, tokenization and special symbols.

This is why preprocessing is not merely janitorial work. Removing punctuation may help one task and hurt another. Lowercasing can reduce vocabulary size while discarding a capitalization signal. Aggressive stemming can improve recall while damaging precise terminology.

raw text → normalized text → tokens → token IDs → model inputs

2. Linguistic structure still matters

Part-of-speech tags, named entities, dependency relations and semantic roles remain useful mental models even when a modern neural model learns their signals implicitly. They give engineers a vocabulary for explaining ambiguity and debugging data.

Syntax
How words relate structurally.
Semantics
What the utterance means.
Pragmatics
How context changes meaning.

3. Classical NLP: probability before deep learning

N-gram language models, Naive Bayes, logistic regression and hidden Markov models are worth learning because they make the core ideas explicit: probability distributions, conditional dependence, feature representations, sequence state and decoding.

The historical progression is not “old methods were wrong.” It is that later models learned richer representations and dependencies with less hand-crafted feature engineering.

4. Representation became geometry

Bag-of-words and TF-IDF represent text with sparse counts. Word embeddings turned words into dense vectors. Contextual representations later made the vector depend on surrounding text.

Sparse
TF-IDF
Useful, interpretable baseline.
Static dense
Word2Vec
Compact distributional geometry.
Contextual
Transformer
Representation changes with context.

5. RNNs, then the problem that attention solved

RNNs process sequences recurrently. Their hidden state is a compressed summary of what has already been read. That sequential dependency is conceptually elegant but creates optimization and long-range dependency problems. Attention changed the architecture by allowing a representation to access a weighted set of context positions directly.

6. Self-attention and the Transformer block

The key computation is a query–key compatibility score followed by a weighted combination of values:softmax(QKᵀ / √dk)V. Multi-head attention repeats this idea in parallel learned subspaces. Residual paths, normalization and position information turn the attention operation into a trainable stack rather than an isolated trick.

Embeddings
Position
Attention
Residual + Norm
Feed Forward
Residual + Norm

7. Language-model pretraining

Modern language models learn from large corpora using self-supervised objectives. Autoregressive language models predict the next token; masked-language models reconstruct hidden tokens. The data mixture, tokenizer, objective and optimization setup are part of the model's effective learning environment.

8. RAG changes the application architecture

A production LLM system often needs information outside the model's parameters. Retrieval-Augmented Generation adds an external retrieval stage so responses can be grounded in selected documents. That creates two separate quality questions: did we retrieve the right evidence? and did the model use it correctly?

9. Evaluation is part of the architecture

Accuracy, precision, recall and F1 are useful for many classification tasks. BLEU and ROUGE can provide signals for some generation settings, but modern NLP evaluation often needs task-specific test sets, human judgment, robustness tests, grounding checks and production telemetry.

10. Reliability and safety

Fluent language is not evidence of correctness. Production systems need controls for hallucination, data leakage, prompt injection, harmful content, bias, provenance and model drift. The right control depends on where the risk enters the system.

The learning loop we use in the course

01
Predict
02
Visualize
03
Explain
04
Retrieve
05
Apply
06
Revisit

The course uses retrieval practice, spaced review, chunking, elaboration, generation, self-explanation, interleaving and dual coding. The aim is to make you reconstruct the mechanism, not recognize it from familiar wording.

Where to go next

The dedicated StackShade NLP course turns this architecture into a structured 10-week path with 60 lessons. Every lesson has a screen-recordable presentation deck with a shared design system, keyboard navigation, fullscreen mode, presenter notes, animation, active recall and a closing teach-back challenge.

FoundationsClassical NLPEmbeddingsRNNsAttentionTransformersLLMsRAGEvaluationProduction