# csebuetnlp/banglanmt architecture

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

- Interactive diagram: https://gitdiagram.com/csebuetnlp/banglanmt
- Repository: https://github.com/csebuetnlp/banglanmt

## Overview

##### Main Components
A. Data Sources
- Raw parallel corpora (2.75M Bengali-English pairs)
- RisingNews dev/test and SIPC dev/test sets
- SentencePiece vocab models (Bengali & English)
B. Segmentation Module (`segmentation/`)
- Custom segmenter (`segmenter.py`)
- Builds sentence boundaries for Bengali text
C. Batch-Filtering Module (`batch_filtering/`)
- Installs external tools & models (`install_*.sh`)
- Scoring pipeline (`scoring_pipeline.py`)
- Bitext mining (`mine_bitexts.py`) & embedding/indexing libs
- Cleans and filters noisy sentence pairs
D. Training & Evaluation Module (`training/`)
- Preprocessing (`training/preprocessing/preprocessor.py`, remove_evaluation_pairs.py)
- Seq2Seq pipeline (OpenNMT-py wrapper `pipeline.py`, dataProcessor, BLEU script)
- Sample directories illustrating data format
E. External Dependencies
- Python 3.7.3, PyTorch 1.2, OpenNMT-py 2.2.0
- Faiss, FastBPE, SentencePiece CLI, transliterate, regex, torchtext, sacrebleu, aksharamukha

##### Relationships & Data Flow
1. Raw Data → Segmentation
- Raw corpora fed into the segmenter → segmented corpora
2. Segmented Corpora → Batch-Filtering
- Invoke external tools (FastBPE, Faiss) → compute embedding scores → filter noisy pairs
- Output: high-quality parallel corpus
3. Filtered Corpus → Preprocessing
- Normalize, apply SentencePiece, remove dev/test overlaps
4. Preprocessed Data → Seq2Seq Training
- OpenNMT-py training script → model checkpoints
5. Model Checkpoints → Inference & Evaluation
- Colab notebook / local inference module → sacrebleu evaluation

