Skip to content

About

A brain-computer interface project focused on EEG signal processing and neural representation learning

Resources

Stars

21 stars

Watchers

1 watching

Forks

Latest commit

 

History

2,301 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brain-Go-Brrr ⚡

Production-Ready EEG Analysis with EEGPT Foundation Model

CI/CD Pipeline Python 3.11+ License: Apache 2.0

📢 Note: Active seizure detection development has moved to SeizureTransformer (https://github.com/Clarity-Digital-Twin/SeizureTransformer). This repository maintains core EEG processing infrastructure.

What This Is

A Python wrapper around the EEGPT foundation model (10M parameters) for EEG analysis, providing:

  • EEGPT Features: 4×512 token embeddings (2048-d flattened for training; 512-d pooled in API by default)
  • Sleep Analysis: 87% accuracy using YASA (off-the-shelf)
  • Quality Control: Autoreject for bad channel/artifact detection
  • Abnormality Detection: Linear probe on TUAB dataset (training)
  • REST API: FastAPI with Redis caching

Quick Start

Requirements

  • Python 3.11-3.12 (3.13 not supported - scipy issues)
  • 8GB+ RAM recommended (16GB for training)
  • GPU optional (speeds up training)
  • Ubuntu/WSL2 recommended

Install

# Clone and install
git clone https://github.com/Clarity-Digital-Twin/brain-go-brrr.git
cd brain-go-brrr
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync

# Run API
uv run uvicorn brain_go_brrr.api.main:app --reload

# Test
curl http://localhost:8000/api/v1/health

Core Capabilities

✅ Working Now

  • Sleep Staging: 5-stage classification (W, N1, N2, N3, REM) via YASA
  • Feature Extraction: EEGPT embeddings (4×512 tokens → 2048 dims)
  • Quality Control: Bad channel detection, artifact rejection
  • API Server: REST endpoints with async processing

📊 Performance

Component Metric Status
Sleep Staging 87% accuracy (YASA paper) ✅ Working
QC (Autoreject) 87% expert agreement (paper) ✅ API only*
TUAB Abnormality 0.83 AUROC achieved (target: 0.869) ✅ Complete
API Response <100ms cached ✅ Working

*QC integrated in API flows; training scripts bypass QC for speed

⚠️ Archived

  • TUEV Events: Implementation correct but 22% BAC (vs 62% paper claim) - dataset has fatal class imbalance

Architecture

EEG Input → Quality Control → Parallel Processing:
                              ├── EEGPT (19+ channels, 256Hz) → Features → Abnormality Detection
                              └── YASA (any channels, 100Hz) → Sleep Stages → Metrics

Key points:

  • EEGPT requires 19+ channels at 256Hz
  • YASA works with any channel count
  • Processing is parallel, not sequential

Project Structure

brain-go-brrr/
├── src/brain_go_brrr/
│   ├── domain/          # Pure business logic
│   ├── application/     # Use cases
│   ├── infra/          # External adapters (EEGPT, YASA)
│   └── api/            # REST endpoints
├── experiments/        # Training scripts
├── tests/             # Unit & integration tests
└── docs/              # Documentation

Data & Models

Required Downloads

  1. EEGPT Model: Download from Figshare (https://figshare.com/s/e37df4f8a907a866df4b)

    • Place in: data/models/pretrained/eegpt_mcae_58chs_4s_large4E.ckpt
  2. Datasets (obtain separately):

Configuration

# Required
export BGB_DATA_ROOT=/path/to/data

# Optional
export BGB_TUAB_VERSION=""         # Versionless layout
export BGB_CACHE_DIR=$BGB_DATA_ROOT/cache  # Cache location
export BGB_SLEEP_EDF_FILE=/path/to/file.edf  # Specific test file
export EEGPT_CKPT_PATH=$BGB_DATA_ROOT/models/pretrained/eegpt_mcae_58chs_4s_large4E.ckpt  # Override checkpoint

Development

Core Commands

# Run tests
make test

# Watch tests (TDD mode)
make test-watch

# Code quality
make lint        # Ruff linting
make typecheck   # Mypy checking
make format      # Auto-format code

# Full CI check (MUST PASS before push)
make check-all

Training Models

# Build cache and train TUAB
cd experiments/eegpt_linear_probe
./scripts/build_mne_cache.sh
./scripts/launch_tuab_mne.sh

Integration Tests

# With real data
uv run pytest -m "integration and data" --run-integration --run-data

# Specific dataset
export BGB_SLEEP_EDF_FILE=/path/to/file.edf
uv run pytest tests/unit/domain/sleep -v

Key Technical Details

  • Sampling: 256Hz for EEGPT, 100Hz for YASA
  • Windows: 4 seconds for EEGPT (some legacy 8s code exists)
  • Channels: Modern naming (T7/T8/P7/P8), not legacy (T3/T4/T5/T6)
  • Features: EEGPT outputs 4×512 summary tokens, flattened to 2048 dims
  • Architecture: Clean separation - domain layer has zero infrastructure dependencies

Related Work

Documentation

Guide Purpose
docs/ARCHITECTURE.md System design patterns
docs/API.md REST endpoint reference
docs/TRAINING.md Model training guide
docs/QUICK_START.md Detailed setup
docs/CI_CD_SETUP.md GitHub Actions pipeline
ROADMAP.md Future plans

Limitations

  • Research software, not a medical device
  • Not FDA approved for clinical use
  • Models trained on specific datasets - generalization pending validation
  • Performance varies across EEG systems and populations

License & Citation

Apache 2.0 License. See LICENSE.

If using in research, please cite:

  • EEGPT: Wang et al. (2024) NeurIPS
  • YASA: Vallat & Walker (2021) bioRxiv
  • MNE-Python: Gramfort et al. (2013) Frontiers
  • Datasets: See documentation for specific citations

For AI assistants: See CLAUDE.md for development context

About

A brain-computer interface project focused on EEG signal processing and neural representation learning

Resources

Stars

21 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages