Skip to main content

Scoring offline

A trained model is a JSON artifact: result.client_handoff_artifact from GET /models/{id}/result. Scoring it needs nothing from FidelityAI: the portable scorer is one dependency-free script, built from the same scorer.js the console uses. It is tested to give the same scores in Node and in JavaScriptCore (iOS), to about 12 significant digits — engines round Math.exp and friends differently in the last bits.

https://fidelityai.org/sdk/scorer.v1.js

Pin the filename: breaking changes ship under a new name (scorer.v2.js).

Load it​

// Node
const FidelityAIScorer = require('./scorer.v1.js')

// Browser
// <script src="https://fidelityai.org/sdk/scorer.v1.js"></script> → window.FidelityAIScorer

const rows = FidelityAIScorer.scoreEncodedSequences(sequences, artifact)
// iOS — JavaScriptCore is built in
import JavaScriptCore
let js = JSContext()!
js.evaluateScript(scorerSource) // contents of scorer.v1.js
js.setObject(artifactJSON, forKeyedSubscript: "artifactJSON" as NSString)
let rows = js.evaluateScript("JSON.stringify(FidelityAIScorer.scoreEncodedSequences(\(sequencesJSON), JSON.parse(artifactJSON)))")

On Android, load the same file in QuickJS or Hermes; it defines the global FidelityAIScorer wherever there is no module system.

Training renumbers your vocabulary, so map your token ids to the model's own positions before scoring:

const seq = FidelityAIScorer.encodeTokens([3, 1, 4, 1, 5], artifact) // your ids → the model's
FidelityAIScorer.scoreEncodedSequences([seq], artifact)

Scoring raw ids gives wrong scores without any error. Ids the model never saw are skipped (or pass { unknown: id }). calibrate expects mapped sequences too.

Scoring text (prose models)​

For models trained on prose, use the text build instead — the same scorer plus the text encoder the console uses:

https://fidelityai.org/sdk/scorer-text.v1.js (~400 KB, ~150 KB gzipped)

Models whose artifact says "frameExtractor": "scribe-v1" (prose models trained from October 2026) read sentences with a dependency parse. Load its model once, before encoding text:

https://fidelityai.org/scribe-parse-v1.bin (~7.6 MB; CC BY-SA 4.0: learned from the
UD English Web Treebank and Open English WordNet)
const FidelityAIScorer = require('./scorer-text.v1.js')
FidelityAIScorer.loadParseModel(require('fs').readFileSync('scribe-parse-v1.bin')) // or an ArrayBuffer from fetch
const rows = await FidelityAIScorer.scoreText(['The Receiving Party shall not disclose Confidential Information.'], artifact)
// rows[i].text, rows[i].tokens (e.g. "subject=party", "action=disclose"), rows[i].score
const { sequence } = await FidelityAIScorer.encodeText(text, artifact) // just the token ids

encodeText and scoreText are asynchronous. They make no network calls, and run in Node, browsers and JavaScriptCore — on iOS, call them from a JSContext and read the result in a later evaluateScript, after the promise settles. Text with no recognizable tokens gets status: "error". The text build defines the same FidelityAIScorer, so it can replace scorer.v1.js.

Calibrate (for flagging)​

score alone is enough to rank sequences. To flag one as unusual, the scorer compares it with the scores your own source gets — its percentiles. Compute them on your device from the source you trained on, once per model:

const mapped = sourceSequences.map(s => FidelityAIScorer.encodeTokens(s, artifact))
const calibration = FidelityAIScorer.calibrate(mapped, artifact) // samples up to 1,000
const calibrated = FidelityAIScorer.withCalibration(artifact, calibration)
FidelityAIScorer.scoreEncodedSequences(sequences, calibrated) // status and margins now set

Pass { sampleSize: 0 } to use every source sequence. Save calibration with the artifact so you only compute it once. Without calibration, status falls back to the raw score's sign and the margins are empty.

Reading a score​

Each row of scoreEncodedSequences describes one sequence:

FieldMeaning
scoreHow far the record is beyond the fitted source: 0 when it is at least as typical as the median source record, higher the less it looks like the source (less typical on the one-class boundary, or outside what the reference records span). Lower is more typical.
statuscompliant within the source's 95th-percentile score, anomaly beyond it (needs calibrate)
sourceP95Margin, sourceP99Margin, sourceMaxMarginscore minus that source percentile (from calibrate) — positive means farther than that share of the source. With sampling, the max is an estimate
severityLabelThe margins in words, e.g. above source p99
runtimeScoresThe same sequence under other distance measures (one-class SVM boundary, nearest support vector, centroid, Mahalanobis, …) when the artifact includes them
tupleContributionsWhich tuples of the sequence contributed most to its score. With role embeddings, each tuple's own score against the source's tuples (0 = at least as typical as the median source tuple), worst first

Use score to rank candidates against each other (as in Recipes); use status and the margins to flag a single sequence as unusual.

Speed​

Scoring time is linear in the number of sequences and grows with the model's capacity. Batch sequences into one scoreEncodedSequences call, and measure on your target device before scoring in a latency-sensitive path.