This mock training script logs simulated accuracy and loss metrics to W&B. Copy and paste the following code into a Python script or notebook cell and run it:
Select Python to create a new code cell.
Copy and paste the following code into the cell:
import randomimport wandbPROJECT = "your-project-name"# Dictionary with hyperparametersconfig = { 'epochs' : 10, 'lr' : 0.01}with wandb.init(project=PROJECT, config=config) as run: offset = random.random() / 5 print(f"lr: {config['lr']}") # Simulate a training run for epoch in range(2, config['epochs']): acc = 1 - 2**-config['epochs'] - random.random() / config['epochs'] - offset loss = 2**-config['epochs'] + random.random() / config['epochs'] + offset print(f"epoch={config['epochs']}, accuracy={acc}, loss={loss}") run.log({"accuracy": acc, "loss": loss})
Press Command + Enter on macOS or Ctrl+Enter on Windows or Linux. Alternatively, click Play () next to the cell.
View the accuracy and loss metrics logged during the training experiment:
Select Workspace from the project sidebar.
Review the runs and visualizations in the workspace. The runs list shows each run logged to the project and its details. Workspace panels display visualizations of the metrics logged during each run.
W&B stores your notebook as a W&B Artifact and automatically saves changes as a new Artifact version every 30 seconds and when the notebook’s compute session stops.To save your latest changes immediately, use one of the following options:
Press Command+S on macOS or Ctrl+S on Windows or Linux.