# bonbhel/kabena-ml architecture

> Architecture diagram of the GitHub repository bonbhel/kabena-ml, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bonbhel/kabena-ml
- Repository: https://github.com/bonbhel/kabena-ml

## Overview

K-ABENA is a Python library that reduces training computation by selecting examples from each batch or epoch and returning weights that compensate for selected examples. The principal workflow is: a training loop supplies per-example losses to `Kabena.select()`, which configures and resolves a selection strategy, samples active examples, and returns a mask and weights for the caller’s training update. Framework adapters expose this behavior for PyTorch, Keras, scikit-learn, and Hugging Face. The README also documents scripts for reproducing the preprint’s validation tables. Adapter wiring is based on the README and SOURCE INDEX references; unsampled implementations are not inferred beyond those references.

Main entry points: [`kabena/core/filter.py`](https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/filter.py) (Kabena selector), [`kabena/integrations/torch.py`](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/torch.py) (PyTorch adapter), [`kabena/integrations/keras.py`](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/keras.py) (Keras adapter), [`kabena/integrations/sklearn.py`](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/sklearn.py) (scikit-learn adapter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_selection["Selection core"]
  node_selector["Kabena selector<br/>[filter.py]"]
  node_configuration["Selection config<br/>[config.py]"]
  node_strategy_gate["Strategy gate<br/>[gate.py]"]
  node_sampling["Sampling strategies<br/>[sampling.py]"]
end

subgraph group_adapters["Framework adapters"]
  node_torch_adapter["PyTorch adapter<br/>[torch.py]"]
  node_keras_adapter["Keras adapter<br/>[keras.py]"]
  node_sklearn_adapter["scikit-learn adapter<br/>[sklearn.py]"]
  node_hf_adapter["Hugging Face adapter<br/>[huggingface.py]"]
end

subgraph group_validation["Validation scripts"]
  node_validation_scripts["Preprint validation"]
end

node_trainer(("Training loop"))
node_training_update["Training update"]

node_trainer -->|"supplies losses"| node_selector
node_selector -->|"creates config"| node_configuration
node_selector -->|"resolves strategy"| node_strategy_gate
node_selector -->|"selects examples"| node_sampling
node_selector -->|"returns mask and weights"| node_training_update
node_trainer -->|"fits selected data"| node_training_update
node_torch_adapter -->|"delegates selection"| node_selector
node_keras_adapter -->|"uses core API"| node_selector
node_sklearn_adapter -->|"uses core API"| node_selector
node_hf_adapter -->|"uses adapter"| node_torch_adapter
node_trainer -->|"runs table scripts"| node_validation_scripts

click node_selector "https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/filter.py"
click node_configuration "https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/config.py"
click node_strategy_gate "https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/gate.py"
click node_sampling "https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/sampling.py"
click node_torch_adapter "https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/torch.py"
click node_keras_adapter "https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/keras.py"
click node_sklearn_adapter "https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/sklearn.py"
click node_hf_adapter "https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/huggingface.py"
click node_validation_scripts "https://github.com/bonbhel/kabena-ml/tree/main/validation"

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_selector,node_configuration,node_strategy_gate,node_sampling toneBlue
class node_torch_adapter,node_keras_adapter,node_sklearn_adapter,node_hf_adapter toneAmber
class node_validation_scripts toneMint
class node_trainer,node_training_update toneIndigo
```

## Components

### Selection core

- [Kabena selector](https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/filter.py): `kabena/core/filter.py`
- [Selection config](https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/config.py): `kabena/core/config.py`
- [Strategy gate](https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/gate.py): `kabena/core/gate.py`
- [Sampling strategies](https://github.com/bonbhel/kabena-ml/blob/main/kabena/core/sampling.py): `kabena/core/sampling.py`

### Framework adapters

- [PyTorch adapter](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/torch.py): `kabena/integrations/torch.py`
- [Keras adapter](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/keras.py): `kabena/integrations/keras.py`
- [scikit-learn adapter](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/sklearn.py): `kabena/integrations/sklearn.py`
- [Hugging Face adapter](https://github.com/bonbhel/kabena-ml/blob/main/kabena/integrations/huggingface.py): `kabena/integrations/huggingface.py`

### Validation scripts

- [Preprint validation](https://github.com/bonbhel/kabena-ml/tree/main/validation): `validation`

### Other components

- **Training loop**
- **Training update**

## Connections

- Training loop → Kabena selector: supplies losses (evidence: `README.md`)
- Kabena selector → Selection config: creates config (evidence: `kabena/core/filter.py`)
- Kabena selector → Strategy gate: resolves strategy (evidence: `kabena/core/filter.py`)
- Kabena selector → Sampling strategies: selects examples (evidence: `kabena/core/filter.py`)
- Kabena selector → Training update: returns mask and weights (evidence: `README.md`)
- Training loop → Training update: fits selected data (evidence: `README.md`)
- PyTorch adapter → Kabena selector: delegates selection (evidence: `kabena/integrations/torch.py`)
- Keras adapter → Kabena selector: uses core API (evidence: `kabena/integrations/keras.py`)
- scikit-learn adapter → Kabena selector: uses core API (evidence: `kabena/integrations/sklearn.py`)
- Hugging Face adapter → PyTorch adapter: uses adapter (evidence: `kabena/integrations/huggingface.py`)
- Training loop → Preprint validation: runs table scripts (evidence: `README.md`)
