liveBook · Manning

Transfer learning

As explained in Natural Language Processing in Action, Second Edition

Transfer learning is reusing knowledge learned from one task or dataset to improve learning on another task or dataset.

Transfer learning reuses knowledge learned from a broader task or dataset to give a new model a head start. In NLP, pretrained word embeddings provide useful word meanings before a CNN learns from a narrower corpus, while pretrained BERT supplies contextual representations for classification without requiring a huge dataset or supercomputer. section 7.4.3 section 9.3.4

A practical transfer-learning workflow includes:

  • Represent unavailable words with zero vectors so the model can learn those embeddings during task-specific training; initialize the layer with freeze=False when continued updating is desired. section 7.4.3

Classifying toxic social-media comments

Load 159,571 comments with six toxicity labels, split them into training and evaluation sets, and fine-tune bert-base-cased with MultiLabelClassificationModel. Evaluation reports LRAP, accuracy, and evaluation loss; the best saved model can then be evaluated separately.

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains initialization, vocabulary alignment, missing-token handling, fine-tuning, validation, and evaluation, but not pretrained-model training internals.
Examples
Uses a 4,000-token GloVe matrix and a toxic-comment BERT classifier evaluated with LRAP, accuracy, and evaluation loss.
What it assumes
Assumes tokenized vocabularies, labeled datasets, train-validation splits, and basic Python libraries while demonstrating model setup.
What you can do after
Builds transfer-learning pipelines with PyTorch embeddings or fine-tunes pretrained BERT models for labeled text classification.
How it connects
Connects pretrained embeddings, GloVe, CNNs, BERT, fine-tuning, multilabel classification, and out-of-vocabulary tokens.

Also explained in

Compare how 11 books explain transfer learning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.