Reverse-engineered Jev-like model
https://github.com/vinnylarouge/jevlike📌 逆向工程 Jev:一次前向傳播,選出正確選項
TL;DR:開源複刻商用選項評分模型 Jev,單次前向傳播比逐字生成快約 100 倍。
多數 LLM 應用在做選擇題時,還是讓模型一個字一個字寫出答案,再解析成選項。TypeSafe 的商用模型 Jev 反其道而行:輸入一段文字與一份選項清單,直接為每個選項輸出一個機率,一次前向傳播就搞定。TypeSafe 沒有公開設計細節,Hacker News 上一個名為 jevlike 的專案,獨立做出了輸入輸出形狀相同的起始模型。
🤔 為什麼不用生成式方式做選擇題
Jev 這類模型要解決的問題是:給一段 context 文字,以及一份會不斷變動的選項清單,為每個選項算出一個機率,而不是像自迴歸解碼器那樣逐字生成答案。作者明確強調,jevlike 是獨立的研究起始模型,不是 Jev 的複製品,也沒有證明與 Jev 效能相當,或重現 TypeSafe 的私有訓練方法。
🧩 核心架構:query 向量、attention、共享點積、softmax
每個選項會先被轉成一個 query 向量(代表該選項文字的一組短數字)。這個 query 向量對 context tokens 做 attention,算出對應的權重,產生該選項專屬的 context 向量。接著用一個共享的點積運算,把「選項向量」與「context 向量」這對組合轉換成一個分數,最後所有選項的分數一起做 softmax,轉成總和為一的機率分布。
encoder(把文字轉成向量的部分)有兩種選擇:預設是從頭學習 byte embedding,成本低但對語意理解較弱;另一個選項是接上凍結的 Hugging Face 預訓練 encoder,只訓練小型的 scorer head,--rank 參數控制這個 head 的寬度。資料格式是每行一個 JSON,包含 context、options 清單(每行選項數可不同,最少兩個)與 zero-based 的 label 索引。
專案還展示了同一個 option-attention head 不只能處理文字,也能替影像 patch 打分:demo 影片串接了兩段五秒畫面,一段是用七個按鍵操作的 Doom 戰鬥畫面,一段是用五個按鍵下棋的畫面,兩個範例都是呼叫 jevlike.vision 這同一個視覺 scorer,沒有另外複製一份模型。
📊 準確率與速度數據
- 在合成選單資料上,單次前向傳播的 scorer 達到約 98% 準確率。
- 在 target-disjoint 的 Wikispeedia 下一步點擊資料上,搭配凍結的 Qwen2.5-0.5B encoder,準確率為 26%,而 shuffled 與 random-encoder 對照組僅約 8%;一個從頭訓練、只用 4 萬筆點擊資料的小模型則達到 29%。
- 在八個選項的情境下,單次前向傳播的速度比被迫寫出 400 個 token 的小型解碼器快約 100 倍。
- Demo 用的 Doom 聯合訓練 checkpoint,在 10 場紀錄中平均擊殺 0.60、reward -97.50;純棋類 checkpoint 在對隨機對手的 50 局中取得 4 勝 46 和 0 敗,但對戰 Stockfish level 0 時僅 0 勝 2 和 48 敗——作者特別說明這些片段是挑選出來展示活動性,不代表典型表現或棋力宣稱。
⚠️ 作者列出的明確限制
這是研究性質的起始模型,而非 Jev 的複製品;準確率高度依賴資料品質、切分品質與 encoder 選擇;預設的 byte encoder 雖然便宜,但對語言意義的掌握較弱;接上預訓練模型的路徑可能需要下載大型模型、佔用更多記憶體;單次評分需要在預測前就拿到完整的選項清單;速度比較用的是小型本地解碼器,而非大型商用模型。
🎯 實務啟示
如果你的應用場景是「從一份會變動的選項清單裡挑一個」,例如意圖路由、選單分類這類任務,jevlike 提供了一個比自迴歸生成快得多的推論路徑,程式碼採 MIT 授權。專案也提醒使用自有資料時,要把相關紀錄(例如同一位客戶或同一個目標頁面)切在同一個資料切分裡,避免近似重複樣本洩漏到測試集,這點在自建 held-out 測試集時值得留意。
🔗 來源
- 標題:Reverse-engineered Jev-like model
- 連結:https://github.com/vinnylarouge/jevlike
#ReverseEngineering #MachineLearning #Attention #OpenSource #TextClassification #NeuralNetworks #Softmax #ModelArchitecture #GitHub #AIResearch
原始資料 Hacker News · 收集於 2026-09-17
摘要原文
Jevlike Train a small model that chooses among a changing list of text options. A Jev-like model takes a piece of text and a list of N text options. It returns one probability for each option. It does this in one pass instead of writing an answer word by word. Jev is TypeSafe's commercial model for this kind of task. TypeSafe has not published its design. This repository is an independent starter model with the same input and output shape. Demo The same option-attention head can score controller buttons from image patches. This ten-second film joins two selected five-second windows: live deadly_corridor combat on the seven Doom buttons, then a chess controller walking to and playing moves with five keys. The diagram shows the tensors used for each decision. The Doom window came from the supplied joint checkpoint, which averaged 0.60 kills and -97.50 reward across its ten recorded episodes. The chess window came from the stronger chess-only checkpoint, which scored 4 wins, 46 draws and 0 losses in 50 sampled games against a random mover, but 0 wins, 2 draws and 48 losses against Stockfish level 0. The windows were selected for activity and are not typical-play or competence claims. Install the game extras and record a fresh 640 by 480 Doom trace from the released joint checkpoint: uv pip install -e ' .[games] ' python examples/doom/play.py examples/checkpoints/joint-imitation.pt --episodes 10 --game-seconds 35.3 --device cpu --capture-resolution 640x480 --output runs/doom.mp4 --trace runs/doom-trace.json Render the trace in the same visual layout. This writes a silent film because the author-owned soundtrack source is not part of the repository. (cd examples/film && npm install && npx playwright install chromium) examples/film/make-film.sh runs/doom-trace.json runs/doom-film.mp4 10 The release includes the Doom example , the chess example , the single-game checkpoints and the shared 12-option checkpoint. Both games import the visual scorer from jevlike.vision ; there is no second model copy in either example. Architecture Each option becomes a query vector, which is a short list of numbers representing its text. The query assigns attention weights to the context tokens. Those weights make one context vector for that option. A shared dot product turns each option and context pair into one score. A softmax, which converts scores into probabilities that sum to one, runs across the options. The default encoder learns byte embeddings from scratch. An encoder is the part that turns text into vectors. The optional Hugging Face path uses a frozen pretrained encoder, whose existing weights stay fixed while the small scorer learns. Data format Use one JSON object per line: { "context" : " The customer needs a refund. " , "options" :[ " refund " , " sales " , " technical support " ], "label" : 0 } label is the zero-based index of the correct option. Each row may have a different number of options, with a minimum of two. Quickstart Run these commands from the repository root. They create local synthetic data, train on it, evaluate the saved model and score one new menu. uv venv source .venv/bin/activate uv pip install -e ' .[dev] ' jevlike-data synthetic --output data/synthetic jevlike-train data/synthetic/train.jsonl \ --validation data/synthetic/validation.jsonl \ --output runs/synthetic.pt jevlike-eval runs/synthetic.pt data/synthetic/test.jsonl jevlike-predict runs/synthetic.pt \ --context " Choose the exact badge amber badger. Badge: amber badger. " \ --option " azure crane " \ --option " amber badger " \ --option " gold heron " The evaluation prints top-1 accuracy, which is the fraction of correct first choices. Top-3 accuracy is the fraction with the right answer among the three highest scores. Expected calibration error compares confidence with observed accuracy. The command also prints a shuffled-context control, which pairs each menu with the wrong context. A useful model should beat that control. Use your own data Export train, validation and test JSONL files in the format above. Keep all options that the model will see at prediction time in each row. Split related records together. For example, keep all records for one customer or one target page in one split. This prevents near-duplicates from leaking into the test set. Run jevlike-train with your train and validation files. Run jevlike-eval once on the held-out test file. Held-out means the file was never used for training or model selection. The default byte encoder truncates context to 192 bytes and each option to 32 bytes. Raise --context-tokens or --option-tokens when your text needs more room. Training supports CPU, Apple MPS for a Mac GPU, and CUDA for an NVIDIA GPU through --device . Use a frozen pretrained encoder Install the optional dependency and name any compatible encoder from Hugging Face: uv pip install -e ' .[transformers] ' jevlike-train data/synthetic/train.jsonl \ --validation data/synthetic/validation.jsonl \ --output runs/qwen-head.pt \ --encoder hf \ --hf-model Qwen/Qwen2.5-0.5B \ --rank 256 \ --batch-size 8 The checkpoint stores the trained scorer head and the encoder name. It does not copy the frozen encoder weights. Loading the checkpoint therefore needs access to the same Hugging Face model. --rank sets the width of the small scorer head. A wider head has more trainable weights and uses more memory. Wikispeedia example scripts/get_wikispeedia.sh downloads the public SNAP archives and builds next-click JSONL files. The data stay outside this repository. scripts/get_wikispeedia.sh jevlike-train data/wikispeedia/jsonl/train.jsonl \ --validation data/wikispeedia/jsonl/validation.jsonl \ --output runs/wikispeedia.pt Cite Robert West and Jure Leskovec, Human Wayfinding in Information Networks , WWW 2012. Review the source data terms on the SNAP dataset page . What to expect In the experiments that led to this starter, the one-pass scorer reached about 98% accuracy on synthetic menus. On target-disjoint Wikispeedia next-click data, a frozen Qwen2.5-0.5B encoder plus the scorer reached 26%, against about 8% for shuffled and random-encoder controls. A small model trained from scratch on 40,000 clicks reached 29%. At eight options, one pass was about 100 times faster than a small decoder forced to write 400 tokens. These numbers describe local experiments, not this quickstart run. We did not show equal quality with Jev or reproduce TypeSafe's private training method. Limitations This is a research starter, not a copy of Jev. Accuracy depends on data quality, split quality and the encoder. The byte encoder is cheap but weak on language meaning. The pretrained path may download a large model and needs more memory. One-pass scoring requires the complete option list before prediction. The speed comparison used a small local decoder rather than a large commercial model. Licence Code is released under the MIT License . Downloaded datasets and pretrained models keep their own terms. (154 points, 22 comments on Hacker News)
由 claude-code/sonnet 自動生成