# nvidia-ai-blueprints/transaction-foundation-model architecture

> Architecture diagram of the GitHub repository nvidia-ai-blueprints/transaction-foundation-model, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nvidia-ai-blueprints/transaction-foundation-model
- Repository: https://github.com/nvidia-ai-blueprints/transaction-foundation-model

## Overview

1. **Repository purpose and shape**  
   This is a notebook-driven ML research/example repo for building a **transaction foundation model**. The architecture is a pipeline: raw financial transaction tables are converted into token sequences, used to pretrain a decoder-only model, then repurposed as embeddings for fraud detection and visualization.

2. **Primary execution entrypoints**  
   The main user-facing flow lives in the five notebooks at the repo root. They are intended to be run in order:
   - dataset baseline
   - tokenizer construction
   - foundation-model training
   - embedding extraction / visualization
   - downstream fraud classification  
   The notebooks are the orchestration layer; the `src/` and `scripts/` code provide reusable components underneath.

3. **Data ingestion and baseline branch**  
   `01_dataset_baseline.ipynb` loads the TabFormer financial transaction dataset, performs temporal train/validation/test splitting, and trains an **XGBoost** fraud baseline on raw/tabular features. This establishes the non-foundation-model comparison branch early in the pipeline.

4. **Tokenization subsystem**  
   `src/tokenizer/` is the main preprocessing subsystem. It is modular and schema-aware, with components for:
   - numerical fields
   - categorical hashing
   - fixed-vocabulary mappings
   - time-delta encoding
   - pipeline composition for financial records  
   The key architectural point is that heterogeneous transaction columns are transformed into a **domain-specific token vocabulary** rather than generic text tokens.

5. **GPU-accelerated preprocessing boundary**  
   The README makes it clear that tokenization is designed to run with **NVIDIA RAPIDS / cuDF / CuPy**. That means the preprocessing boundary is not just “Python data prep”; it is a GPU-oriented transformation stage that turns tabular rows into sequence model inputs at scale.

6. **Sequence modeling data prep**  
   `src/clm_data.py` sits between tokenized records and model training. Its role is to package the token sequences for **causal language modeling** so the decoder can learn next-token prediction over transaction histories rather than supervised fraud labels.

7. **Foundation model training subsystem**  
   `scripts/train_decoder_model.py` plus `configs/pretrain_financial_decoder.yaml` define the training path. The model is a **decoder-only transformer** trained with **NVIDIA NeMo AutoModel** using HuggingFace-compatible architecture settings. The README specifies the example uses a small Llama-style decoder, trained for causal LM on GPU.

8. **Checkpoint and artifact boundary**  
   The reusable pretrained checkpoint lives in `models/decoder-foundation-model/` and is tracked with **Git LFS**. This is a distinct artifact from the notebook demo training output (`models/decoder-demo/`), which is not the checkpoint used by later notebooks. That separation matters for the architecture: one path demonstrates training, another path consumes the shipped model artifact.

9. **Inference and embedding extraction**  
   `src/decoder_inference.py` loads the pretrained decoder and runs GPU inference. The downstream representation is produced by **last-token pooling**, yielding fixed-size embeddings (the README calls out 512-dimensional vectors). This is the bridge from sequence modeling to classical ML workflows.

10. **Downstream analytics branch**  
   `04_inference_embedding_extraction.ipynb` visualizes embeddings with UMAP, while `05_xgboost_fraud_detection.ipynb` evaluates fraud detection using:
   - raw features
   - foundation-model embeddings
   - combined features  
   This shows the intended reuse pattern: the foundation model is not the final predictor; it is a representation learner feeding classical ML.

11. **Runtime and infrastructure context**  
   The repo is designed to run inside the **NVIDIA NeMo Framework container** with CUDA-enabled GPUs. The notebooks expect the containerized environment and rely on inline-installed notebook dependencies. This is an offline research workflow, not a deployed service.

12. **What the architecture diagram should emphasize**  
   The clearest diagram would show two converging paths:
   - **tabular transactions → tokenizer → decoder pretraining → checkpoint → embeddings**
   - **raw tabular features → XGBoost baseline / downstream classifier**  
   The shared boundary is the dataset; the key reusable artifact is the pretrained decoder checkpoint; the main value-add is that learned embeddings improve fraud detection over hand-crafted features.

