# cffan/neural_seq_decoder architecture

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

- Interactive diagram: https://gitdiagram.com/cffan/neural_seq_decoder
- Repository: https://github.com/cffan/neural_seq_decoder

## Overview

This repository implements a PyTorch neural sequence decoder for speech BCI. The main workflow is to format competition data, train a GRU-based decoder on neural features and phoneme targets, then decode competition data and optionally rescore hypotheses with language models. The core runtime covers dataset preparation, neural-network inference, and training/evaluation. The README documents preprocessing and training; the sampled evaluation script shows language-model decoding. The preprocessing notebook and configuration contents were not sampled, so those links reflect README-level evidence only.

Main entry points: [`src/neural_decoder/neural_decoder_trainer.py`](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/neural_decoder_trainer.py) (Training loop), [`scripts/eval_competition.py`](https://github.com/cffan/neural_seq_decoder/blob/master/scripts/eval_competition.py) (Competition evaluation), [`notebooks/formatCompetitionData.ipynb`](https://github.com/cffan/neural_seq_decoder/blob/master/notebooks/formatCompetitionData.ipynb) (Competition formatter), [`src/neural_decoder/model.py`](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/model.py) (GRU decoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_formatter["Competition formatter"]
  node_prepared_data[("Formatted dataset")]
  node_speech_dataset["Speech dataset<br/>[dataset.py]"]
end

subgraph group_decoder["Decoder runtime"]
  node_augmentations["Signal augmentations<br/>[augmentations.py]"]
  node_gru_decoder["GRU decoder<br/>[model.py]"]
end

subgraph group_training["Training"]
  node_train_entry["Training entry<br/>[train_model.py]"]
  node_trainer["Training loop"]
  node_training_outputs[("Weights and metrics")]
end

subgraph group_evaluation["Evaluation"]
  node_competition_eval["Competition evaluation"]
  node_lm_utils["LM decoding utilities"]
  node_ngram_lm["5-gram language model"]
  node_opt_llm["OPT language model"]
  node_submission["Decoded transcripts"]
end

node_user(("Researcher"))
node_competition_data[("Speech BCI data")]

node_user -.->|"formats data"| node_formatter
node_competition_data -.->|"provides input"| node_formatter
node_formatter -.->|"produces"| node_prepared_data
node_user -->|"starts training"| node_train_entry
node_train_entry -->|"calls"| node_trainer
node_trainer -->|"loads batches"| node_speech_dataset
node_prepared_data -->|"supplies dataset"| node_trainer
node_trainer -->|"trains and evaluates"| node_gru_decoder
node_gru_decoder -->|"uses smoothing"| node_augmentations
node_trainer -->|"writes"| node_training_outputs
node_user -.->|"runs evaluation"| node_competition_eval
node_competition_data -->|"provides trials"| node_competition_eval
node_competition_eval -->|"constructs"| node_speech_dataset
node_competition_eval -->|"calls decoding"| node_lm_utils
node_lm_utils -->|"decodes with"| node_ngram_lm
node_lm_utils -->|"rescores with"| node_opt_llm
node_competition_eval -->|"writes transcripts"| node_submission

click node_formatter "https://github.com/cffan/neural_seq_decoder/blob/master/notebooks/formatCompetitionData.ipynb"
click node_speech_dataset "https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/dataset.py"
click node_augmentations "https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/augmentations.py"
click node_gru_decoder "https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/model.py"
click node_train_entry "https://github.com/cffan/neural_seq_decoder/blob/master/scripts/train_model.py"
click node_trainer "https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/neural_decoder_trainer.py"
click node_training_outputs "https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/neural_decoder_trainer.py"
click node_competition_eval "https://github.com/cffan/neural_seq_decoder/blob/master/scripts/eval_competition.py"
click node_submission "https://github.com/cffan/neural_seq_decoder/blob/master/scripts/eval_competition.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_formatter,node_prepared_data,node_speech_dataset toneBlue
class node_augmentations,node_gru_decoder,node_competition_data toneAmber
class node_train_entry,node_trainer,node_training_outputs toneMint
class node_competition_eval,node_lm_utils,node_ngram_lm,node_opt_llm,node_submission toneRose
class node_user toneIndigo
```

## Components

### Data preparation

- [Competition formatter](https://github.com/cffan/neural_seq_decoder/blob/master/notebooks/formatCompetitionData.ipynb): `notebooks/formatCompetitionData.ipynb`
- **Formatted dataset**
- [Speech dataset](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/dataset.py): `src/neural_decoder/dataset.py`

### Decoder runtime

- [Signal augmentations](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/augmentations.py): `src/neural_decoder/augmentations.py`
- [GRU decoder](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/model.py): `src/neural_decoder/model.py`

### Training

- [Training entry](https://github.com/cffan/neural_seq_decoder/blob/master/scripts/train_model.py): `scripts/train_model.py`
- [Training loop](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/neural_decoder_trainer.py): `src/neural_decoder/neural_decoder_trainer.py`
- [Weights and metrics](https://github.com/cffan/neural_seq_decoder/blob/master/src/neural_decoder/neural_decoder_trainer.py): `src/neural_decoder/neural_decoder_trainer.py`

### Evaluation

- [Competition evaluation](https://github.com/cffan/neural_seq_decoder/blob/master/scripts/eval_competition.py): `scripts/eval_competition.py`
- **LM decoding utilities**
- **5-gram language model**
- **OPT language model**
- [Decoded transcripts](https://github.com/cffan/neural_seq_decoder/blob/master/scripts/eval_competition.py): `scripts/eval_competition.py`

### Other components

- **Researcher**
- **Speech BCI data**

## Connections

- Researcher → Competition formatter: formats data (evidence: `README.md`)
- Speech BCI data → Competition formatter: provides input (evidence: `README.md`)
- Competition formatter → Formatted dataset: produces (evidence: `README.md`)
- Researcher → Training entry: starts training (evidence: `README.md`)
- Training entry → Training loop: calls (evidence: `scripts/train_model.py`)
- Training loop → Speech dataset: loads batches (evidence: `src/neural_decoder/neural_decoder_trainer.py`)
- Formatted dataset → Training loop: supplies dataset (evidence: `src/neural_decoder/neural_decoder_trainer.py`)
- Training loop → GRU decoder: trains and evaluates (evidence: `src/neural_decoder/neural_decoder_trainer.py`)
- GRU decoder → Signal augmentations: uses smoothing (evidence: `src/neural_decoder/model.py`)
- Training loop → Weights and metrics: writes (evidence: `src/neural_decoder/neural_decoder_trainer.py`)
- Researcher → Competition evaluation: runs evaluation (evidence: `scripts/eval_competition.py`)
- Speech BCI data → Competition evaluation: provides trials (evidence: `scripts/eval_competition.py`)
- Competition evaluation → Speech dataset: constructs (evidence: `scripts/eval_competition.py`)
- Competition evaluation → LM decoding utilities: calls decoding (evidence: `scripts/eval_competition.py`)
- LM decoding utilities → 5-gram language model: decodes with
- LM decoding utilities → OPT language model: rescores with
- Competition evaluation → Decoded transcripts: writes transcripts (evidence: `scripts/eval_competition.py`)
