Skip to main content

Crate brain2qwerty

Crate brain2qwerty 

Source
Expand description

§brain2qwerty

Rust inference for Brain2Qwerty: MEG/EEG neural decoding to text, with numeric parity against the official Python reference implementation.

§Pipelines

VersionPaperRust entry point
V1Nature Neuroscience 2026 — keystroke-aligned windows + sentence transformerV1Pipeline
V2Sentence-level CTC + TinyLlama beam searchPipeline

§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_DIR or ./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.safetensors exists.