Live demo · Transaction sequence model

Learn the habit.
Catch the break.

A small transformer reads each customer's card transactions in order, predicts the next one, and scores every transaction for fraud. It is trained with PyTorch in a Chalk training run on a GPU, then served from a CPU replica.

Score a customer it has never seen

Pick a scenario and the demo generates a fresh synthetic customer, then shows the model's fraud score, how surprising each transaction was, and what it expected to come next. Rows the generator labelled as fraud have a coral edge, so you can check the model's work.

349k-param transformerOpen in new tab

How it works

A single transaction rarely gives fraud away. A $2.99 app purchase is ordinary until three more follow within minutes and a $900 gift card comes next. Sequence models see the pattern because they read the history, not the row.

Tokenize

Each transaction becomes five tokens: category, amount bucket, channel, hour of day, and time since the previous one. Their embeddings sum into one vector per transaction.

Attend to history

A causal transformer reads a customer's transactions in order, so its view of transaction t only includes what came before. That is the same constraint a live fraud check has.

Forecast and flag

Next-action heads predict the next transaction, trained on every customer with no labels. A fraud head scores each transaction, trained on the labelled bursts.

The data is synthetic: customers with spending personas, about 12% of them hit by card testing, an account takeover, or an ATM drain, plus legitimate look-alikes of each so the model cannot shortcut on a single transaction.

Getting started

Train your own in three commands

Clone the example, log in, and run the training script. It uploads the data as a Chalk dataset, runs PyTorch on an L4, and prints the metrics for every epoch. A second script serves the trained weights behind this exact demo.

The model is deliberately small and the data is synthetic. The workflow is the part that carries over: dataset in, training run on a GPU, weights on a volume, a replica that serves them.

chalk-ai/transaction-sequence-model
git clone https://github.com/chalk-ai/transaction-sequence-model
cd transaction-sequence-model

# Or export CHALK_CLIENT_ID and CHALK_CLIENT_SECRET.
chalk login

# Generate 20k customers, upload them as a dataset, and train on an L4.
./train.py

# Serve the trained weights behind the page you see above.
./deploy.py

What Chalk handles

The model is the interesting part. Everything around it is the part Chalk does for you.

Datasets in, data frames out

DatasetClient.upload turns a dict of columns into a versioned Chalk dataset. The training run receives its latest revision as a Polars frame.

Training runs on GPUs

chalkcompute.training(gpu="nvidia-l4") builds the image, schedules the run, streams its status, and records it alongside your other runs.

Measured, not promised

On one L4, eight epochs over about 960k transactions take 25 seconds. Fraud average precision on held-out customers reaches 0.85 against a 0.8% base rate.

Weights on a volume

The run writes model.pt to a Chalk volume. The serving replica reads it at startup with its own workload identity, so no API key ships in the image.

Cheap to serve

The trained model has 349k parameters. A CPU replica scores a 40-transaction history in about 3 ms, no GPU needed.

Open source

The data generator, model, training script, and serving app are Apache-2.0 on GitHub. Swap in your own transactions and labels.

Train on your own transactions

Fraud, credit risk, and next-best-action all start from sequences. Talk to an engineer about training and serving sequence models on GPUs in your cloud.