Data Types
Core data types used in the W&B Query Expression Language
3 minute read
The W&B Query Expression Language lets you programmatically analyze and visualize your ML experiments directly in the W&B UI. Transform raw experiment data into actionable insights using powerful query operations.
Query Expressions are NOT local code! They are typed directly into the W&B web interface, not in your Python/JavaScript files.
First, you need data in W&B to query. This requires the W&B Python SDK:
pip install wandb # Only installation needed - for logging data
# your_training_script.py - runs locally
import wandb
wandb.init(project="my-ml-project")
wandb.log({"loss": 0.5, "accuracy": 0.85})
wandb.finish()
After logging runs, analyze them in the W&B web interface:
wandb.ai/your-username/my-ml-project
)// This is typed into the wandb.ai interface
runs.map(r => runSummary(r).accuracy).avg()
Here’s what you would type in the W&B Query Panel editor to analyze a hyperparameter sweep:
// Remember: This is typed into the Query Panel at wandb.ai
// NOT in your local code files!
// Step 1: Filter to successful runs from your latest sweep
const validRuns = runs
.filter(r => r.state === "finished")
.filter(r => runConfig(r).sweep_id === "sweep_2024_01")
// Step 2: Extract key metrics and configurations
const runAnalysis = validRuns.map(r => ({
name: r.name,
accuracy: runSummary(r).best_accuracy,
loss: runSummary(r).final_loss,
learning_rate: runConfig(r).learning_rate,
batch_size: runConfig(r).batch_size,
training_time: r.duration
}))
// Step 3: Find the best run
const bestRun = validRuns
.reduce((best, current) =>
runSummary(current).best_accuracy > runSummary(best).best_accuracy
? current
: best
)
// Step 4: Calculate statistics across all runs
const stats = {
avg_accuracy: validRuns.map(r => runSummary(r).best_accuracy).avg(),
std_accuracy: validRuns.map(r => runSummary(r).best_accuracy).std(),
total_compute_hours: validRuns.map(r => r.duration).sum() / 3600
}
// Step 5: Group by hyperparameter to find optimal values
const byLearningRate = validRuns
.groupby(r => runConfig(r).learning_rate)
.map(group => ({
lr: group.key,
avg_accuracy: group.values.map(r => runSummary(r).best_accuracy).avg(),
num_runs: group.values.length
}))
All operations can be chained together for powerful data transformations:
runs
.filter(/* select runs */)
.map(/* transform data */)
.groupby(/* organize results */)
.sort(/* order output */)
The expression language is fully typed, providing autocomplete and validation as you write queries.
Functions for querying and manipulating W&B data:
Core type definitions:
The following examples show Query Expressions you would type in the W&B web UI:
// Type this in the Query Panel at wandb.ai
// Group runs by model type and compare average performance
runs
.groupby(r => runConfig(r).model_type)
.map(g => ({
model: g.key,
avg_accuracy: g.values.map(r => runSummary(r).accuracy).avg(),
best_accuracy: g.values.map(r => runSummary(r).accuracy).max(),
training_hours: g.values.map(r => r.duration).sum() / 3600
}))
.sort((a, b) => b.avg_accuracy - a.avg_accuracy)
// Monitor ongoing experiments
runs
.filter(r => r.state === "running")
.map(r => ({
name: r.name,
progress: runSummary(r).epoch / runConfig(r).total_epochs,
current_loss: runSummary(r).loss,
eta_minutes: (r.duration / runSummary(r).epoch) *
(runConfig(r).total_epochs - runSummary(r).epoch) / 60
}))
// Identify best performing hyperparameter combinations
runs
.filter(r => runSummary(r).val_accuracy > 0.85)
.map(r => ({
accuracy: runSummary(r).val_accuracy,
lr: runConfig(r).learning_rate,
batch_size: runConfig(r).batch_size,
optimizer: runConfig(r).optimizer
}))
.sort((a, b) => b.accuracy - a.accuracy)
.slice(0, 10) // Top 10 configurations
Core data types used in the W&B Query Expression Language
Functions and operations for querying and manipulating W&B data in the Query Expression Language.
Was this page helpful?
Glad to hear it! If you have more to say, please let us know.
Sorry to hear that. Please tell us how we can improve.