Skip to main content

TrainLens

Turn AI training runs into research-grade notebook reports.

TrainLens is a Jupyter-first support package for AI model training and research workflows. Its main value is that you can turn the training state already present in your notebook into structured analysis without leaving Jupyter, opening a separate chat, or copying experiment context by hand.

It redacts likely secrets and asks an OpenAI-compatible LLM to draft:

  • a scientific paper-style training report
  • an evidence-backed improvement plan

It is useful when you run many experiments and want consistent explanations of metrics, datasets, hyperparameters, limitations, and next steps directly inside the notebook where the work is happening.

CI TrainLens 0.3.0 Python License: Apache-2.0

Actively maintained by Eduardo J. Barrios.
For issues or improvements, open a pull request or email edujbarrios@outlook.com.

Quickstart

Install TrainLens:

pip install trainlens

Configure an OpenAI-compatible LLM provider:

import os

os.environ["TRAINLENS_LLM_BASE_URL"] = "https://api.openai.com/v1"
os.environ["TRAINLENS_LLM_API_KEY"] = "your-api-key"
os.environ["TRAINLENS_LLM_MODEL"] = "gpt-5.4-mini"

Keep useful experiment state in ordinary notebook variables:

dataset_name = "synthetic_cpu_binary_classification"
dataset_notes = "240 synthetic 2D samples; balanced validation split."
model_name = "pure-python-logistic-regression"
training_params = {"epochs": 30, "learning_rate": 0.45}

history = {
    "train_loss": [0.6095, 0.5005, 0.2459],
    "eval_loss": [0.6164, 0.5160, 0.2808],
    "accuracy": [0.8889, 0.9056, 0.9222],
    "val_accuracy": [0.8167, 0.8333, 0.9167],
}

Run the notebook magics:

%load_ext trainlens.magic.extension

# Scientific paper-style training report
%explain_training

# Evidence-backed experiment plan
%suggest_improvements
Magic Output
%explain_training Paper-style report with results, discussion, limitations, and LLM provenance.
%suggest_improvements Follow-up experiment plan grounded in the same notebook evidence.

Local Models

TrainLens can avoid external API token costs by using a local OpenAI-compatible server. Example with Ollama:

ollama pull llama3.1
ollama serve
import os

os.environ["TRAINLENS_LLM_BASE_URL"] = "http://localhost:11434/v1"
os.environ["TRAINLENS_LLM_API_KEY"] = "ollama"
os.environ["TRAINLENS_LLM_MODEL"] = "llama3.1"

The same pattern works with LM Studio, vLLM, llama.cpp server, and similar local servers.

Python API

from trainlens import build_improvement_ideas, build_paper_report

paper = build_paper_report()
ideas = build_improvement_ideas()

Inside Jupyter, helpers read the active notebook namespace automatically. Outside IPython, pass an explicit dictionary-like namespace.

Token Usage

Costs depend on provider, model, tokenizer, prompt size, and output length. These are rough estimates, not billing records.

Call Input Tokens Output Tokens Total
%explain_training paper report 1K-2K 2.5K-3.5K 3.5K-5.5K
%suggest_improvements plan 1K-2K 2K-3K 3K-5K
Both calls 2K-4K 4.5K-6.5K 6.5K-10.5K

Approximate USD cost for a 50% input / 50% output token mix, using public prices checked on 2026-07-07:

Provider / model 1K tokens 100K tokens 1M tokens 10M tokens
OpenAI gpt-5.4-mini $0.0026 $0.2625 $2.6250 $26.2500
Anthropic Claude Haiku 4.5 $0.0030 $0.3000 $3.0000 $30.0000
Google Gemini 2.5 Flash-Lite $0.0003 $0.0250 $0.2500 $2.5000
Local Ollama / LM Studio $0 API cost $0 API cost $0 API cost $0 API cost

Cost formula:

\text{estimated cost} =
\frac{
\text{input tokens} \times \text{input price per 1M}
+ \text{output tokens} \times \text{output price per 1M}
}{1{,}000{,}000}

Privacy

TrainLens summarizes visible notebook state, redacts likely secrets, truncates large literals, and sends only the resulting context to the configured endpoint. Do not store real API keys in notebooks or committed files.

License

Apache License 2.0. See LICENSE.

Release files for trainlens 0.3.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.3.0
File Size Uploaded
trainlens-0.3.0.tar.gz 36.3 kB Details

Built distribution (wheel)

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

Total release size: 76.4 kB

Release files / trainlens-0.3.0.tar.gz

Download URL trainlens-0.3.0.tar.gz
Size 36.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7429b41bc78c7cc59bf5bda4e932fd2b5aac035e0dcba9e5c85ff082a76304de
BLAKE2b-256 checksum
How to use checksums
ff8bab6e651a484bff0486aaa9bfa3a1b2115a9679febbbd45177637f5cb001e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

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

Download URL trainlens-0.3.0-py3-none-any.whl
Size 40.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30d2a99fdef1c36a1bf540c47df4180aefc2a29e15a23c2547e44b4d44b3ee0f
BLAKE2b-256 checksum
How to use checksums
ad003b00bc7c6e9203e2b5fb474dd3f970eccd4bb6498740b53482edabdc16bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release history Release notifications | RSS feed

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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