Skip to content

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

from spectro_kernel import run_algorithm

output = run_algorithm("embed_pretrained", ctx, {
    "model_path": "<value>",
    "model_id": "user_model",
    "input_length": 1024,
    "device": "cpu"
})
spectro run embed_pretrained --input spectrum.fits \
  --param model_path=<value> \
  --param model_id=user_model \
  --param input_length=1024 \
  --param device=cpu
{
  "tool": "embed_pretrained",
  "arguments": {
    "session_id": "<session_id>",
    "params": {
      "model_path": "<value>",
      "model_id": "user_model",
      "input_length": 1024,
      "device": "cpu"
    }
  }
}

Every algorithm is an MCP tool of the same name; describe_algorithm returns this page's metadata as JSON.

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).