Skip to main content

TrainLens

TrainLens turns ML training runs into evidence: what changed, what went wrong, and what experiment to run next.

TrainLens is lightweight, notebook-first, and local by default. Its core analysis is deterministic; LLM reasoning is optional.

CI PyPI 0.17.0 Python License: Apache-2.0

Start with the notebook

The fastest way to understand TrainLens is the end-to-end example:

Open the TrainLens quickstart notebook in Google Colab

It shows dataset context, training diagnosis, plots, experiment evidence, LLM request previewing, and evidence-backed next-step planning.

Install

pip install trainlens

For plots:

pip install "trainlens[plots]"

No tracking server or hosted TrainLens service is required.

Choose how you want to use TrainLens

Workflow Who does the reasoning? Extra LLM setup inside TrainLens?
Local analysis TrainLens deterministic analyzers No
Agent Mode The surrounding agent: Claude, Codex, Cursor, etc. Usually no
LLM reports An LLM provider called directly by TrainLens Yes, optional provider configuration

1. Local deterministic analysis

from trainlens import analyze, plot_training_curves, render_report

analysis = analyze(globals())
plot_training_curves(globals())
print(render_report(analysis))

TrainLens keeps training, validation, and held-out test evidence distinct and turns notebook state into structured observations and recommendations.

2. Agent Mode: TrainLens as the evidence layer

TrainLens can be used inside AutoResearch-style skills and coding agents.

from trainlens import build_agent_context, verify_agent_plan

context = build_agent_context(globals())
print(context.to_markdown())

plan = verify_agent_plan(agent_response, context=context)
print(plan.is_fully_supported)

In Agent Mode, TrainLens prepares bounded deterministic context, stable evidence IDs, instructions, and an output schema. The surrounding agent performs the reasoning and tool execution.

Agent Mode can therefore use whatever LLM and provider are available to the host agent. In the common case, Claude, Codex, Cursor, or another coding/research agent already owns that model connection, so there is no reason to configure a second LLM provider inside TrainLens.

training state -> TrainLens evidence -> Claude / Codex / Cursor -> structured plan -> TrainLens verification

Terminal-first agents can use portable run JSON:

trainlens agent-context candidate.json --format json > agent-context.json
trainlens verify-agent-plan plan.json --context agent-context.json

See Agent Mode and the reusable Agent Skill example.

3. No agent? TrainLens can generate LLM reports directly

Agent Mode is optional. TrainLens can also call an LLM provider itself to generate training reports, diagnoses, or improvement ideas from its sanitized deterministic evidence.

from getpass import getpass
from trainlens import OpenAICompatibleProvider, build_llm_report

llm = OpenAICompatibleProvider.from_values(
    base_url="https://your-provider.example/v1",
    model="your-model",
    api_key=getpass("LLM API key: "),
)

report = build_llm_report(globals(), provider=llm)
print(report.markdown)

You can inspect the exact sanitized request before sending it with preview_llm_request(). TrainLens also supports evidence-verified structured improvement plans through build_verified_improvement_plan().

See LLM setup and privacy and Verified LLM plans.

Dataset context

from trainlens import explain_dataset

dataset_context = explain_dataset(
    {
        "train": train_dataset,
        "validation": validation_dataset,
        "test": test_dataset,
    },
    target="label",
)

TrainLens can summarize tabular, text, image, and image-centered multimodal datasets without sending raw rows, pixels, image bytes, private paths, or filenames to an LLM.

Experiments, runs, and CI

TrainLens can save portable runs, compare experiments, select validation-based checkpoints, aggregate repeated seeds, estimate controlled parameter effects, build Pareto-aware leaderboards, and gate regressions in CI.

trainlens compare baseline.json candidate.json
trainlens check candidate.json --against baseline.json --require 'f1>=0.85'

Core idea

TrainLens is the evidence layer, not AutoML:

  • deterministic analysis stays local by default;
  • Agent Mode lets an existing agent reason over TrainLens evidence using the agent's own LLM/provider;
  • direct LLM reports remain available when no agent is involved;
  • held-out test evidence is kept out of tuning decisions;
  • generated recommendations should still be checked against the underlying data and experimental design.

Documentation

Contributing and license

See CONTRIBUTING.md to contribute and SECURITY.md to report vulnerabilities. TrainLens is licensed under the Apache License 2.0.

Metadata

Release files for trainlens 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trainlens 0.17.0
File Size Uploaded
trainlens-0.17.0.tar.gz 191.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trainlens 0.17.0
File Interpreter ABI Platform
trainlens-0.17.0-py3-none-any.whl Python 3 none any Details

Total release size: 326.4 kB

Release files / trainlens-0.17.0.tar.gz

Download URL trainlens-0.17.0.tar.gz
Size 191.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f4848ed028071a96b2f0a2a1be54eb695f5d8d5dc13e895d5d19bd8d58d1c799
BLAKE2b-256 checksum
How to use checksums
3f19df487ab7c6400aede433ee42849ccf8853e1328b8940ae0eae408a6dfe5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log

Release files / trainlens-0.17.0-py3-none-any.whl

Download URL trainlens-0.17.0-py3-none-any.whl
Size 135.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8be6eb2a3c11b3fe0c0b51d7f578616946e355bdc2fbfa0851fbafec4c3d266b
BLAKE2b-256 checksum
How to use checksums
8f9bcfc9958a4a85d501406c788ca0adf2112d36353c0272696b99b5ac2cba34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 6, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page