Skip to main content

edu-ai-suite

A plain-Python teaching library for image features, tiny language models and LoRA fine-tuning, with Hugging Face assets: cloud photographs, digits, and an LLM small enough to fine-tune on a 16 GB Mac.

  • Each image feature turns a picture into one number, such as mean_intensity, edge_density, coarse_texture and left_right_symmetry.
  • Each language model is a tokenizer and an architecture fitted to text, which then generates more text.
  • Each LoRA run takes a pre-trained model and produces an adapter.

Only the LoRA component needs MLX, and therefore Apple Silicon.

Contents

  • edu_ai_suite/images/ - the image pipeline: decode, resize, flatten and pixels, and the features package built on them: one class per feature, the groups that select them, extraction, and the generated guide.
  • edu_ai_suite/lm/ - the character and word tokenizers with their stats, pairs, the bigram/MLP/LSTM architectures, training options and results, and LanguageModel, which carries its tokenizer, so one directory holds everything a model needs.
  • edu_ai_suite/lora/ - LoRA fine-tuning of an MLX base model: options, data, the train/validation split, the run, and the adapter and model objects that read it back.
  • edu_ai_suite/text/ - plain text into training rows, behind one facade: cleaning, splitting and Q/A parsing.
  • edu_ai_suite/assets/ - the Hugging Face assets, each behind a download function that caches and verifies it, and the command-line interface over them.
  • examples/ - one runnable script per subject, and a shell walkthrough of the LoRA scripts in the order a run happens.
  • tests/ - the test suite, in plain Python.
  • GLOSSARY.md - definitions of key words.

Installation

Requirements: Python 3.11+, and macOS on Apple Silicon for LoRA training.

Everything except LoRA is a plain dependency: OpenCV for the image pipeline, Keras on a TensorFlow backend for the from-scratch language models. Only LoRA is an extra, because it uses MLX, which is specific to Apple Silicon.

pip install edu-ai-suite            # everything but LoRA
pip install "edu-ai-suite[lora]"    # plus LoRA (Apple Silicon)

Development, from the repository root:

uv sync
uv run pytest
uv build

Python API

Language models

A minimal example showing how to train and run a small LLM.

import edu_ai_suite.lm as lm

text = """...a few thousand lines of normal English text..."""
held_out_text = """...different text, which the model never trains on..."""

# The tokenizer is built once and travels inside the model.
tokenizer = lm.tokenizer_from_text(text, "char")
tokenizer = tokenizer.keep_top(2000)  # or .drop_rare(min_count=3); pure, chainable

# An architecture is the recipe; a model is that recipe fitted. MLP is a
# scikit-learn estimator, so get_params() lists its settings.
architecture = lm.MLP(context_width=16, embedding_dim=32, hidden_units=128)
model = lm.LanguageModel(architecture, tokenizer).fit(
    text,
    lm.TrainingOptions(epochs=15, validation_fraction=0.1, seed=0),
)

# fit builds pairs at the architecture's context width and splits by
# TrainingOptions.validation_fraction, so the data and the weights cannot disagree.

# Generate some text, evaluate on held out text, and save the model.
model.generate("the ", temperature=0.8, max_new_tokens=64)
model.evaluate(held_out_text)  # {'loss': ..., 'perplexity': ...}; perplexity = e^loss
model.save("my-model")  # weights + tokenizer + metadata

LoRA

import tempfile
from pathlib import Path

import edu_ai_suite.assets as assets
import edu_ai_suite.lora as lora

base = assets.get_britllm()  # pinned 4-bit MLX weights, cached on first use
data = lora.LoRAData.from_texts(corpus)  # or lora.LoRAData.from_pairs(pairs)
with tempfile.TemporaryDirectory() as scratch:  # this run's scratch, deleted on exit
    run = lora.train_lora(
        base,
        data,
        options=lora.LoRAOptions(iters=300, num_layers=16),
        workdir=scratch,  # each run gets a fresh child of it
        name="my-adapter",  # the artifact's name is the caller's to choose
    )
    for event in run:  # lora.Params, then TrainReport and ValReport as they arrive
        print(event)
    # keep the artifact somewhere you own; the scratch can then be discarded
    artifact = run.adapter.save(Path("adapters") / run.adapter.name)
model = lora.LoRAModel.from_artifact(artifact)
model.generate("In the second century", temperature=0)
model.evaluate(held_out_text)  # {'loss': ..., 'perplexity': ...}
model.adapter_enabled = False  # the same base model, before adaptation

train_lora returns a run rather than doing the work: nothing starts until you iterate it, each report arrives as a typed event, and run.adapter is the artifact once the iteration ends. run.stop() may be called from any thread - a Stop control in a caller does exactly that - and it returns at once; the stop itself happens in the iteration, which also waits for the training process to be gone before anything reads its directory. mlx-lm writes a checkpoint every save_every iterations, so a stop adopts the newest and iters_completed records how far the run got, while a stop before the first one raises TrainingStopped and produces no model. The training runs in its own process - a module whose name begins mlx_ hides that, along with mlx-lm's API and file conventions, so the rest of lora/ never sees a subprocess.

Image feature groups

Each feature is a class in edu_ai_suite.images.features.catalogue, carrying its own name, description sentence and computation. Groups are a set of membership lists over that flat catalogue (edu_ai_suite.images.features.groups): membership lists used for ablation and display, so a feature can belong to more than one group and the grouping never touches the feature itself.