##### Architectural Patterns
- Pipeline pattern (linear data transformation)
- Modularity: segmentation, filtering, preprocessing, training are separate stages
- Reuse of external tool wrappers (FastBPE, Faiss)
- Configurable scripts (install scripts, requirements.txt)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: Raw Data & Vocab
    subgraph "Layer 1: Raw Data & Vocab"
        RDC["Raw Parallel Corpora (2.75M pairs)"]:::data
        VTM["vocab.tar.bz2"]:::data
        RN1["RisingNews.test.bn"]:::data
        RN2["RisingNews.test.en"]:::data
        RN3["RisingNews.valid.bn"]:::data
        RN4["RisingNews.valid.en"]:::data
        SP_bn["bn.model"]:::data
        SP_en["en.model"]:::data
    end

    %% Layer 2: Segmentation
    subgraph "Layer 2: Segmentation Module"
        SEG["Segmenter"]:::compute
        SI["segmentation/__init__.py"]:::utility
        SS["segmentation/setup.py"]:::utility
        SR["segmentation/README.md"]:::utility
    end

    %% Layer 2b: Batch-Filtering
    subgraph "Layer 2: Batch-Filtering Module"
        IE["install_external_tools.sh"]:::utility
        IM["install_models.sh"]:::utility
        SPipe["scoring_pipeline.py"]:::compute
        MB["mine_bitexts.py"]:::compute
        EMB["embed.py"]:::compute
        IDX["indexing.py"]:::compute
        RLC["romanize_lc.py"]:::compute
        TP["text_processing.py"]:::compute
    end

    %% Layer 3: Preprocessing & Training
    subgraph "Layer 3: Preprocessing"
        PRE["preprocessor.py"]:::compute
        REP["remove_evaluation_pairs.py"]:::compute
        RPAT["replacePatterns.txt"]:::utility
        PRD["README.md"]:::utility
    end

    subgraph "Layer 3: Seq2Seq Pipeline & Evaluation"
        PIPE["pipeline.py"]:::compute
        DP["dataProcessor.py"]:::utility
        MBLEU["multi-bleu-detok.perl"]:::utility
        REQS["requirements.txt"]:::utility
        GITI[".gitignore"]:::utility
        SAMPLE["sample_input_dir"]:::data
    end

    %% Layer 4: Model Artifacts & Evaluation
    subgraph "Layer 4: Model Artifacts & Evaluation"
        CKPT["Model Checkpoints"]:::data
        EVAL["Evaluator (sacrebleu)"]:::compute
    end

    %% External Dependencies
    subgraph "External Tools & Libraries"
        PY["Python 3.7.3"]:::external
        PT["PyTorch 1.2"]:::external
        ONMT["OpenNMT-py 2.2.0"]:::external
        FBPE["FastBPE"]:::external
        FAISS["Faiss"]:::external
        SPC["SentencePiece CLI"]:::external
        REGX["regex"]:::external
        TORCHT["torchtext"]:::external
        SAC["sacrebleu"]:::external
    end

    %% Data Flow Arrows
    RDC -->|feeds into| SEG
    RN1 --> SEG
    RN2 --> SEG
    RN3 --> SEG
    RN4 --> SEG
    SEG -->|"segmented corpora"| SPipe
    SP_bn --> PRE
    SP_en --> PRE
    VTM --> PRE
    SPipe --> MB
    MB --> EMB
    EMB --> IDX
    IDX --> TP
    TP --> PRE
    PRE --> PIPE
    PIPE --> CKPT
    CKPT --> EVAL

    %% Dotted control arrows
    IE -.-> SPipe
    IM -.-> SPipe

    %% Click Events
    click VTM "https://github.com/csebuetnlp/banglanmt/blob/master/vocab.tar.bz2"
    click RN1 "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/sample_input_dir/data/RisingNews.test.bn"
    click RN2 "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/sample_input_dir/data/RisingNews.test.en"
    click RN3 "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/sample_input_dir/data/RisingNews.valid.bn"
    click RN4 "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/sample_input_dir/data/RisingNews.valid.en"
    click SP_bn "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/sample_input_dir/vocab/bn.model"
    click SP_en "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/sample_input_dir/vocab/en.model"
    click SEG "https://github.com/csebuetnlp/banglanmt/blob/master/segmentation/segmenter.py"
    click SI "https://github.com/csebuetnlp/banglanmt/blob/master/segmentation/__init__.py"
    click SS "https://github.com/csebuetnlp/banglanmt/blob/master/segmentation/setup.py"
    click SR "https://github.com/csebuetnlp/banglanmt/blob/master/segmentation/README.md"
    click IE "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/install_external_tools.sh"
    click IM "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/install_models.sh"
    click SPipe "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/scoring_pipeline.py"
    click MB "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/source/mine_bitexts.py"
    click EMB "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/source/embed.py"
    click IDX "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/source/lib/indexing.py"
    click RLC "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/source/lib/romanize_lc.py"
    click TP "https://github.com/csebuetnlp/banglanmt/blob/master/batch_filtering/source/lib/text_processing.py"
    click PRE "https://github.com/csebuetnlp/banglanmt/blob/master/training/preprocessing/preprocessor.py"
    click REP "https://github.com/csebuetnlp/banglanmt/blob/master/training/preprocessing/remove_evaluation_pairs.py"
    click RPAT "https://github.com/csebuetnlp/banglanmt/blob/master/training/preprocessing/replacePatterns.txt"
    click PRD "https://github.com/csebuetnlp/banglanmt/blob/master/training/preprocessing/README.md"
    click PIPE "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/pipeline.py"
    click DP "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/dataProcessor.py"
    click MBLEU "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/multi-bleu-detok.perl"
    click REQS "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/requirements.txt"
    click GITI "https://github.com/csebuetnlp/banglanmt/blob/master/training/seq2seq/.gitignore"
    click SAMPLE "https://github.com/csebuetnlp/banglanmt/tree/master/training/seq2seq/sample_input_dir"

    %% Styles
    classDef data fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1
    classDef compute fill:#E8F5E9,stroke:#A5D6A7,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#FFCC80,color:#E65100
    classDef utility fill:#ECEFF1,stroke:#B0BEC5,color:#455A64
```
