# yeyupiaoling/masr architecture

> Architecture diagram of the GitHub repository yeyupiaoling/masr, 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/yeyupiaoling/masr
- Repository: https://github.com/yeyupiaoling/masr

## Overview

MASR is a PyTorch speech-recognition framework supporting model training and evaluation, plus offline, long-audio, streaming, diarization-oriented, GUI, and server inference. The central workflow prepares audio and text into features and tokens, trains or loads an acoustic model, decodes its output, and returns recognized text. The graph includes documented capabilities whose detailed wiring is not visible in the sampled excerpts; those links are omitted where callers cannot be verified.

Main entry points: [`masr/trainer.py`](https://github.com/yeyupiaoling/masr/blob/develop/masr/trainer.py) (Training and evaluation), [`masr/data_utils/reader.py`](https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/reader.py) (Dataset reader), [`masr/infer_utils/inference_predictor.py`](https://github.com/yeyupiaoling/masr/blob/develop/masr/infer_utils/inference_predictor.py) (Inference predictor), [`infer_path.py`](https://github.com/yeyupiaoling/masr/blob/develop/infer_path.py) (Path inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_datasets["Dataset preparation"]
  node_manifest["Audio manifests<br/>[create_data.py]"]
  node_reader["Dataset reader<br/>[reader.py]"]
  node_features["Feature extraction"]
  node_tokens["Text tokenization<br/>[tokenizer.py]"]
  node_batch["Batch preparation<br/>[collate_fn.py]"]
end

subgraph group_learning["Model learning"]
  node_trainer["Training and evaluation<br/>[trainer.py]"]
  node_train_entry["Training entry<br/>[train.py]"]
  node_model_families["Acoustic model families"]
  node_losses["Training losses"]
  node_checkpoints[("Model checkpoints<br/>[checkpoint.py]")]
  node_evaluation["Recognition metrics<br/>[eval.py]"]
  node_export["Model export<br/>[export_model.py]"]
end

subgraph group_recognition["Recognition runtime"]
  node_predictor["Inference predictor"]
  node_decoders["CTC and attention decoders"]
  node_beam_lm["Beam search language model"]
  node_punctuation["Punctuation prediction<br/>[punc_predictor.py]"]
end

subgraph group_delivery["Inference interfaces"]
  node_offline["Path inference<br/>[infer_path.py]"]
  node_streaming["Streaming inference<br/>[infer_sd_asr.py]"]
  node_server["Inference server<br/>[infer_server.py]"]
  node_gui["GUI inference<br/>[infer_gui.py]"]
end

node_user(("Audio user"))
node_browser(("Browser recorder<br/>[record.js]"))
node_text["Recognized text"]

node_user -->|"provides audio"| node_offline
node_user -->|"provides audio"| node_streaming
node_user -->|"provides audio"| node_gui
node_datasets -->|"writes manifests"| node_manifest
node_manifest -->|"supplies examples"| node_reader
node_reader -->|"extracts features"| node_features
node_reader -->|"encodes transcripts"| node_tokens
node_reader -->|"provides samples"| node_batch
node_train_entry -->|"starts training"| node_trainer
node_trainer -->|"builds datasets"| node_reader
node_trainer -->|"batches samples"| node_batch
node_trainer -->|"constructs model"| node_model_families
node_trainer -->|"computes loss"| node_losses
node_trainer -->|"saves and loads"| node_checkpoints
node_evaluation -->|"evaluates model"| node_trainer
node_export -->|"exports model"| node_model_families
node_offline -->|"runs inference"| node_predictor
node_streaming -->|"runs chunks"| node_predictor
node_gui -->|"runs inference"| node_predictor
node_server -->|"runs inference"| node_predictor
node_browser -->|"sends audio"| node_server
node_predictor -->|"decodes probabilities"| node_decoders
node_decoders -.->|"scores hypotheses"| node_beam_lm
node_offline -.->|"adds punctuation"| node_punctuation
node_server -.->|"adds punctuation"| node_punctuation
node_offline -->|"returns transcript"| node_text
node_streaming -->|"returns transcript"| node_text
node_gui -->|"displays transcript"| node_text
node_server -->|"returns transcript"| node_text

click node_datasets "https://github.com/yeyupiaoling/masr/tree/develop/download_data"
click node_manifest "https://github.com/yeyupiaoling/masr/blob/develop/create_data.py"
click node_reader "https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/reader.py"
click node_features "https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/audio_featurizer.py"
click node_tokens "https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/tokenizer.py"
click node_batch "https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/collate_fn.py"
click node_trainer "https://github.com/yeyupiaoling/masr/blob/develop/masr/trainer.py"
click node_train_entry "https://github.com/yeyupiaoling/masr/blob/develop/train.py"
click node_model_families "https://github.com/yeyupiaoling/masr/tree/develop/masr/model_utils"
click node_losses "https://github.com/yeyupiaoling/masr/tree/develop/masr/model_utils/loss"
click node_checkpoints "https://github.com/yeyupiaoling/masr/blob/develop/masr/utils/checkpoint.py"
click node_evaluation "https://github.com/yeyupiaoling/masr/blob/develop/eval.py"
click node_predictor "https://github.com/yeyupiaoling/masr/blob/develop/masr/infer_utils/inference_predictor.py"
click node_decoders "https://github.com/yeyupiaoling/masr/tree/develop/masr/decoders"
click node_beam_lm "https://github.com/yeyupiaoling/masr/blob/develop/masr/decoders/beam_search_decoder.py"
click node_punctuation "https://github.com/yeyupiaoling/masr/blob/develop/masr/infer_utils/punc_predictor.py"
click node_offline "https://github.com/yeyupiaoling/masr/blob/develop/infer_path.py"
click node_streaming "https://github.com/yeyupiaoling/masr/blob/develop/infer_sd_asr.py"
click node_server "https://github.com/yeyupiaoling/masr/blob/develop/infer_server.py"
click node_gui "https://github.com/yeyupiaoling/masr/blob/develop/infer_gui.py"
click node_browser "https://github.com/yeyupiaoling/masr/blob/develop/static/record.js"
click node_export "https://github.com/yeyupiaoling/masr/blob/develop/export_model.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_datasets,node_manifest,node_reader,node_features,node_tokens,node_batch,node_user,node_browser toneBlue
class node_trainer,node_train_entry,node_model_families,node_losses,node_checkpoints,node_evaluation,node_export toneAmber
class node_predictor,node_decoders,node_beam_lm,node_punctuation toneMint
class node_offline,node_streaming,node_server,node_gui toneRose
class node_text toneIndigo
```

## Components

### Data preparation

- [Dataset preparation](https://github.com/yeyupiaoling/masr/tree/develop/download_data): `download_data`
- [Audio manifests](https://github.com/yeyupiaoling/masr/blob/develop/create_data.py): `create_data.py`
- [Dataset reader](https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/reader.py): `masr/data_utils/reader.py`
- [Feature extraction](https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/audio_featurizer.py): `masr/data_utils/audio_featurizer.py`
- [Text tokenization](https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/tokenizer.py): `masr/data_utils/tokenizer.py`
- [Batch preparation](https://github.com/yeyupiaoling/masr/blob/develop/masr/data_utils/collate_fn.py): `masr/data_utils/collate_fn.py`

### Model learning

- [Training and evaluation](https://github.com/yeyupiaoling/masr/blob/develop/masr/trainer.py): `masr/trainer.py`
- [Training entry](https://github.com/yeyupiaoling/masr/blob/develop/train.py): `train.py`
- [Acoustic model families](https://github.com/yeyupiaoling/masr/tree/develop/masr/model_utils): `masr/model_utils`
- [Training losses](https://github.com/yeyupiaoling/masr/tree/develop/masr/model_utils/loss): `masr/model_utils/loss`
- [Model checkpoints](https://github.com/yeyupiaoling/masr/blob/develop/masr/utils/checkpoint.py): `masr/utils/checkpoint.py`
- [Recognition metrics](https://github.com/yeyupiaoling/masr/blob/develop/eval.py): `eval.py`
- [Model export](https://github.com/yeyupiaoling/masr/blob/develop/export_model.py): `export_model.py`

### Recognition runtime

- [Inference predictor](https://github.com/yeyupiaoling/masr/blob/develop/masr/infer_utils/inference_predictor.py): `masr/infer_utils/inference_predictor.py`
- [CTC and attention decoders](https://github.com/yeyupiaoling/masr/tree/develop/masr/decoders): `masr/decoders`
- [Beam search language model](https://github.com/yeyupiaoling/masr/blob/develop/masr/decoders/beam_search_decoder.py): `masr/decoders/beam_search_decoder.py`
- [Punctuation prediction](https://github.com/yeyupiaoling/masr/blob/develop/masr/infer_utils/punc_predictor.py): `masr/infer_utils/punc_predictor.py`

### Inference interfaces

- [Path inference](https://github.com/yeyupiaoling/masr/blob/develop/infer_path.py): `infer_path.py`
- [Streaming inference](https://github.com/yeyupiaoling/masr/blob/develop/infer_sd_asr.py): `infer_sd_asr.py`
- [Inference server](https://github.com/yeyupiaoling/masr/blob/develop/infer_server.py): `infer_server.py`
- [GUI inference](https://github.com/yeyupiaoling/masr/blob/develop/infer_gui.py): `infer_gui.py`

### Other components

- **Audio user**
- [Browser recorder](https://github.com/yeyupiaoling/masr/blob/develop/static/record.js): `static/record.js`
- **Recognized text**

## Connections

- Audio user → Path inference: provides audio
- Audio user → Streaming inference: provides audio
- Audio user → GUI inference: provides audio
- Dataset preparation → Audio manifests: writes manifests
- Audio manifests → Dataset reader: supplies examples
- Dataset reader → Feature extraction: extracts features
- Dataset reader → Text tokenization: encodes transcripts
- Dataset reader → Batch preparation: provides samples
- Training entry → Training and evaluation: starts training
- Training and evaluation → Dataset reader: builds datasets
- Training and evaluation → Batch preparation: batches samples
- Training and evaluation → Acoustic model families: constructs model
- Training and evaluation → Training losses: computes loss
- Training and evaluation → Model checkpoints: saves and loads
- Recognition metrics → Training and evaluation: evaluates model
- Model export → Acoustic model families: exports model
- Path inference → Inference predictor: runs inference
- Streaming inference → Inference predictor: runs chunks
- GUI inference → Inference predictor: runs inference
- Inference server → Inference predictor: runs inference
- Browser recorder → Inference server: sends audio
- Inference predictor → CTC and attention decoders: decodes probabilities
- CTC and attention decoders → Beam search language model: scores hypotheses
- Path inference → Punctuation prediction: adds punctuation
- Inference server → Punctuation prediction: adds punctuation
- Path inference → Recognized text: returns transcript
- Streaming inference → Recognized text: returns transcript
- GUI inference → Recognized text: displays transcript
- Inference server → Recognized text: returns transcript
