liveBook · Manning

BERT

As explained in Domain-Specific Small Language Models

A transformer-based language model that uses the encoder stack for understanding tasks such as classification.

BERT (bidirectional encoder representation from transformers) uses only the Transformer encoder stack. It suits text classification and prediction, whereas decoder-only GPT models generally suit generation. section 1.2

A practical BERT classification workflow includes:

  • Collect labeled text, tokenize it, and represent tokens and labels as numerical IDs. section 2.1.1
  • Use [CLS] and [SEP] markers, then pad or truncate sequences to a consistent maximum length. section 2.1.1
  • Split data into training and validation sets, wrap it in data loaders, and load a pretrained classification model. section 2.1.1
  • Fine-tune pretrained BERT for a specific domain instead of training a model from scratch. section 1.7

Sentiment classification

A small dataset can label movie reviews as positive or negative. Tokenize the reviews with bert-base-uncased, encode the labels, and initialize BertForSequenceClassification with the number of labels. section 2.1.1

from transformers import BertTokenizer

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

Inspect the tokenizer setup used to convert raw text into BERT-compatible inputs. section 2.1.1

How Domain-Specific Small Language Models covers it

How deep it goes
Explains architecture choice and fine-tuning preparation through tokenization, data splitting, loaders, and model loading, without training internals.
Examples
Demonstrates sentiment labels, bert-base-uncased tokenization, padded sequences, validation splits, data loaders, and sequence classification.
What it assumes
Assumes basic machine-learning workflow knowledge while defining tokens, special markers, padding, truncation, and numerical IDs.
What you can do after
Builds a labeled-data pipeline and fine-tunes pretrained BERT for classification using tokenizers, PyTorch loaders, and Hugging Face models.
How it connects
Connects BERT with Transformers, self-attention, tokenization, GPT, transfer learning, and domain-specific models.

Also explained in

Compare how 9 books explain BERT →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.