Use the W&B Python Library to track machine learning experiments with a few lines of code. You can then review the results in an interactive dashboard or export your data to Python for programmatic access using our Public API. Quickly find and reproduce machine learning experiments with W&B.
Utilize W&B Integrations if you use use popular frameworks such as PyTorch, Keras, or Scikit. See our Integration guides for a for a full list of integrations and information on how to add W&B to your code.
How it works
W&B Experiments are composed of the following building blocks:
wandb.init(): Initialize a new run at the top of your script. This returns a
Runobject and creates a local directory where all logs and files are saved, then streamed asynchronously to a W&B server. If you want to use a private server instead of our hosted cloud server, we offer Self-Hosting.
wandb.config: Save a dictionary of hyperparameters such as learning rate or model type. The model settings you capture in config are useful later to organize and query your results.
wandb.log(): Log metrics over time in a training loop, such as accuracy and loss. By default, when you call
wandb.logit appends a new step to the
historyobject and updates the
history: An array of dictionary-like objects that tracks metrics over time. These time series values are shown as default line plots in the UI.
summary: By default, the final value of a metric logged with wandb.log(). You can set the summary for a metric manually to capture the highest accuracy or lowest loss instead of the final value. These values are used in the table, and plots that compare runs — for example, you could visualize at the final accuracy for all runs in your project.
wandb.log_artifact: Save outputs of a run, like the model weights or a table of predictions. This lets you track not just model training, but all the pipeline steps that affect the final model.
The proceeding pseudocode demonstrates a common W&B Experiment tracking workflow:
# Flexible integration for any Python script
# 1. Start a W&B Run
# 2. Save mode inputs and hyperparameters
config = wandb.config
config.learning_rate = 0.01
# Set up model and data
model, dataloader = get_model(), get_data()
# Model training goes here
# 3. Log metrics over time to visualize performance
# 4. Log an artifact to W&B
How to get started
Depending on your use case, explore the following resources to get started with W&B Experiments:
- If this is your first time using W&B Experiments, we recommend you read the Quick Start. The Quickstart walks you through setting up your first experiment.
- Explore topics about Experiments in the W&B Developer Guide such as:
- Create an experiment
- Configure experiments
- Log data from experiments
- View results from experiments
- Explore the W&B Python Library within the W&B API Reference Guide.