Download scripts/purge_mock_gold.mjs from htaf/distill-pipeline: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/htaf/distill-pipeline/resolve/main/scripts/purge_mock_gold.mjs
- Command line
-
hf download hf://htaf/distill-pipeline/scripts/purge_mock_gold.mjs
-
curl -L -o purge_mock_gold.mjs https://huggingface.co/htaf/distill-pipeline/resolve/main/scripts/purge_mock_gold.mjs
1.61 kB
| // scripts/purge_mock_gold.mjs | |
| // Remove gold entries with mock/test questions (e.g., "Q1?") from pipeline_gold.jsonl | |
| import fs from 'fs/promises'; | |
| import path from 'path'; | |
| import { fileURLToPath } from 'url'; | |
| const __filename = fileURLToPath(import.meta.url); | |
| const __dirname = path.dirname(__filename); | |
| const PROJECT_ROOT = path.join(__dirname, '..'); | |
| const GOLD_PATH = | |
| process.env.GOLD_PATH || | |
| path.join(PROJECT_ROOT, 'gold', 'pipeline_gold.jsonl'); | |
| const questionRegex = new RegExp(process.env.PURGE_QUESTION_REGEX || '^Q1\\?$'); | |
| async function main() { | |
| let raw; | |
| try { | |
| raw = await fs.readFile(GOLD_PATH, 'utf8'); | |
| } catch (e) { | |
| if (e.code === 'ENOENT') { | |
| console.error(`Gold file not found: ${GOLD_PATH}`); | |
| process.exit(1); | |
| } | |
| throw e; | |
| } | |
| const lines = raw | |
| .split('\n') | |
| .map((l) => l.trim()) | |
| .filter(Boolean); | |
| const kept = []; | |
| const removed = []; | |
| for (const line of lines) { | |
| try { | |
| const obj = JSON.parse(line); | |
| const q = obj.question || ''; | |
| if (questionRegex.test(q)) { | |
| removed.push(line); | |
| } else { | |
| kept.push(line); | |
| } | |
| } catch { | |
| // if invalid JSON, keep it to avoid accidental loss | |
| kept.push(line); | |
| } | |
| } | |
| if (removed.length === 0) { | |
| console.log('No matching entries to purge.'); | |
| return; | |
| } | |
| await fs.writeFile(GOLD_PATH, kept.join('\n') + '\n', 'utf8'); | |
| console.log(`Purged ${removed.length} entries matching ${questionRegex}. Kept ${kept.length}.`); | |
| } | |
| main().catch((err) => { | |
| console.error('Purge error:', err); | |
| process.exit(1); | |
| }); | |