Main entry points: [`src/tokenizer/financial_tokenizer.py`](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/financial_tokenizer.py) (Financial tokenizer), [`scripts/train_decoder_model.py`](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/scripts/train_decoder_model.py) (Train script), [`02_seq_preproc_tokenization.ipynb`](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/02_seq_preproc_tokenization.ipynb) (Tokenization), [`04_inference_embedding_extraction.ipynb`](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/04_inference_embedding_extraction.ipynb) (Extract embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_notebooks["Notebook flow"]
  node_nb_dataset["Dataset baseline<br/>notebook orchestration"]
  node_nb_tokenize["Tokenization<br/>notebook orchestration"]
  node_nb_train["Train decoder<br/>notebook orchestration"]
  node_nb_embed["Extract embeddings<br/>notebook orchestration"]
  node_nb_fraud["Fraud eval<br/>notebook orchestration"]
end

subgraph group_preprocess["Tokenization"]
  node_tok_pipeline["Token pipeline<br/>tokenization pipeline<br/>[pipeline.py]"]
  node_tok_financial["Financial tokenizer<br/>tokenization core"]
  node_tok_fpipeline["Financial pipeline<br/>tokenization orchestration"]
  node_tok_numeric["Numeric tokens<br/>field encoder<br/>[numerical.py]"]
  node_tok_categorical["Category hashing<br/>field encoder"]
  node_tok_vocab["Fixed vocab<br/>field encoder<br/>[fixed_vocab.py]"]
  node_tok_timedelta["Time deltas<br/>field encoder<br/>[timedelta.py]"]
end

subgraph group_modeling["Modeling"]
  node_clm_data["CLM data<br/>sequence packing<br/>[clm_data.py]"]
  node_train_script["Train script<br/>training entrypoint"]
  node_train_cfg["Pretrain config<br/>training config"]
  node_decoder_infer["Decoder inference<br/>inference runtime"]
end

subgraph group_artifacts["Artifacts"]
  node_decoder_ckpt[("Decoder checkpoint<br/>trained artifact")]
end

subgraph group_downstream["Downstream"]
  node_embeddings(("Embeddings<br/>representation output"))
  node_xgboost_flow["Fraud model<br/>classical ML"]
end

node_nb_dataset -->|"dataset flow"| node_nb_tokenize
node_nb_tokenize -->|"uses"| node_tok_fpipeline
node_tok_fpipeline -->|"composes"| node_tok_pipeline
node_tok_pipeline -->|"drives"| node_tok_financial
node_tok_financial -->|"encodes"| node_tok_numeric
node_tok_financial -->|"encodes"| node_tok_categorical
node_tok_financial -->|"encodes"| node_tok_vocab
node_tok_financial -->|"encodes"| node_tok_timedelta
node_nb_tokenize -->|"prepares"| node_clm_data
node_nb_train -->|"launches"| node_train_script
node_nb_train -->|"configures"| node_train_cfg
node_train_script -->|"consumes"| node_clm_data
node_train_script -->|"produces"| node_decoder_ckpt
node_train_cfg -->|"sets"| node_train_script
node_decoder_ckpt -->|"loads"| node_nb_embed
node_nb_embed -->|"uses"| node_decoder_infer
node_decoder_infer -->|"outputs"| node_embeddings
node_embeddings -->|"feeds"| node_nb_fraud
node_nb_dataset -->|"baseline"| node_xgboost_flow
node_nb_fraud -->|"evaluates"| node_xgboost_flow
node_nb_embed -->|"hand off"| node_nb_fraud

click node_nb_dataset "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/01_dataset_baseline.ipynb"
click node_nb_tokenize "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/02_seq_preproc_tokenization.ipynb"
click node_nb_train "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/03_foundation_model_training.ipynb"
click node_nb_embed "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/04_inference_embedding_extraction.ipynb"
click node_nb_fraud "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/05_xgboost_fraud_detection.ipynb"
click node_tok_pipeline "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/pipeline.py"
click node_tok_financial "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/financial_tokenizer.py"
click node_tok_fpipeline "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/financial_pipeline.py"
click node_tok_numeric "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/numerical.py"
click node_tok_categorical "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/categorical_hash.py"
click node_tok_vocab "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/fixed_vocab.py"
click node_tok_timedelta "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/timedelta.py"
click node_clm_data "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/clm_data.py"
click node_train_script "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/scripts/train_decoder_model.py"
click node_train_cfg "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/configs/pretrain_financial_decoder.yaml"
click node_decoder_infer "https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/decoder_inference.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_nb_dataset,node_nb_tokenize,node_nb_train,node_nb_embed,node_nb_fraud toneBlue
class node_tok_pipeline,node_tok_financial,node_tok_fpipeline,node_tok_numeric,node_tok_categorical,node_tok_vocab,node_tok_timedelta toneAmber
class node_clm_data,node_train_script,node_train_cfg,node_decoder_infer toneMint
class node_decoder_ckpt toneRose
class node_embeddings,node_xgboost_flow toneIndigo
```

## Components

### Notebook flow

User-facing orchestration for dataset prep, training, inference, and evaluation.

- [Dataset baseline](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/01_dataset_baseline.ipynb): notebook orchestration · Loads transactions, performs temporal splits, and trains a raw-feature fraud baseline. · `01_dataset_baseline.ipynb`
- [Tokenization](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/02_seq_preproc_tokenization.ipynb): notebook orchestration · Drives schema-aware transaction tokenization and sequence preparation. · `02_seq_preproc_tokenization.ipynb`
- [Train decoder](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/03_foundation_model_training.ipynb): notebook orchestration · Launches foundation-model pretraining for the decoder-only transformer. · `03_foundation_model_training.ipynb`
- [Extract embeddings](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/04_inference_embedding_extraction.ipynb): notebook orchestration · Runs pretrained-model inference to produce embeddings and visualize them. · `04_inference_embedding_extraction.ipynb`
- [Fraud eval](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/05_xgboost_fraud_detection.ipynb): notebook orchestration · Compares raw features, embeddings, and combined features for fraud detection. · `05_xgboost_fraud_detection.ipynb`

### Tokenization

GPU-oriented preprocessing that converts transaction tables into domain tokens.

- [Token pipeline](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/pipeline.py): tokenization pipeline · Composes the column-wise transaction tokenization stages. · `src/tokenizer/pipeline.py`
- [Financial tokenizer](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/financial_tokenizer.py): tokenization core · Schema-aware tokenizer for heterogeneous financial records. · `src/tokenizer/financial_tokenizer.py`
- [Financial pipeline](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/financial_pipeline.py): tokenization orchestration · Higher-level preprocessing flow for financial transaction data. · `src/tokenizer/financial_pipeline.py`
- [Numeric tokens](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/numerical.py): field encoder · Encodes numerical transaction fields into token form. · `src/tokenizer/numerical.py`
- [Category hashing](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/categorical_hash.py): field encoder · Hashes categorical fields into a compact token space. · `src/tokenizer/categorical_hash.py`
- [Fixed vocab](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/fixed_vocab.py): field encoder · Maps selected fields to fixed vocabulary tokens. · `src/tokenizer/fixed_vocab.py`
- [Time deltas](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/tokenizer/timedelta.py): field encoder · Encodes temporal gaps between transactions. · `src/tokenizer/timedelta.py`

### Modeling

Causal language modeling training and inference for the decoder-only foundation model.

- [CLM data](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/clm_data.py): sequence packing · Packages tokenized transaction histories for causal language modeling. · `src/clm_data.py`
- [Train script](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/scripts/train_decoder_model.py): training entrypoint · Python entrypoint that launches decoder pretraining. · `scripts/train_decoder_model.py`
- [Pretrain config](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/configs/pretrain_financial_decoder.yaml): training config · Model and optimization settings for decoder pretraining. · `configs/pretrain_financial_decoder.yaml`
- [Decoder inference](https://github.com/nvidia-ai-blueprints/transaction-foundation-model/blob/main/src/decoder_inference.py): inference runtime · Loads the pretrained decoder and produces sequence representations. · `src/decoder_inference.py`

### Artifacts

Persisted pretrained checkpoint consumed by later notebooks.

- **Decoder checkpoint**: trained artifact · Persisted pretrained decoder model reused by inference and downstream analysis.

### Downstream

Embedding visualization and fraud classification on top of learned representations.

- **Embeddings**: representation output · Fixed-size last-token pooled vectors used for visualization and classifiers.
- **Fraud model**: classical ML · XGBoost fraud detection on raw, learned, and combined features.

## Connections

- Dataset baseline → Tokenization: dataset flow · Temporal split and baseline data preparation feed the tokenization stage.
- Tokenization → Financial pipeline: uses · Notebook orchestrates the financial tokenization pipeline.
- Financial pipeline → Token pipeline: composes · Higher-level financial preprocessing is built from the generic pipeline.
- Token pipeline → Financial tokenizer: drives · Pipeline applies the schema-aware financial tokenizer.
- Financial tokenizer → Numeric tokens: encodes · Numeric transaction columns are converted to tokens.
- Financial tokenizer → Category hashing: encodes · Categorical columns are hashed into token ids.
- Financial tokenizer → Fixed vocab: encodes · Selected fields are mapped through a fixed vocabulary.
- Financial tokenizer → Time deltas: encodes · Relative time gaps become temporal tokens.
- Tokenization → CLM data: prepares · Tokenized records are packed for causal language modeling.
- Train decoder → Train script: launches · Notebook delegates training to the script entrypoint.
- Train decoder → Pretrain config: configures · Training notebook uses the decoder pretraining configuration.
- Train script → CLM data: consumes · Training reads sequence-packed CLM data.
- Train script → Decoder checkpoint: produces · Pretraining writes the reusable decoder checkpoint artifact.
- Pretrain config → Train script: sets · Config specifies architecture and optimization settings.
- Decoder checkpoint → Extract embeddings: loads · Embedding extraction notebook consumes the pretrained checkpoint.
- Extract embeddings → Decoder inference: uses · Notebook runs the inference runtime for pooled representations.
- Decoder inference → Embeddings: outputs · Inference produces fixed-size transaction embeddings.
- Embeddings → Fraud eval: feeds · Learned representations are evaluated in downstream fraud analysis.
- Dataset baseline → Fraud model: baseline · Raw transaction features support the initial fraud baseline.
- Fraud eval → Fraud model: evaluates · Classifier compares raw, embedding, and combined feature sets.
- Extract embeddings → Fraud eval: hand off · Embedding extraction results are reused by fraud evaluation.
