Expand description
§brain2qwerty
Rust inference for Brain2Qwerty: MEG/EEG neural decoding to text, with numeric parity against the official Python reference implementation.
§Pipelines
| Version | Paper | Rust entry point |
|---|---|---|
| V1 | Nature Neuroscience 2026 — keystroke-aligned windows + sentence transformer | V1Pipeline |
| V2 | Sentence-level CTC + TinyLlama beam search | Pipeline |
§V2 quick start
use brain2qwerty::pipeline::{InferenceInput, Pipeline};
let mut pipeline = Pipeline::from_paths(
"data/config.yaml",
"data/encoder.safetensors",
Some("data/llm"),
)?;
let input = InferenceInput {
neuros: /* (B, T, C) tensor */,
subject_ids: vec![0],
chan_pos: None,
};
let out = pipeline.run(&input)?;
println!("{}", out.pred_text);§V1 quick start
V1 expects keystroke windows shaped (N, channels, time) — see V1Input.
use brain2qwerty::{V1Input, V1Pipeline};
let pipeline = V1Pipeline::from_tiny_weights("data/encoder_v1.safetensors")?;
let out = pipeline.run(&V1Input {
neuros: /* (N, C, T) */,
subject_ids: vec![0],
chan_pos: None,
})?;
println!("{}", out.pred_text);§Features
rlx-encoder(default): RLX-accelerated Conformer tail for V2.pure-rust: disable RLX; use the reference CPU encoder only.- Backend features:
rlx-cpu,rlx-metal,rlx-cuda,rlx-mlx,rlx-coreml, …
§Parity tests
Generate Python references, then run bash scripts/run_all_parity.sh or individual
cargo test --test *_parity targets. Continuous tensors must reach Pearson r ≥ 0.999999.
Re-exports§
pub use config::Brain2QwertyConfig;pub use config::BuildArgs;pub use config::EncoderConfig;pub use decode::ctc_greedy_decode;pub use decode::CTCSpaceSegmenter;pub use decode::IntraWordPooler;pub use model::conv_conformer::ConvConformer;pub use model::conv_conformer::ConvConformerOutput;pub use pipeline::InferenceInput;pub use pipeline::Pipeline;pub use pipeline::PipelineOptions;pub use pipeline::PipelineOutput;pub use tensor::Tensor;pub use v1::Brain2QwertyV1;pub use v1::V1Config;pub use v1::V1Input;pub use v1::V1Output;pub use v1::V1Pipeline;
Modules§
- config
- Configuration matching brain2qwerty_v2 Python configs.
- data_
paths - Paths to bundled configs, weights, and parity reference data.
- decode
- llm
- model
- model_
rlx - ConvConformer on RLX — compiled graph with per-shape cache.
- pipeline
- End-to-end Brain2Qwerty V2 inference: encoder → CTC → segmenter → LLM beam search.
- rlx_
device - Map CLI / env device strings to
rlx::Device. - tensor
- Lightweight f32 tensors for inference, I/O, and the pure-Rust reference ops.
- v1
- Brain2Qwerty V1 — keystroke-aligned MEG decoding (Conv + sentence transformer).
- weights
- Safetensors loading and PyTorch key utilities.
Functions§
- data_
dir - Root data directory (
BRAIN2QWERTY_DATA_DIRor./data). - encoder_
v1_ weights_ available - encoder_
v2_ weights_ available - parity_
refs_ available - Whether tiny V2 parity refs are present.
- parity_
refs_ dir - Tiny V2 parity reference tensors (
data/parity_refs/). - parity_
refs_ v1_ available - parity_
refs_ v1_ dir - V1 parity refs (
data/parity_refs_v1/). - parity_
refs_ v2_ available - parity_
refs_ v2_ dir - Production-scale V2 parity refs (
data/parity_refs_v2/). - weights_
available - Whether
data/encoder.safetensorsexists.