File size: 1,059 Bytes
e4d2e6e fb98fc7 e4d2e6e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // node tokenize_check.mjs tokenizer.json cases.jsonl -> mismatches against the Python tokenizer's ids
import fs from "node:fs";
import readline from "node:readline";
import { UnigramTokenizer, pocketText } from "./pocket_text.js";
const tok = new UnigramTokenizer(JSON.parse(fs.readFileSync(process.argv[2], "utf8")));
let n = 0, bad = 0, badText = 0;
const rl = readline.createInterface({ input: fs.createReadStream(process.argv[3]) });
for await (const line of rl) {
const r = JSON.parse(line); n++;
const t = pocketText(r.raw, r.tags);
if (t !== r.text) { badText++; if (badText <= 3) console.log("TEXT", JSON.stringify(r.raw).slice(0, 80), "|", JSON.stringify(t).slice(0, 80), "|", JSON.stringify(r.text).slice(0, 80)); }
const ids = tok.encode(r.full ?? r.text);
if (ids.join(",") !== r.ids.join(",")) { bad++; if (bad <= 5) console.log("IDS", JSON.stringify(r.text).slice(0, 70), ids.slice(0, 12).join(","), "|", r.ids.slice(0, 12).join(",")); }
}
console.log(JSON.stringify({ cases: n, pocket_text_mismatch: badText, ids_mismatch: bad }));
|