Catalog PyPI
PACKAGE EXPLORERView in registry

aicoach

PyPI

A framework-agnostic Python library that coaches you through model training.

aicoachdiagnosticslearningmachinetraining
Versions collected1
Direct dependencies2From release 0.1.0
Last observed21 Oct, 10:10 UTC

README

Version 0.1.0 documentation

aicoach

A framework-agnostic Python library that acts like a mentor watching your model training loop.

Python License: MIT Version

aicoach monitors per-epoch training metrics (loss, validation loss, learning rate, accuracy) and returns plain-English advice based on patterns it detects — with no model training, GPU access, or ML framework integration required inside the library itself.


Quick Start

import aicoach

coach = aicoach.Coach()

for epoch in range(epochs):
    train_loss, val_loss = run_one_epoch(...)   # your training loop
    coach.observe(epoch=epoch, train_loss=train_loss, val_loss=val_loss, lr=current_lr)

    for tip in coach.get_advice():
        print(f"💡 {tip}")

For standalone class-imbalance checks (before training begins):

label_counts = {"cat": 800, "dog": 750, "bird": 90}
advice = aicoach.check_class_imbalance(label_counts)
if advice:
    print(f"⚠️  {advice}")

Installation

pip install aicoach

Or from source:

git clone https://github.com/Rishabh55122/Aicoach.git
cd Aicoach
pip install -e .[dev]

Module Overview

ModuleFunctionDetectsSeverity
historyCoach.observe() / Coach.get_advice()Observation store + advice aggregator—
overfittingcheck_overfitting()Val loss rising while train loss fallsWARNING
plateaucheck_plateau()Metric stalled (relative range < threshold)WARNING
learning_ratecheck_learning_rate()LR too high (oscillation) or too low (slow)WARNING / INFO
imbalancecheck_class_imbalance()Majority/minority class ratio too largeWARNING
divergencecheck_divergence()NaN, Inf, or exponential loss explosionCRITICAL

Advice Object

Every check returns either None (no issue) or an Advice object:

from aicoach.data_types import Advice, AdviceLevel

advice.message   # str  — plain-English description and suggested action
advice.level     # AdviceLevel.INFO | WARNING | CRITICAL
advice.code      # str  — machine-readable identifier (e.g. "overfitting")
advice.metadata  # dict — diagnostic context (thresholds, values, indices used)

print(advice)    # [WARNING] (overfitting) Validation loss has risen for 3 consecutive epoch(s)...

Module Details

history — Observation tracking
coach = aicoach.Coach()

coach.observe(
    epoch=0,
    train_loss=0.85,
    val_loss=0.90,    # optional
    lr=1e-3,          # optional
    accuracy=0.72,    # optional
)

coach.get_metric("train_loss")           # all values
coach.get_metric("val_loss", window=5)   # last 5 only
coach.get_observations()                 # list[Observation]
coach.reset()                            # clear for a new run
len(coach)                               # number of recorded epochs

Validation rules:

  • epoch must be a non-negative, strictly increasing int
  • All metric values must be int or float (booleans rejected)
  • None is accepted for optional fields
overfitting — Early stopping advice
from aicoach.overfitting import check_overfitting

advice = check_overfitting(coach, patience=3)

Triggers when (both conditions must hold over the last patience + 1 epochs):

  1. val_loss rises on every consecutive step
  2. train_loss shows a net decrease over the same window

Default: patience=3 — sensible middle ground between sensitivity and noise-resistance. Increase for noisy validation curves.

plateau — Stalled training detection
from aicoach.plateau import check_plateau

advice = check_plateau(coach, metric="train_loss", window=5, threshold=0.01)

Triggers when:

(max(window) - min(window)) / mean(abs(window)) < threshold

Uses relative range so it scales correctly across all loss magnitudes (a flat loss at 0.01 and a flat loss at 100 are both detected equally).

Defaults: window=5, threshold=0.01 (1%)

learning_rate — LR too high or too low
from aicoach.learning_rate import check_learning_rate

advice = check_learning_rate(coach, window=5)

Three-zone design (mutually exclusive with plateau):

ZoneConditionAdvice
Stallednet decrease < 1%check_plateau owns this
Creeping1% ≤ net decrease < 5% + low oscillationlr_too_slow (INFO) — raise LR
Healthynet decrease ≥ 5%None
Oscillating≥ 40% of steps went uplr_oscillation (WARNING) — lower LR

Oscillation is checked first and takes priority over the zone check.

Defaults: window=5, oscillation_threshold=0.40, plateau_threshold=0.01, healthy_rate_threshold=0.05

imbalance — Class imbalance check
from aicoach.imbalance import check_class_imbalance

label_counts = {"cat": 800, "dog": 750, "bird": 90}
advice = check_class_imbalance(label_counts, ratio_threshold=4.0)

Triggers when: max(counts) / min(counts) >= ratio_threshold

Standalone — does not require a Coach instance. Call before or during training.

Default: ratio_threshold=4.0 — flags when the dominant class has at least 4× as many samples as the rarest class.

divergence — Catastrophic failure detection
from aicoach.divergence import check_divergence

advice = check_divergence(coach, window=5, growth_threshold=10.0)

Three sub-checks, in priority order:

CodeTriggerScope
divergence_nanAny NaN in train_lossFull history
divergence_infAny ±Inf in train_lossFull history
divergence_explosiveloss[-1] / loss[0] >= growth_thresholdRolling window

Returns CRITICAL severity. When divergence fires via get_advice(), all other checks are suppressed.

Default: window=5, growth_threshold=10.0 (10× growth within the window)


Running Tests

pip install -e .[dev]
pytest -v

All Default Thresholds (for your review before publishing)

CheckParameterDefaultRationale
check_overfittingpatience3Middle ground between sensitivity and noise resistance
check_plateauwindow5Short enough to respond quickly, wide enough to smooth noise
check_plateauthreshold0.01 (1%)Relative range — scale-invariant across all loss magnitudes
check_learning_ratewindow5Consistent with plateau
check_learning_rateoscillation_threshold0.40 (40%)≥ 2 of 4 up-steps within window indicates bouncing
check_learning_rateplateau_threshold0.01 (1%)Shared lower boundary with check_plateau
check_learning_ratehealthy_rate_threshold0.05 (5%)≈ 1%/epoch net decrease — conservative minimum progress
check_class_imbalanceratio_threshold4.0×Commonly cited rule of thumb for moderate imbalance
check_divergencewindow5Rolling window for explosive-growth check
check_divergencegrowth_threshold10.0×10× growth over 5 epochs is unambiguous explosion

License

MIT — see LICENSE.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.020 Jul 20262

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
rishabh55122/aicoach

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:10 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:df7467918aa9cd008f7287015c6e06e2b2755dc7fb2e2cba1743ba07372a8cc5