Downloads · 30 days
75
16% of all-time downloads
wi-lab/lwm-spectro
lwm-spectro is a feature extraction model from wi-lab. Use it when you need embeddings to search or compare text. It is set up for pytorch.
Dataset is available: https://www.dropbox.com/scl/fo/anxd7u57snh505zfll0wr/AB159k9OG7nGWyVtXlGsYvw?rlkey=6ct9w6iwb3ms8fiygcv9q3iyk&st=wqg7e0b4&dl=0
Downloads · 30 days
75
16% of all-time downloads
All-time downloads
477
Public
Repo size
3.4 GB
Likes
5
Public
Click a slice to open those files.
.pt766 MB · 89%
From the Hugging Face model README
Dataset is available: https://www.dropbox.com/scl/fo/anxd7u57snh505zfll0wr/AB159k9OG7nGWyVtXlGsYvw?rlkey=6ct9w6iwb3ms8fiygcv9q3iyk&st=wqg7e0b4&dl=0
🚀 Click here to try the Interactive Demo!
Space: https://huggingface.co/spaces/wi-lab/LWM-Spectro
🚀 This model repo provides
moe_checkpoint.pth (router + experts + classifier; top-1 gating)experts/*demo_data.pt / demo_data_moe.ptThis repo is intentionally drop-in and lightweight for inference, visualization, and reproducing the Space plots.
For the broader research / training workflow (pretraining + task scripts + MoE training), see README_code.md.
Modern wireless learning models often work well on a single protocol / dataset / SNR range, but can break when the communication standard, propagation environment, or label budget changes.
LWM-Spectro is a foundation model for received baseband I/Q signals represented as time–frequency spectrograms. The core goal is to learn a representation that:
Received I/Q signals inherently encode both transmitter-side structure (e.g., modulation/coding) and channel-side structure (e.g., multipath, Doppler, SNR).
By converting the received waveform into an STFT spectrogram, we get a structured time–frequency “image” where both modulation signatures and channel dynamics appear as learnable patterns.
LWM-Spectro is pretrained on large-scale unlabeled (or weakly labeled) spectrogram data so that downstream tasks can reuse these learned features instead of training from scratch.
At a high level, LWM-Spectro combines:
In practice, the released checkpoint is packaged behind an inference wrapper (MoEPredictor) that returns:
LWM-Spectro uses protocol-specialized experts (e.g., WiFi / LTE / 5G) inside an MoE. Conceptually, training is two-stage:
Stage 1 — Expert pretraining (per protocol)
Each expert encoder (E_k) is pretrained on its own protocol’s spectrogram dataset using a self-supervised objective (masked spectrogram modeling) and optionally a contrastive objective to shape the embedding space.
Stage 2 — Router (and head) training (multi-protocol)
Experts are frozen, then a lightweight router (R) is trained on a balanced mix of WiFi/LTE/5G to select which expert to use.
In the paper this is described as top‑1 routing (activate one expert per input) for efficiency. The implementation in this repo exposes top‑k routing for experimentation, but the released “drop-in” artifacts are used in a top‑1 style at inference time.
From the paper configuration, each expert is a Transformer encoder over spectrogram patches:
(Implementation pointers: expert pretraining scripts live in pretraining/train_lwm_spectro*.py and the backbone definition is in pretraining/pretrained_model.py.)
The MoE combines a small router with the experts:
Implementation note: the paper describes a small Transformer router, while the repo’s training implementation uses a lightweight CNN router for practicality (see mixture/train_embedding_router.py, RouterNet).
experts/: per‑protocol expert weights (protocol-specialized encoders)moe_checkpoint.pth: a packed checkpoint used by MoEPredictor (router + experts + classifier/head)LWM-Spectro representations transfer effectively to downstream tasks such as:
The repo also includes scripts to reproduce common qualitative sanity checks, e.g., t‑SNE comparisons where raw spectrograms overlap heavily while learned embeddings form more coherent clusters.
The LWM-Spectro paper pipeline synthesizes diverse I/Q spectrograms across:
The intent is to expose the model to realistic variability (protocol + channel + motion) so the learned representation generalizes.
sample["data"]){SNR-5dB, SNR0dB, SNR5dB, SNR10dB, SNR15dB, SNR20dB, SNR25dB}{tech, snr, mod, mob, data, embedding, tech_embedding, moe_embedding, tech_embedding_dim}hf_hub_download() for fetching artifacts without cloningimport torch
from huggingface_hub import hf_hub_download
from mixture.train_embedding_router import MoEPredictor
repo_id = "wi-lab/lwm-spectro"
ckpt_path = hf_hub_download(repo_id=repo_id, filename="moe_checkpoint.pth")
predictor = MoEPredictor.from_checkpoint(ckpt_path)
# One spectrogram: [H, W] = [128, 128]
spec = torch.rand(128, 128)
out = predictor.predict(spec, return_probabilities=True, return_routing=True)
print(out["label"], out["confidence"])
print("routing:", out.get("routing"))
import torch
from huggingface_hub import hf_hub_download
from mixture.train_embedding_router import MoEPredictor
repo_id = "wi-lab/lwm-spectro"
ckpt_path = hf_hub_download(repo_id=repo_id, filename="moe_checkpoint.pth")
demo_path = hf_hub_download(repo_id=repo_id, filename="demo_data.pt")
predictor = MoEPredictor.from_checkpoint(ckpt_path)
samples = torch.load(demo_path, weights_only=False)
# Each sample is a dict; the spectrogram lives under sample["data"] (float16 128x128).
spec0 = samples[0]["data"].float() # [128, 128]
out0 = predictor.predict(spec0, return_probabilities=False, return_routing=True)
print(out0["label"], out0["confidence"], out0.get("routing"))
# Batch inference: [B, H, W]
batch = torch.stack([s["data"].float() for s in samples[:32]], dim=0)
outb = predictor.predict(batch)
print(outb["labels"][:5], outb["confidence"][:5])
Use Miniconda/Anaconda (any recent version is fine).
conda create -n lwm_spectro python=3.10 -y
conda activate lwm_spectro
pip install -r requirements.txt
git lfs install
git clone https://huggingface.co/wi-lab/lwm-spectro
cd lwm-spectro
git lfs pull
from huggingface_hub import hf_hub_download
repo_id = "wi-lab/lwm-spectro"
ckpt = hf_hub_download(repo_id=repo_id, filename="moe_checkpoint.pth")
demo = hf_hub_download(repo_id=repo_id, filename="demo_data.pt")
python hf_minimal_inference.py
This downloads moe_checkpoint.pth (if needed), runs a random 128×128 tensor through the MoE predictor, and prints the predicted label + confidence.
The main inference entry point is:
mixture.train_embedding_router.MoEPredictor.from_checkpoint(checkpoint_path)MoEPredictor.predict(spectrogram, return_probabilities=False, return_routing=False)spectrogram: torch.Tensor of shape [H, W] or [B, H, W]The returned dict includes:
predicted_class: int (single) or list[int] (batch)confidence: float (single) or list[float] (batch)label / labels: human-readable label(s) when label mapping is availableprobabilities (optional): full softmax distribution if return_probabilities=Truerouting (optional): top‑k expert routing weights if return_routing=Trueimport torch
from huggingface_hub import hf_hub_download
repo_id = "wi-lab/lwm-spectro"
local = hf_hub_download(repo_id=repo_id, filename="demo_data.pt")
samples = torch.load(local, weights_only=False)
print(len(samples), samples[0].keys())
python -m plot.plot_tsne --LTE --sampling-mode reservoir --label-field snr
python -m plot.plot_tsne --WiFi --sampling-mode reservoir --label-field modulation
python -m plot.plot_tsne --5G --sampling-mode reservoir --label-field modulation
Each command loads 3,500 samples (7×500) per technology when using the bundled demo tensors.
This repo includes scripts used in the research workflow:
pretraining/train_lwm_spectro*.pytask1/train_mcs_models.pytask2/train_joint_snr_mobility.pyMoE/* and mixture/*For a structured overview, see README_code.md.
hf_minimal_inference.py: minimal Hub inference demo (random tensor)mixture/run_moe_inference.py: CLI to run Task1+Task2 MoE checkpoints on real spectrogram pickle inputsmoe_checkpoint.pth: main MoE checkpoint (Git LFS)experts/: per-tech expert weights (Git LFS)demo_data.pt, demo_data_moe.pt: SNR-balanced demo samples (Git LFS)plot/plot_tsne.py: raw-vs-embedding t‑SNE with SNR-balanced sampling, plus optional clustering metricspretraining/: pretraining scripts for the spectrogram backbonetask1/, task2/: downstream training/eval scriptsMoE/, mixture/: MoE training, baselines, and inference utilitiesPlease cite the following paper if you use the LWM model or any modified parts:
@misc{kim2026lwmspectrofoundationmodelwireless,
title={LWM-Spectro: A Foundation Model for Wireless Baseband Signal Spectrograms},
author={Namhyun Kim and Sadjad Alikhani and Ahmed Alkhateeb},
year={2026},
eprint={2601.08780},
archivePrefix={arXiv},
primaryClass={cs.IT},
url={https://arxiv.org/abs/2601.08780},
}
<!-- ## 📄 License
MIT -->