basics · feature-extraction · Xenova/multi-qa-MiniLM-L6-cos-v1 · WASM q8 · 22.97 MB

Inside Multi-QA MiniLM: question-vs-answer asymmetry & the token budget

Four small experiments, each running the real model in a Web Worker: how phrasing changes the score, why keyword search gets fooled where a QA-trained embedder doesn't, what the 512-token limit actually cuts, and why cosine and dot product give identical rankings for this model.

Model

A · Same need, four phrasings

Multi-QA MiniLM was trained on (question, answer) pairs. Score one answer passage against a question, a flat statement, bare keywords, and an answer-like sentence — and against an off-topic distractor from the same domain.

Cosine of each phrasing against the answer and the distractor
PhrasingTextcos → answercos → distractorMarginTokens
Load the model to score the phrasings.

B · Keyword-overlap traps

Each trap pairs a decoy that repeats the query's words with an answer that uses different vocabulary. BM25 counts shared terms; the dense model compares meaning.

BM25 picks…

–

Multi-QA MiniLM picks…

–

All keyword traps: which passage each ranker picked
TrapKeyword overlap (decoy / answer)BM25Dense cos (decoy / answer)Dense
Run all 4 traps to fill the scoreboard.

C · 512-token truncation inspector

The encoder sees at most 512 WordPiece tokens (and was trained on ≤ 250). A key sentence is buried after repeated filler; move it deeper and shrink the budget to see when it falls off the end and the score collapses.

Indigo = tokens kept by the budget · amber line = where the key sentence starts.

Document tokens–
Kept by budget–
Key sentence starts at–
cos(query, doc @ budget)–
cos(query, doc @ 512)–
cos(query, key sentence)–

Show the WordPiece tokens (struck = dropped by the budget)

D · Cosine ≡ dot product for unit vectors

The model card says to score with dot product or cosine. Embed two texts with and without the final L2 normalisation step: cosine is unchanged, and once vectors have length 1 the plain dot product equals it.

Norms, dot product and cosine with and without L2 normalisation
Vectors‖A‖‖B‖A · Bcos(A, B)|cos − dot|
Run the comparison.

Show the code — verifying cosine ≡ dot product on the returned vectors
Show the code — exact WordPiece counting and budget truncation in worker.js