liveBook · Manning

Epoch

As explained in Build AI Drug Discovery Pipelines

An epoch is one complete pass through all examples in a machine-learning training dataset.

An epoch is one complete pass through every example in a machine-learning training dataset. Training usually divides that pass into batches, computes predictions and loss, backpropagates gradients, and updates parameters batch by batch. section 8.2.3

Listing 8.7 Train the Model
def train_model(
    model, train_loader, val_loader, criterion, optimizer, 
    scheduler, device, num_epochs=10
):
    model.train()    #A
    train_losses = []    #B
    val_losses = []
    
    for epoch in range(num_epochs):    #C
        running_loss = 0.0    #D
        for inputs, targets in train_loader:
            inputs, targets = inputs.to(device), targets.to(device)
            
            optimizer.zero_grad()    #E
            outputs = model(inputs)    #F
            loss = criterion(outputs, targets)    #G
            loss.backward()    #H
            optimizer.step()    #I
            
            running_loss += loss.item()
        
        train_loss = running_loss / len(train_loader)
        train_losses.append(train_loss)
        
        model.eval()    #J
        val_loss = 0.0
        with torch.no_grad():    #K
            for inputs, targets in val_loader:
                inputs, targets = inputs.to(device), targets.to(device)
                outputs = model(inputs)
                loss = criterion(outputs, targets)
                val_loss += loss.item()
        
        val_loss /= len(val_loader)
        val_losses.append(val_loss)
        
        print(f'Epoch {epoch+1}/{num_epochs}', 
              f'Train Loss: {train_loss:.4f}',
              f'Val Loss: {val_loss:.4f}')    #L
        
        scheduler.step(val_loss)    #M
        model.train()    #N

A PyTorch training loop makes epochs explicit with range(num_epochs); each epoch accumulates batch losses, then evaluates validation loss. section 8.2.3

Reading epoch logs

A 50-epoch run can show training loss falling from 3.7013 to 0.2256 while validation loss improves early, then levels off near 0.66. This suggests reducing epochs or using early stopping, while also considering the learning-rate scheduler.

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains epoch-based loops, batch updates, loss tracking, and validation monitoring, but not optimization theory.
Examples
Uses a PyTorch training listing and 50-epoch train-versus-validation loss logs.
What you can do after
Operate/configure PyTorch training by selecting epoch counts and interpreting train-validation loss curves.
How it connects
Connects epochs with batches, backpropagation, validation loss, learning-rate schedulers, and early stopping.

Also explained in

Compare how 14 books explain epoch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.