Download batch_correction.js from anmol-unitmole/05-grammar-error-correction-t5-encoder-decoder: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/anmol-unitmole/05-grammar-error-correction-t5-encoder-decoder/resolve/main/batch_correction.js
- Command line
-
hf download hf://spaces/anmol-unitmole/05-grammar-error-correction-t5-encoder-decoder/batch_correction.js
-
curl -L -o batch_correction.js https://huggingface.co/spaces/anmol-unitmole/05-grammar-error-correction-t5-encoder-decoder/resolve/main/batch_correction.js
1.34 kB
| import { parseBatchInput } from './text_preprocessing.js'; | |
| import { correctText } from './correction_inference.js'; | |
| export async function correctBatch(rawText, metadata, enrichResult) { | |
| const items = parseBatchInput(rawText); | |
| const results = []; | |
| for (let index = 0; index < items.length; index += 1) { | |
| const generation = await correctText(items[index], metadata); | |
| results.push({ rowId: index + 1, ...enrichResult(generation) }); | |
| } | |
| return results; | |
| } | |
| export function downloadCsv(rows, filename = 'grammar_corrections.csv') { | |
| const headers = ['row_id','original_text','corrected_text','edit_count','error_categories','confidence_proxy','meaning_preservation','overcorrection_flag','latency_ms','inference_mode']; | |
| const escape = (value) => `"${String(value ?? '').replaceAll('"', '""')}"`; | |
| const lines = [headers.join(',')]; | |
| rows.forEach((row) => lines.push([ | |
| row.rowId,row.original,row.corrected,row.tracked.wordLevelEditCount,row.categories.categories.join('; '),row.confidence.score,row.meaning.score,row.over.flag,row.latencyMs,row.mode, | |
| ].map(escape).join(','))); | |
| const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' }); | |
| const link = document.createElement('a'); | |
| link.href = URL.createObjectURL(blob); link.download = filename; link.click(); URL.revokeObjectURL(link.href); | |
| } | |