embed_pretrained¶
Embed a spectrum with a local pre-trained PyTorch model.
| Category | Embeddings |
| Backend | pytorch - runs a local PyTorch model (optional extra embedding-ml) |
| Version | 1.0.1 |
| Reads | ctx.spectrum (a Spectrum1D) |
| Writes | embedding, extras.embedding_provenance, metrics.embedding_dim, metrics.embedding_norm |
On the first call for a given model_path the file's SHA-256 is computed and recorded in the provenance dict; subsequent calls reuse the loaded model object (cached on the algorithm instance). Non-finite samples (NaN/inf) make the brick fail cleanly — interpolate or mask bad pixels before inference.
Parameters¶
| Parameter | Default | Required | Description |
|---|---|---|---|
model_path |
None |
yes | Filesystem path to the PyTorch model file (.pt / .pth) (REQUIRED). The user is responsible for downloading or training the model; the kernel only loads what's already on disk. |
model_id |
'user_model' |
- | Human-readable identifier captured in the provenance dict alongside the SHA-256 hash; lets the similarity layer track which model version produced which vector. |
input_length |
1024 |
- | Number of pixels the model expects. The spectrum is resampled to this length before being fed to the model. |
device |
'cpu' |
- | Torch device ('cpu' or 'cuda:0' if a GPU is present). |
Use it¶
References¶
- Bishop 2006, 'Pattern Recognition and Machine Learning' — embedding via learned representations.
- Naul et al. 2018, Nat. Astron. 2, 151 — RNN autoencoders for irregular astronomical time series (analogous architecture).
Related algorithms¶
embed_band_power- Embed a spectrum as the integrated flux in N adjacent wavelength bands.embed_continuum_subtracted- Subtract the polynomial continuum, then embed the line residual.embed_lick_indices- Embed a spectrum as the canonical Lick/IDS line-strength indices.embed_log_lambda- Resample to a uniform log-λ grid, then embed.embed_remote- Embed a spectrum via a remote HTTPS inference endpoint.embed_spectrum- Compute a fixed-length, L2-normalised embedding of a spectrum.embed_wavelets- Embed a spectrum via a truncated discrete wavelet transform.