### Install Losscape Library Source: https://github.com/alxndrtl/losscape/blob/main/README.md Install the losscape library using pip. This command downloads and installs the package and its dependencies from the Python Package Index. ```bash pip install losscape ``` -------------------------------- ### Complete Example with Spiral Dataset Source: https://context7.com/alxndrtl/losscape/llms.txt Demonstrates a full workflow including defining a custom SpiralDataset, an MLP model, training the model, and generating 2D and 3D loss landscapes. It utilizes various components from the losscape library and PyTorch. ```python import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import Dataset, DataLoader import numpy as np from losscape.train import train from losscape.create_landscape import create_2D_losscape, create_3D_losscape # Custom dataset class SpiralDataset(Dataset): def __init__(self, N=100, K=3): X = np.zeros((N*K, 2)) y = np.zeros(N*K, dtype='uint8') for j in range(K): ix = range(N*j, N*(j+1)) r = np.linspace(0.0, 1, N) t = np.linspace(j*4, (j+1)*4, N) + np.random.randn(N)*0.2 X[ix] = np.c_[r*np.sin(t), r*np.cos(t)] y[ix] = j self.X = torch.from_numpy(X).float() self.y = torch.from_numpy(y).long() def __len__(self): return len(self.y) def __getitem__(self, idx): return self.X[idx], self.y[idx] # Multi-layer perceptron class MLP(nn.Module): def __init__(self): super(MLP, self).__init__() self.fc1 = nn.Linear(2, 100) self.fc2 = nn.Linear(100, 30) self.fc3 = nn.Linear(30, 3) def forward(self, x): x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(x) return x # Create dataset and loaders dataset = SpiralDataset(N=100, K=3) train_loader = DataLoader(dataset, batch_size=300, shuffle=True) train_loader_fixed = DataLoader(dataset, batch_size=300, shuffle=False) # Train model model = MLP() optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9, weight_decay=5e-4) train(model, train_loader, epochs=1000, optimizer=optimizer, verbose=1) # Generate visualizations create_2D_losscape(model, train_loader_fixed) create_3D_losscape(model, train_loader_fixed, output_vtp=True, num_points=50) # Result: 2d_losscape.png, 3d_losscape.png, losscape.vtp, losscape_log.vtp ``` -------------------------------- ### Basic Usage of Losscape in PyTorch Source: https://github.com/alxndrtl/losscape/blob/main/README.md Demonstrates the basic usage of the losscape library by importing necessary functions, defining a PyTorch model and data loader, and then calling functions to train the model and create a 2D loss landscape visualization. The `train` function handles model training, and `create_2D_losscape` generates the visualization, with `output_vtp=True` indicating the creation of a VTK PolyData file for 3D visualization. ```python from losscape.train import train from losscape.create_landscape import create_2D_losscape model = ... # create your torch model (subclass of torch.nn.Module) train_loader = ... # the DataLoader containing your favorite dataset train(model, train_loader) # losscape can perform the training for you create_2D_losscape(model, train_loader, output_vtp=True) ``` -------------------------------- ### Initialize MLP Model and Optimizer in Python Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Initializes an instance of the MLP model and sets up the Stochastic Gradient Descent (SGD) optimizer. The optimizer is configured with a learning rate, momentum, and weight decay. ```python model = MLP() optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9, weight_decay=5e-4) ``` -------------------------------- ### Advanced Configuration for 3D Landscape Source: https://context7.com/alxndrtl/losscape/llms.txt This snippet is a placeholder for advanced configuration options when creating a 3D loss landscape. It suggests that further customization is possible beyond the standard parameters. ```python from losscape.create_landscape import create_3D_losscape # Advanced configuration options would go here. ``` -------------------------------- ### Import Libraries for Losscape Project Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Imports necessary libraries for the Losscape project, including PyTorch for deep learning, Matplotlib for plotting, and NumPy for numerical operations. It also imports custom modules for training and landscape creation. ```python import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import Dataset, DataLoader import matplotlib.pyplot as plt import numpy as np from losscape.train import train from losscape.create_landscape import create_1D_losscape, create_2D_losscape ``` -------------------------------- ### Create High-Resolution 3D Loss Landscape (Python) Source: https://context7.com/alxndrtl/losscape/llms.txt Generates a high-resolution 3D visualization of the neural network's loss landscape. It explores a custom range of parameters, estimates loss using a specified number of batches, and saves the output in VTP and H5 formats. Requires a PyTorch model, an unshuffled data loader, and a loss criterion. ```python X, Y, losses = create_3D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, criterion=F.cross_entropy, num_batches=16, # More batches for stable loss estimation x_min=-2.0, # Wider exploration range x_max=2.0, y_min=-2.0, y_max=2.0, num_points=100, # High resolution: 10,000 evaluations save_only=True, output_path='./results/', output_vtp=True, output_h5=True ) ``` -------------------------------- ### Train Neural Network Source: https://context7.com/alxndrtl/losscape/llms.txt Trains a PyTorch model using the provided data loader, optimizer, and loss function. It supports basic training loops with optional learning rate decay and verbose output. ```APIDOC ## Train Neural Network ### Description Trains a PyTorch model using the provided data loader, optimizer, and loss function. Supports learning rate decay and verbose progress output. ### Method `train` function from `losscape.train` ### Parameters #### Function Parameters - **model** (torch.nn.Module) - The neural network model to train. - **train_loader** (DataLoader) - DataLoader for the training dataset. - **optimizer** (torch.optim.Optimizer) - Optimizer for the model parameters. - **criterion** (callable) - The loss function. - **epochs** (int) - The total number of training epochs. - **decay_lr_epochs** (int) - Number of epochs after which to decay the learning rate (optional). - **verbose** (int) - Controls the frequency of printing training progress (0: no output, 1: at intervals). ### Request Example ```python from losscape.train import train import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader, TensorDataset class SimpleNet(nn.Module): def __init__(self): super(SimpleNet, self).__init__() self.fc1 = nn.Linear(10, 50) self.fc2 = nn.Linear(50, 20) self.fc3 = nn.Linear(20, 2) def forward(self, x): x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(x) return x X = torch.randn(1000, 10) y = torch.randint(0, 2, (1000,)) dataset = TensorDataset(X, y) train_loader = DataLoader(dataset, batch_size=32, shuffle=True) model = SimpleNet() optimizer = torch.optim.Adam(model.parameters(), lr=0.001) train( model=model, train_loader=train_loader, optimizer=optimizer, criterion=F.cross_entropy, epochs=100, decay_lr_epochs=30, verbose=1 ) ``` ### Response No direct return value, but the model is trained in-place. Progress is printed to the console if `verbose` is set to 1. ``` -------------------------------- ### Create 3D Loss Landscape with VTP Export using losscape Source: https://context7.com/alxndrtl/losscape/llms.txt Generates a 3D contour plot and VTP (VTK PolyData) files for visualization of the loss landscape using `create_3D_losscape` from `losscape.create_landscape`. It takes the model, unshuffled DataLoader, and loss criterion as input. The function creates a grid of points within specified ranges, computes losses, and saves the output as PNG, VTP, and optionally HDF5. ```python from losscape.create_landscape import create_3D_losscape # Create 3D contour plot and exportable VTP files X, Y, losses = create_3D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, criterion=F.cross_entropy, num_batches=8, x_min=-1.0, x_max=1.0, y_min=-1.0, y_max=1.0, num_points=50, # Creates 50x50 grid = 2500 evaluations save_only=True, # Only save, don't display output_path='./', output_vtp=True, # Generate VTP files for 3D viewing output_h5=True # Save raw data in HDF5 format ) # Output during execution: # LOSS FOR x=-1.0 AND y=-1.0 IS : 2.34. Done : 1/2500 (0.04%) # LOSS FOR x=-0.96 AND y=-1.0 IS : 2.29. Done : 2/2500 (0.08%) # ... # Here's your output file:./losscape_log.vtp # Here's your output file:./losscape.vtp # X, Y: (50, 50) meshgrid arrays # losses: (50, 50) array of loss values # Files created: 3d_losscape.png, losscape.vtp, losscape_log.vtp, data.h5 ``` -------------------------------- ### Train MLP Model in Python Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Trains the initialized MLP model using the `train` function. The training process is set to run for 1000 epochs, utilizing the provided DataLoader and optimizer. ```python train(model, train_loader, epochs=1000, optimizer=optimizer) ``` -------------------------------- ### Create 2D Loss Landscape Visualization Source: https://context7.com/alxndrtl/losscape/llms.txt Generates a 2D line plot visualizing the loss landscape. It samples points along random directions from the trained model's weights and computes the loss. ```APIDOC ## Create 2D Loss Landscape Visualization ### Description Generates a 2D line plot visualizing the loss landscape. It samples points along random directions from the trained model's weights and computes the loss. The plot can be displayed and saved. ### Method `create_2D_losscape` function from `losscape.create_landscape` ### Parameters #### Function Parameters - **model** (torch.nn.Module) - The trained neural network model. - **train_loader_unshuffled** (DataLoader) - DataLoader for the training dataset (should be unshuffled for consistent evaluation). - **criterion** (callable) - The loss function. - **num_batches** (int) - The number of batches to use for loss computation. - **x_min** (float) - The minimum exploration range along the x-axis (random direction). - **x_max** (float) - The maximum exploration range along the x-axis (random direction). - **num_points** (int) - The number of points to sample along the direction. - **save_only** (bool) - If True, only saves the plot; if False, displays and saves. - **output_path** (str) - The directory to save the plot. The filename will be '2d_losscape.png'. ### Request Example ```python from losscape.create_landscape import create_2D_losscape from torch.utils.data import DataLoader import torch.nn.functional as F # Assuming 'model', 'dataset' are already defined from the training example train_loader_fixed = DataLoader(dataset, batch_size=32, shuffle=False) coords, losses = create_2D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, criterion=F.cross_entropy, num_batches=8, x_min=-1.0, x_max=1.0, num_points=50, save_only=False, output_path='./' ) ``` ### Response #### Success Response (200) - **coords** (numpy.ndarray) - Array of x-coordinates (50 points). - **losses** (list) - List of corresponding loss values for each coordinate. #### Response Example ```json { "coords": ["... numpy array of 50 values ..."], "losses": ["... list of 50 loss values ..."] } ``` ### Output Files - `./2d_losscape.png` (300 DPI line plot) ``` -------------------------------- ### Create 2D Loss Landscape Visualization with losscape Source: https://context7.com/alxndrtl/losscape/llms.txt Generates a 2D line plot visualizing the loss landscape of a trained PyTorch model using `create_2D_losscape` from `losscape.create_landscape`. It requires the model, an unshuffled DataLoader, and a loss criterion. The function samples points along random directions within specified ranges and outputs coordinates and corresponding loss values. ```python from losscape.create_landscape import create_2D_losscape from torch.utils.data import DataLoader import torch.nn.functional as F # Use a fixed (unshuffled) dataloader for consistent evaluation train_loader_fixed = DataLoader(dataset, batch_size=32, shuffle=False) # Create 2D line plot of loss landscape coords, losses = create_2D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, criterion=F.cross_entropy, num_batches=8, # Use 8 batches for loss computation x_min=-1.0, # Explore from -1 to +1 along random direction x_max=1.0, num_points=50, # Sample 50 points save_only=False, # Display plot and save to file output_path='./' # Save as './2d_losscape.png' ) # coords: numpy array of 50 x-coordinates # losses: list of 50 loss values # Output file: 2d_losscape.png (300 DPI line plot) ``` -------------------------------- ### Access and Analyze Loss Landscape Data from HDF5 (Python) Source: https://context7.com/alxndrtl/losscape/llms.txt Reads raw loss landscape data (parameters X, Y, and corresponding losses) from an HDF5 file generated by `losscape`. It prints the range and shape of the loss data, enabling further programmatic analysis or visualization. Requires the `h5py` library. ```python import h5py with h5py.File('./results/data.h5', 'r') as f: X_data = f['X'][:] Y_data = f['Y'][:] loss_data = f['losses'][:] print(f"Loss range: {loss_data.min():.3f} to {loss_data.max():.3f}") print(f"Grid shape: {loss_data.shape}") ``` -------------------------------- ### Create 3D Loss Landscape with VTP Export Source: https://context7.com/alxndrtl/losscape/llms.txt Generates a 3D contour plot of the loss landscape and optionally exports data in VTP and HDF5 formats for advanced visualization and analysis. ```APIDOC ## Create 3D Loss Landscape with VTP Export ### Description Generates a 3D contour plot of the loss landscape by sampling points in a 2D plane defined by two random directions. Optionally exports data in VTP (for 3D viewers) and HDF5 formats. ### Method `create_3D_losscape` function from `losscape.create_landscape` ### Parameters #### Function Parameters - **model** (torch.nn.Module) - The trained neural network model. - **train_loader_unshuffled** (DataLoader) - DataLoader for the training dataset (should be unshuffled). - **criterion** (callable) - The loss function. - **num_batches** (int) - The number of batches to use for loss computation. - **x_min** (float) - The minimum exploration range along the first random direction. - **x_max** (float) - The maximum exploration range along the first random direction. - **y_min** (float) - The minimum exploration range along the second random direction. - **y_max** (float) - The maximum exploration range along the second random direction. - **num_points** (int) - The number of points to sample along each direction, creating a `num_points` x `num_points` grid. - **save_only** (bool) - If True, only saves the plot and data; if False, displays and saves. - **output_path** (str) - The directory to save the output files. - **output_vtp** (bool) - If True, generates VTP files for 3D visualization. - **output_h5** (bool) - If True, saves the raw loss data in an HDF5 file. ### Request Example ```python from losscape.create_landscape import create_3D_losscape from torch.utils.data import DataLoader import torch.nn.functional as F # Assuming 'model', 'dataset' are already defined train_loader_fixed = DataLoader(dataset, batch_size=32, shuffle=False) X, Y, losses = create_3D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, criterion=F.cross_entropy, num_batches=8, x_min=-1.0, x_max=1.0, y_min=-1.0, y_max=1.0, num_points=50, save_only=True, output_path='./', output_vtp=True, output_h5=True ) ``` ### Response #### Success Response (200) - **X** (numpy.ndarray) - Meshgrid array for the first dimension (shape: `num_points` x `num_points`). - **Y** (numpy.ndarray) - Meshgrid array for the second dimension (shape: `num_points` x `num_points`). - **losses** (numpy.ndarray) - Array of loss values for each point in the grid (shape: `num_points` x `num_points`). #### Response Example ```json { "X": "... 50x50 meshgrid numpy array ...", "Y": "... 50x50 meshgrid numpy array ...", "losses": "... 50x50 loss values numpy array ..." } ``` ### Output Files - `./3d_losscape.png` (300 DPI contour plot) - `./losscape.vtp` (VTP file for 3D viewing) - `./losscape_log.vtp` (Log VTP file) - `./data.h5` (HDF5 file containing raw loss data) ``` -------------------------------- ### Generate 1D Loss Landscape in Python Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Generates a 1D visualization of the loss landscape using the `create_1D_losscape` function. This function takes the trained model and a fixed DataLoader as input to create the plot. ```python create_1D_losscape(model, train_loader_fixed) ``` -------------------------------- ### Custom Loss Function and Closure Source: https://context7.com/alxndrtl/losscape/llms.txt Shows how to use custom loss functions and model closures with `create_2D_losscape`. The custom loss includes cross-entropy and L2 regularization. The custom closure handles non-standard data formats and computes loss per batch. ```python from losscape.compute_loss import compute_loss from losscape.create_landscape import create_2D_losscape # Custom criterion def custom_loss(predictions, targets): ce_loss = F.cross_entropy(predictions, targets) # Add L2 regularization manually l2_reg = sum(p.pow(2).sum() for p in model.parameters()) return ce_loss + 0.001 * l2_reg # Custom closure for non-standard model inputs/outputs def custom_closure(train_loader, num_batches): loss = 0 device = "cuda" if torch.cuda.is_available() else "cpu" for batch_idx, batch_data in enumerate(train_loader): # Extract custom data format inputs = batch_data['features'].to(device) labels = batch_data['labels'].to(device) # Forward pass outputs = model(inputs) loss += F.cross_entropy(outputs, labels).item() if batch_idx + 1 >= num_batches: break return loss, batch_idx # Use with landscape creation create_2D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, criterion=custom_loss, closure=custom_closure, num_batches=10 ) ``` -------------------------------- ### Train Neural Network with losscape Source: https://context7.com/alxndrtl/losscape/llms.txt Trains a PyTorch neural network using the `train` function from the `losscape.train` module. It requires a PyTorch model, DataLoader, optimizer, and loss criterion. The function handles the training loop for a specified number of epochs and can optionally decay the learning rate. ```python from losscape.train import train import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader, TensorDataset # Define a simple neural network class SimpleNet(nn.Module): def __init__(self): super(SimpleNet, self).__init__() self.fc1 = nn.Linear(10, 50) self.fc2 = nn.Linear(50, 20) self.fc3 = nn.Linear(20, 2) def forward(self, x): x = F.relu(self.fc1(x)) x = F.relu(self.fc2(x)) x = self.fc3(x) return x # Create synthetic dataset X = torch.randn(1000, 10) y = torch.randint(0, 2, (1000,)) dataset = TensorDataset(X, y) train_loader = DataLoader(dataset, batch_size=32, shuffle=True) # Initialize and train model model = SimpleNet() optimizer = torch.optim.Adam(model.parameters(), lr=0.001) # Train with losscape's training function train( model=model, train_loader=train_loader, optimizer=optimizer, criterion=F.cross_entropy, epochs=100, decay_lr_epochs=30, verbose=1 # Print progress at 0%, 25%, 50%, 75%, 100% ) # Output: Epoch 25/100. Loss=0.523 # Epoch 50/100. Loss=0.321 # Epoch 75/100. Loss=0.187 # Epoch 100/100. Loss=0.098 ``` -------------------------------- ### Create Random Directions for Exploration Source: https://context7.com/alxndrtl/losscape/llms.txt Generates random directions for exploring the loss landscape. `create_random_direction` creates a single normalized direction, while `create_random_directions` creates multiple directions suitable for 3D landscapes. The directions are lists of tensors normalized by filter-wise norm. ```python from losscape.create_directions import create_random_direction, create_random_directions # Create single random direction (for 2D landscape) direction = create_random_direction(model) # Returns: list of tensors, one per model parameter # Each tensor normalized by filter-wise norm as per Li et al. 2018 # Create two random directions (for 3D landscape) directions = create_random_directions(model) # Returns: [x_direction, y_direction] # Each direction is a list of normalized tensors matching model parameters # Example: Use custom directions for 3D landscape X, Y, losses = create_3D_losscape( model=model, train_loader_unshuffled=train_loader_fixed, directions=directions, # Use pre-computed directions num_batches=8, num_points=30 # Smaller grid for faster computation ) ``` -------------------------------- ### Create Spiral Dataset Class in Python Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Defines a custom PyTorch Dataset class named SpiralDataset for generating spiral-shaped data. It generates data points and labels, converting them to PyTorch tensors. The dataset supports standard PyTorch DataLoader. ```python class SpiralDataset(Dataset): def __init__(self, N, K): self.X, self.y = self.generate_spiral_dataset(N, K) # Convert numpy arrays to PyTorch tensors self.X = torch.from_numpy(self.X).float() self.y = torch.from_numpy(self.y).long() def generate_spiral_dataset(self, N, K): X = np.zeros((N*K, 2)) # data matrix (each row = single example) y = np.zeros(N*K, dtype='uint8') # class labels for j in range(K): ix = range(N*j, N*(j+1)) r = np.linspace(0.0, 1, N) # rayon t = np.linspace(j*4, (j+1)*4, N) + np.random.randn(N)*0.2 # theta X[ix] = np.c_[r*np.sin(t), r*np.cos(t)] y[ix] = j return X, y def __len__(self): return len(self.y) def __getitem__(self, idx): return self.X[idx], self.y[idx] N = 100 # number of points per class K = 3 # number of classes spiral_dataset_train = SpiralDataset(N, K) spiral_dataset_test = SpiralDataset(N, K) train_loader = DataLoader(spiral_dataset_train, batch_size=3*N, shuffle=True) test_loader = DataLoader(spiral_dataset_train, batch_size=3*N, shuffle=False) train_loader_fixed = DataLoader(spiral_dataset_train, batch_size=3*N, shuffle=False) ``` -------------------------------- ### Generate 2D Loss Landscape in Python Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Generates a 2D visualization of the loss landscape using the `create_2D_losscape` function. Similar to the 1D version, it requires the trained model and a fixed DataLoader to produce the plot. ```python create_2D_losscape(model, train_loader_fixed) ``` -------------------------------- ### Compute Loss on Model with losscape Source: https://context7.com/alxndrtl/losscape/llms.txt Computes the loss for a given PyTorch model and dataset using the `compute_loss` function from `losscape.compute_loss`. This function is a utility for calculating model performance on a specified dataset with a given loss criterion. It requires the model, an unshuffled DataLoader, and the loss function. ```python from losscape.compute_loss import compute_loss import torch.nn.functional as F ``` -------------------------------- ### Compute Average Loss Source: https://context7.com/alxndrtl/losscape/llms.txt Calculates the average loss over a specified number of batches using torch.no_grad() for efficiency. It takes a model, data loader, loss criterion, and the number of batches as input. ```python from losscape.compute_loss import compute_loss # Compute average loss over specified batches loss_value = compute_loss( model=model, train_loader_unshuffled=train_loader_fixed, get_batch=None, # Optional custom batch function criterion=F.cross_entropy, num_batches=8, # Average over 8 batches closure=None # Optional custom closure for non-standard models ) # Returns: 0.098 (average loss across 8 batches) # Computation uses torch.no_grad() for efficiency ``` -------------------------------- ### Define Multi-Layer Perceptron (MLP) Model in Python Source: https://github.com/alxndrtl/losscape/blob/main/spirals.ipynb Defines a simple Multi-Layer Perceptron (MLP) neural network using PyTorch. The MLP has three fully connected layers with ReLU activation functions. It takes 2D input and outputs 3 classes. ```python class MLP(nn.Module): def __init__(self): super(MLP, self).__init__() self.fc1 = nn.Linear(2, 100) self.fc2 = nn.Linear(100, 30) self.fc3 = nn.Linear(30, 3) def forward(self, x): x = self.fc1(x) x = F.relu(x) x = self.fc2(x) x = F.relu(x) x = self.fc3(x) return x ``` -------------------------------- ### Compute Loss on Model Source: https://context7.com/alxndrtl/losscape/llms.txt A utility function to compute the loss of a given model on a dataset using a specified criterion. ```APIDOC ## Compute Loss on Model ### Description A utility function to compute the loss of a given model on a dataset using a specified criterion. This function is typically used internally by the visualization functions but can be called directly. ### Method `compute_loss` function from `losscape.compute_loss` ### Parameters #### Function Parameters - **model** (torch.nn.Module) - The neural network model. - **train_loader_unshuffled** (DataLoader) - DataLoader for the dataset to compute loss on. - **criterion** (callable) - The loss function. - **num_batches** (int) - The number of batches from the DataLoader to use for computation. ### Request Example ```python from losscape.compute_loss import compute_loss import torch.nn.functional as F # Assuming 'model', 'train_loader_fixed' are defined # Example: Compute average loss over the first 5 batches average_loss = compute_loss( model=model, train_loader_unshuffled=train_loader_fixed, criterion=F.cross_entropy, num_batches=5 ) ``` ### Response #### Success Response (200) - **average_loss** (float) - The computed average loss over the specified batches. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.