AI & LLMs

Transformers vs Traditional NLP: What Changed?

Natural language processing used to be a pipeline of hand-built steps and task-specific models. In three years, pre-trained transformers such as BERT have replaced much of that pipeline. We compare the old and new approaches, explain what actually changed, and when the traditional methods are still the right choice.

By EthicalHat Research · · 3 min read
Infographic: Traditional NLP vs pre-trained transformers

If you built an NLP system five years ago, you probably assembled a pipeline: tokenise the text, tag parts of speech, extract named entities, compute features such as TF-IDF or n-grams, and train a classifier. Each step was a separate component, often with its own model and hand-tuned rules.

Today, the default approach for most NLP tasks is to take a pre-trained transformer such as BERT or RoBERTa and fine-tune it for the task. On many benchmarks, this approach has left the old pipeline far behind.

What exactly changed?

The traditional pipeline

A classic text classification system looked like this:

flowchart LR
  T[Raw text] --> Tok[Tokenise & normalise]
  Tok --> F[Feature extraction<br/>bag of words, TF-IDF, n-grams]
  F --> C[Classifier<br/>logistic regression, SVM]
  C --> L[Label]

It works well, and it is still useful. Its limitations:

  • Features are designed by hand. Performance depends on the engineer's choices of n-grams, stop words and so on.
  • Word order and context are mostly lost. "Not good" and "good" share a feature unless you add bigrams.
  • No transfer. Every new task starts from scratch with its own labelled data.

Step one: word embeddings

word2vec (2013) and GloVe (2014) introduced dense vector representations learned from large amounts of text. Words used in similar contexts ended up close together. They were a major improvement over sparse bag-of-words features, and they could be pre-trained once and reused.

But each word got one vector, regardless of context. "Bank" had the same representation in "river bank" and "bank account".

Step two: contextual representations

In 2018, ELMo produced word representations that depend on the surrounding sentence, using bidirectional LSTMs. Later that year, Google's BERT did the same with a transformer encoder, pre-trained on masked word prediction over large amounts of text. BERT set new records on a wide range of benchmarks at once.

Three ideas made the difference:

  1. Contextual embeddings. Every token's representation depends on the whole sentence.
  2. Transfer learning. Pre-train once on unlabelled text, then fine-tune on a small labelled dataset for each task.
  3. The transformer architecture, which trains efficiently on large datasets and captures long-range relationships through self-attention.

The same task, two ways

A classic baseline with scikit-learn:

python
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline

baseline = make_pipeline(
    TfidfVectorizer(ngram_range=(1, 2), min_df=2),
    LogisticRegression(max_iter=1000),
)
baseline.fit(train_texts, train_labels)
print(baseline.score(test_texts, test_labels))

A fine-tuned transformer with the Hugging Face transformers library:

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments

name = "distilbert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForSequenceClassification.from_pretrained(name, num_labels=2)

def encode(batch):
    return tokenizer(batch["text"], truncation=True, padding="max_length", max_length=256)

train_ds = train_ds.map(encode, batched=True)
test_ds = test_ds.map(encode, batched=True)

trainer = Trainer(
    model=model,
    args=TrainingArguments("out", num_train_epochs=3, per_device_train_batch_size=16),
    train_dataset=train_ds,
    eval_dataset=test_ds,
)
trainer.train()

On many real-world datasets, the transformer wins, often by a wide margin when context matters (sarcasm, negation, long-range references) or when labelled data is limited.

What changed in practice

  • Less feature engineering, more data curation. Effort moves from designing features to collecting good labels and evaluating carefully.
  • One backbone, many tasks. The same pre-trained model can be fine-tuned for classification, named entity recognition, question answering and more.
  • Multilingual models such as mBERT and XLM-R work across dozens of languages.
  • Tooling matured quickly. Libraries like Hugging Face Transformers make pre-trained models available with a few lines of code.

When traditional NLP is still the right answer

Transformers are not always the best choice:

  • Cost and latency. TF-IDF with logistic regression runs in microseconds on a CPU. A transformer needs far more compute, often a GPU.
  • Simple tasks. For keyword-driven classification or spam filtering with lots of data, classic models can be nearly as accurate.
  • Interpretability. Linear models over n-grams are easy to explain; transformers are not.
  • Small, stable problems where a rules-based approach is transparent and sufficient.

A good practice is to always build a classic baseline first. If a transformer does not beat it clearly on your data, the added complexity may not be worth it.

What comes next

Larger models such as GPT-3 show another shift: from fine-tuning to prompting, where tasks are specified in natural language with a few examples. Smaller, distilled transformers (DistilBERT, TinyBERT) are making contextual models cheaper to run. The direction is clear. Pre-trained, general models are becoming the foundation of NLP, with task-specific work moving to adaptation and evaluation.

Our agentic AI security and DevSecOps teams build NLP solutions using the right mix of classic and transformer-based methods for each problem.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.