# abdouaziz/sbert architecture

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

- Interactive diagram: https://gitdiagram.com/abdouaziz/sbert
- Repository: https://github.com/abdouaziz/sbert

## Overview

This is a command-line Sentence-BERT similarity-training application: it reads labeled sentence pairs, prepares tokenized batches, trains a BERT-based pair classifier, and evaluates it on a held-out split. The sampled code places the workflow in one module, so components share its exact path. The README describes semantic sentence embeddings and cosine similarity, but the sampled implementation excerpt shows a pooled-pair classifier; inference or a separate embedding-export workflow is not evidenced.

Main entry points: [`src/sbert.py`](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py) (CLI workflow), [`input/train.csv`](https://github.com/abdouaziz/sbert/blob/master/input/train.csv) (Pair CSV)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Pair preparation"]
  node_csv["Pair CSV<br/>[train.csv]"]
  node_arguments["Run arguments<br/>[sbert.py]"]
  node_split["Train-test split<br/>[sbert.py]"]
  node_loader["Similarity loader<br/>[sbert.py]"]
  node_dataset["Pair dataset<br/>[sbert.py]"]
  node_tokenizer["BERT tokenizer<br/>[sbert.py]"]
end

subgraph group_model["Similarity model"]
  node_pairmodel["Pair similarity model<br/>[sbert.py]"]
  node_pooling["Pooling and classifier<br/>[sbert.py]"]
end

subgraph group_training["Training and evaluation"]
  node_loss["Binary loss<br/>[sbert.py]"]
  node_optimizer["AdamW optimizer<br/>[sbert.py]"]
  node_scheduler["Learning-rate scheduler<br/>[sbert.py]"]
  node_train["Training epoch<br/>[sbert.py]"]
  node_evaluate["Validation epoch<br/>[sbert.py]"]
  node_metrics["Accuracy and loss<br/>[sbert.py]"]
  node_main["CLI workflow<br/>[sbert.py]"]
end

node_user(("CLI user"))
node_pretrained["Pretrained BERT"]

node_user -->|"runs"| node_main
node_main -->|"parses"| node_arguments
node_main -->|"reads"| node_csv
node_main -->|"splits"| node_split
node_main -->|"builds loaders"| node_loader
node_loader -->|"creates"| node_dataset
node_dataset -->|"tokenizes pairs"| node_tokenizer
node_main -->|"loads"| node_tokenizer
node_main -->|"creates"| node_pairmodel
node_pairmodel -.->|"loads BERT"| node_pretrained
node_pairmodel -->|"uses"| node_pooling
node_main -->|"creates"| node_optimizer
node_main -->|"creates"| node_scheduler
node_main -->|"runs epochs"| node_train
node_main -->|"evaluates split"| node_evaluate
node_train -->|"scores batches"| node_pairmodel
node_evaluate -->|"scores batches"| node_pairmodel
node_train -->|"computes loss"| node_loss
node_evaluate -->|"computes loss"| node_loss
node_train -->|"updates weights"| node_optimizer
node_train -->|"steps schedule"| node_scheduler
node_train -->|"returns metrics"| node_metrics
node_evaluate -->|"returns metrics"| node_metrics

click node_csv "https://github.com/abdouaziz/sbert/blob/master/input/train.csv"
click node_arguments "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_split "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_loader "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_dataset "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_tokenizer "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_pairmodel "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_pooling "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_loss "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_optimizer "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_scheduler "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_train "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_evaluate "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_metrics "https://github.com/abdouaziz/sbert/blob/master/src/sbert.py"
click node_main "https://github.com/abdouaziz/sbert/blob/master/src/sbert.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_csv,node_arguments,node_split,node_loader,node_dataset,node_tokenizer,node_user toneBlue
class node_pairmodel,node_pooling toneAmber
class node_loss,node_optimizer,node_scheduler,node_train,node_evaluate,node_metrics,node_main toneMint
class node_pretrained toneIndigo
```

## Components

### Pair preparation

- [Pair CSV](https://github.com/abdouaziz/sbert/blob/master/input/train.csv): `input/train.csv`
- [Run arguments](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Train-test split](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Similarity loader](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Pair dataset](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [BERT tokenizer](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`

### Similarity model

- [Pair similarity model](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Pooling and classifier](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`

### Training and evaluation

- [Binary loss](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [AdamW optimizer](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Learning-rate scheduler](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Training epoch](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Validation epoch](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [Accuracy and loss](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`
- [CLI workflow](https://github.com/abdouaziz/sbert/blob/master/src/sbert.py): `src/sbert.py`

### Other components

- **CLI user**
- **Pretrained BERT**

## Connections

- CLI user → CLI workflow: runs
- CLI workflow → Run arguments: parses
- CLI workflow → Pair CSV: reads
- CLI workflow → Train-test split: splits
- CLI workflow → Similarity loader: builds loaders
- Similarity loader → Pair dataset: creates
- Pair dataset → BERT tokenizer: tokenizes pairs
- CLI workflow → BERT tokenizer: loads
- CLI workflow → Pair similarity model: creates
- Pair similarity model → Pretrained BERT: loads BERT
- Pair similarity model → Pooling and classifier: uses
- CLI workflow → AdamW optimizer: creates
- CLI workflow → Learning-rate scheduler: creates
- CLI workflow → Training epoch: runs epochs
- CLI workflow → Validation epoch: evaluates split
- Training epoch → Pair similarity model: scores batches
- Validation epoch → Pair similarity model: scores batches
- Training epoch → Binary loss: computes loss
- Validation epoch → Binary loss: computes loss
- Training epoch → AdamW optimizer: updates weights
- Training epoch → Learning-rate scheduler: steps schedule
- Training epoch → Accuracy and loss: returns metrics
- Validation epoch → Accuracy and loss: returns metrics
