Onnx Lodestar.Onnx - CyrilB1531/lodestar GitHub Wiki

Development build. This page describes main, not a released package. The latest published Lodestar.Onnx is 0.1.1 — read its documentation.

Home › Onnx

Lodestar.Onnx

Runs a transformer encoder exported to ONNX and pools its token outputs into a sentence embedding, through ONNX Runtime. It was split out of Lodestar.Embeddings so that tokenizing, pooling or searching never restores a native runtime; install this package only when you run the model in-process.

The model file is yours: this repository never ships model weights.

Install

dotnet add package Lodestar.Onnx

Example

using Lodestar.Onnx;

using var embedder = new OnnxTextEmbedder("model.onnx");

long[] ids = [101, 2054, 2003, 102];
long[] mask = [1, 1, 1, 1];

float[] vector = embedder.Embed(ids, mask);

Parity

Embeddings are replayed against batch_encoding.json, whose ids come from HuggingFace tokenizers and whose vectors are float64 numpy arithmetic over the same embedding table the synthetic test model gathers from, computed by tools/generate_oracles.py — not a run of ONNX Runtime's Python binding. ONNX Runtime returns float32, so agreement with it is bounded by float32 precision. docs/equivalence.md maps each Python call to its C# counterpart, with every deliberate divergence.

Dependencies

A satellite package (decision 0003), built for net10.0 and netstandard2.0:

  • Lodestar.Embeddings 0.8.0 or later
  • Microsoft.ML.OnnxRuntime 1.30.0 or later

Documentation