liveBook · Manning

Hyperparameter

As explained in AI-Powered Search

A hyperparameter is a configuration value that controls a model or learning procedure and is set rather than learned from individual examples.

A hyperparameter is a configuration value set before training that changes how a learning process behaves and affects the resulting model. Unlike learned parameters, it is chosen by the practitioner and may require iteration and measurement to optimize. section 13.4.3

Common training hyperparameters control the following parts of a model-training run:

  • Epochs specify how many times training iterates over the dataset; too many can cause overfitting. section 14.3.2
  • Batch sizes specify how many examples are processed together and are constrained by available GPU memory. section 14.3.2
  • Warmup steps gradually adjust the learning rate at the start of training, while weight decay reduces overfitting by shrinking weights at each step. section 14.3.2
  • The number of latent features in matrix factorization determines the dimensions used to represent users and items. section 9.3.1

Configuring a question-answering trainer

A Transformer training run can use three epochs, training and evaluation batch sizes of 16 and 64, 500 warmup steps, and 0.01 weight decay. Grid search evaluates combinations of such values to identify settings that improve model quality. section 14.3.2

Listing 14.10 Initializing the trainer and its hyperparameters
from transformers import RobertaForQuestionAnswering, TrainingArguments,
                         Trainer, default_data_collator

model = RobertaForQuestionAnswering.from_pretrained(
  "deepset/roberta-base-squad2")

training_args = TrainingArguments(
  evaluation_strategy="epoch",  #1
  num_train_epochs=3,  #2
  per_device_train_batch_size=16,  #3
  per_device_eval_batch_size=64,  #4
  warmup_steps=500,  #5
  weight_decay=0.01, #6
  logging_dir="data/question-answering/logs",
  output_dir="data/question-answering/results")

trainer = Trainer(
  model=model,  #7
  args=training_args,  #8
  data_collator=default_data_collator,
  tokenizer=tokenizer,
  train_dataset=tokenized_datasets["train"], #9
  eval_dataset=tokenized_datasets["test"])  #10

Inspect the executable TrainingArguments configuration and see how hyperparameters connect the pretrained model, datasets, evaluation schedule, logging, and output directories. section 14.3.2

How AI-Powered Search covers it

How deep it goes
Explains definitions, effects, example values, and grid search, but stops short of detailing search algorithms or optimization theory.
Examples
Uses Transformer trainer settings, latent-feature dimensions, and RoBERTa sentence-embedding configuration as concrete examples.
What it assumes
Assumes familiarity with model training and datasets while defining hyperparameters and their main effects explicitly.
What you can do after
Apply hyperparameters through Hugging Face TrainingArguments and compare settings with grid search.
How it connects
Connects epochs, batch size, learning rate, weight decay, grid search, matrix factorization, and embeddings.

Also explained in

Compare how 19 books explain hyperparameter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.