Group Count What it describes
A 6 Global photometry: brightness, contrast, skewness, kurtosis, bright fraction
B 10 Row/column/diagonal profile summaries: trend, roughness, peaks, crossings
C 6 Spatial mass: centre of mass, spread, elongation, radial gradient
D 6 Texture: gradient, edge density, fine/coarse texture, autocorrelation width
E 3 Topology: hole count, foreground area, stroke crossings
F 3 Symmetry: left-right, top-bottom, quadrant similarity
G 4 Colour (opt-in): bluish fraction, the blue-red balance, colourfulness, greenery

Groups A-F run on a preprocessed luminance image. Group G reads colour directly and is off by default.

import edu_ai_suite.images.features as features

vec = features.extract_features(rgb_image, groups="ABCDEF")
vec["hole_count"]  # a feature value
vec.to_array()  # one float per selected feature
features.get_feature("hole_count").description  # title, sentence, intuition, mechanics
features.all_features()  # the full catalogue, in stable column order

The feature guide

Every feature carries four descriptions: a title, a one-sentence summary, a plain-language account of which pictures move it and which leave it cold, and a technical account of how it is computed with links for further reading. The whole guide is generated from the catalogue when it is asked for, so it cannot drift from the code. feature_guide_markdown returns the whole page:

import edu_ai_suite.images.features as features

print(features.feature_guide_markdown())

A runnable script lives in examples/image_features.py (uv run python examples/image_features.py). It reads three real cloud photographs from examples/ (credits in examples/CREDITS.md) and shows the catalogue and its descriptions, the extraction and ablation selections, fine texture on wispy cirrus against coarse texture on a roll cloud, and the colour shortcut separating a blue sky from ground vegetation.

Datasets

import edu_ai_suite.assets as assets

britllm = assets.get_britllm()  # a 4-bit MLX snapshot, 1.40 GB
mnist = assets.get_mnist()  # <root>/train, <root>/val: 28x28, 500/100 per digit
clouds = assets.get_clouds()  # <root>/ac, sc, cu, cb, ci + CREDITS.md

get_britllm, get_mnist and get_clouds each download, prepare and verify one pinned Hub asset. The source and the prepared tree are cached; repeated calls are offline.

  • britllm-4bit - tcorbettclark/britllm-3b-v0.1-4bit-mlx, a 4-bit affine conversion of britllm/britllm-3b-v0.1 (2.67B parameters, 1.40 GB), verified against the SHA-256 of its weights file. It keeps the source model's ODC-BY licence; examples/build_britllm_4bit.py builds and optionally publishes it.
  • mnist-digits - ylecun/mnist (MIT), 60k/10k parquet; get_mnist keeps 500/100 per digit at the source 28x28 resolution in the folder-per-label layout.
  • ccsn-clouds - aduuuuuu/CCSN (MIT mirror; the CCSN database itself is CC0), the five genera Ac, Sc, Cu, Cb and Ci at 256x256, with CREDITS.md. Cite Zhang et al. (2018), CloudNet.

The assets command lists each asset with its type, size, cache status and repo; fetch is idempotent and prints the usable path:

assets list
assets fetch britllm-4bit
assets fetch mnist-digits
assets fetch ccsn-clouds

The same interface is available as python -m edu_ai_suite.assets.

Examples

  • examples/image_features.py - the catalogue, extraction and the ablation selections, for three cloud photographs.
  • examples/lm_from_scratch.py - trains, samples and scores a tiny character-level language model on a six-line corpus.
  • examples/lora_train.py - one LoRA job: the rows, the settings, the events and the adapter; --save DIR keeps it and --stop ends the run early.
  • examples/lora_generate.py - loads an adapter and compares the base model with it, text and perplexity both.
  • examples/lora_inspect.py - reads an adapter and summarises it: the base model, the rank and the blocks it reached, how many values it holds, how far the run got. Needs no MLX and no model.
  • examples/build_britllm_4bit.py - a maintainer script: downloads the fp16 source, converts it to 4-bit MLX, writes the model card and the manifest, and uploads it with --upload.
  • examples/lora_walkthrough.sh - runs the three LoRA scripts in order: bash examples/lora_walkthrough.sh.

The LoRA scripts run with the extra: uv run --extra lora python examples/lora_train.py.

License

MIT for the code in this repository.

Third-party material keeps its own terms: MNIST is MIT, the CCSN cloud database is CC0, downloaded text keeps its own licence, and the 4-bit BritLLM artifact keeps the source model's ODC-BY licence.

Metadata

Release files for edu-ai-suite 0.0.2

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

Source distribution (sdist)

Source distribution for edu-ai-suite 0.0.2
File Size Uploaded Provenance Actions
edu_ai_suite-0.0.2.tar.gz 341.2 kB Without provenance Details for edu_ai_suite-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for edu-ai-suite 0.0.2
File Interpreter ABI Platform Actions
edu_ai_suite-0.0.2-py3-none-any.whl Python 3 none any Details for edu_ai_suite-0.0.2-py3-none-any.whl

Total release size: 456.2 kB

Release files / edu_ai_suite-0.0.2.tar.gz

Download URL edu_ai_suite-0.0.2.tar.gz
Size 341.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fa7d7826189949ccfb122895b58e1bb06d61bce8108bb0a6a862104cb1637475
BLAKE2b-256 checksum
How to use checksums
479f9535668b977fc77b91404d09b0a405ecdd037b88ea9d9163355de26902b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / edu_ai_suite-0.0.2-py3-none-any.whl

Download URL edu_ai_suite-0.0.2-py3-none-any.whl
Size 115.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe8eace396e160bc40faf2edce71ce620db6830a169caf3c9b66a3d75648bc6f
BLAKE2b-256 checksum
How to use checksums
7d582189b67359e145f6dcf5d495d82ae3dd0c1a44257bf523713636c8347f02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for edu-ai-suite 0.0.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

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