From Bag of Words to Transformers: A Decade of NLP Architecture Evolution
From Bag of Words to Transformers: A Decade of NLP Architecture Evolution
The history of NLP architecture is a history of increasingly sophisticated ways to represent context. Each generation of models solved the shortcomings of its predecessor — and introduced new ones. Understanding this evolution is not merely historical: it explains why transformers dominate, where they still fall short, and what architectural innovations are coming next.
Era 1: Bag of Words and TF-IDF (pre-2013)
The bag-of-words (BoW) model represents text as a vector of word counts, discarding all order information. "The dog bit the man" and "The man bit the dog" produce identical BoW representations. Despite this obvious limitation, BoW-based classifiers worked surprisingly well for tasks like spam detection and topic classification because the distribution of words carries strong signal even without order.
TF-IDF (Term Frequency-Inverse Document Frequency) improved on raw counts by downweighting words that appear across all documents (common words like "the") and upweighting rare, informative terms. It remains useful for information retrieval today.
The fundamental limitation: no notion of word meaning, no way to know that "car" and "automobile" are related.
Era 2: Word Embeddings (2013–2016)
Word2Vec (Mikolov et al., 2013) introduced the idea of training dense vector representations by predicting surrounding words. The result: semantically similar words ended up near each other in vector space. "King − Man + Woman ≈ Queen" became the canonical demonstration of learned semantic structure.
GloVe offered an alternative based on global co-occurrence statistics rather than local context windows. Both approaches produced static embeddings — a single vector per word regardless of context.
This was a massive leap, enabling transfer learning in NLP for the first time. Pretrained embeddings could be downloaded and used as features in any downstream model. But the static nature remained a problem: the word "apple" had one embedding, regardless of whether you meant the fruit or the company.
Era 3: Sequence Models — RNNs and LSTMs (2014–2018)
Recurrent Neural Networks (RNNs) process text as a sequence, maintaining a hidden state that updates at each timestep. In principle, an RNN can "remember" information from the beginning of a sentence when processing the end. In practice, vanishing gradients meant that information from more than ~10-15 tokens ago was effectively lost.
LSTMs (Long Short-Term Memory) and GRUs (Gated Recurrent Units) addressed this with gating mechanisms that selectively retain or forget information. LSTMs powered the first commercially successful neural machine translation systems and achieved state of the art on many benchmarks from 2015 to 2017.
But LSTMs still processed text sequentially — each token depended on the previous step, making parallelization impossible and training slow. And even LSTMs struggled to maintain coherent context across hundreds of tokens.
Era 4: Attention Mechanisms (2015–2017)
The key insight of attention: instead of relying on a fixed hidden state to encode the entire source sentence, the model should be able to directly look at any part of the source when generating each target word.
Bahdanau et al. introduced additive attention for neural machine translation in 2015. It dramatically improved translation of long sentences by allowing the decoder to focus on relevant source tokens at each generation step.
This attention mechanism was later generalized into multi-head self-attention in the transformer architecture.
Era 5: Transformers and Pretraining (2017–present)
The 2017 Attention Is All You Need paper replaced recurrent processing entirely with self-attention. Every token attends to every other token in parallel. This unlocked:
- GPT (2018): autoregressive pretraining on a large text corpus, fine-tuned on downstream tasks
- BERT (2018): bidirectional masked language modeling, achieving state-of-the-art on 11 NLP tasks simultaneously
- T5, XLNet, RoBERTa (2019): refinements to pretraining objectives and data quality
- GPT-3, GPT-4, PaLM, LLaMA (2020–2024): scaling to billions and hundreds of billions of parameters, with emergent few-shot and reasoning capabilities
What Comes Next
Transformer architecture continues to evolve: sparse attention (Longformer, BigBird) extends context windows efficiently; mixture-of-experts (MoE) models activate only a subset of parameters per token, improving efficiency at scale; state-space models (Mamba) offer an alternative to attention for very long sequences.
Conclusion
Each architectural era was not a replacement but an addition to the toolkit. BoW still powers many search systems. LSTMs appear in embedded NLP applications where transformer compute is prohibitive. The practitioner who understands why each architecture exists — and what problem it solved — makes better decisions about which tool fits which problem.
Keywords: NLP architecture evolution, bag of words, word2vec, LSTM, transformer, BERT, GPT, attention mechanism, natural language processing history