Recipes
Choosing between labels with one model
A model fits one kind of record — but it can choose between labels. Give each
training record a label slot, set the label position in the encoding's
one_hot_roles (Encodings), then score a new case once per candidate label and take the
most typical (lowest score).
For example, to tell the senses of an ambiguous word apart, make each record
(word before, sense, word after) — using the nearest content words, not
"the" or "of" (the most frequent tokens in your own data are a good stop list):
train [prison, CELL_ROOM, cold] one record per labeled example
[body, CELL_BIOLOGY, divides]
score [damp, CELL_ROOM, walls] → 0.41 (illustrative scores)
[damp, CELL_BIOLOGY, walls] → 0.77 lower wins: CELL_ROOM
# before training: role 1 (the middle position) holds the label
curl -s -X PUT $API/models/$MODEL -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
-d '{"encoding": {"type": "role_embedding_v1", "dim": 16, "one_hot_roles": [1]}}'
const candidates = labels.map(label => FidelityAIScorer.encodeTokens([before, label, after], artifact, { unknown: 0 }))
const rows = FidelityAIScorer.scoreEncodedSequences(candidates, artifact)
const best = labels[rows.reduce((b, r, i) => (r.score < rows[b].score ? i : b), 0)]
In our test (two English nouns, four senses, 206 training records, 125 held-out sentences) this chose the right sense 83–91% of the time, depending on the stop-list size, against 72% for always choosing the most common sense. With exact index on that data (before missing values and unseen tokens got roles of their own), every label scored identically.