Files
church-translate/app/_probe-book.mjs
T

33 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

import { pipeline, env } from '@huggingface/transformers';
import os from 'os'; import path from 'path';
env.allowLocalModels=false;
env.cacheDir=path.join(os.homedir(),'Library/Application Support/Church Translate Models');
const pipe=await pipeline('translation','Xenova/nllb-200-distilled-600M',{dtype:'fp32'});
const PHRASINGS=[
'Open up to the book of John.',
'Open to the book of John.',
'Turn to the book of John.',
'Turn with me to the book of John.',
'Go to the book of John.',
'Open your Bibles to the book of John.',
'The book of John chapter three.',
'In the book of Romans Paul writes this.',
'Read the book of Genesis with me.',
'This is a test of the names Jacob, Peter, John.',
'Jacob, Peter and John were there.',
'The names are Jacob, Peter and John.'
];
console.log('=== SPANISH: which phrasings get "libro" and which get "obra"? ===');
for (const t of PHRASINGS) {
const o=await pipe(t,{src_lang:'eng_Latn',tgt_lang:'spa_Latn'});
const s=(Array.isArray(o)?o[0]:o).translation_text.trim();
const flag=/\bobra/i.test(s)?' <-- OBRA (wrong)':(/\blibro/i.test(s)?' libro OK':'');
console.log(' '+t+'\n '+s+flag);
}
console.log('\n=== "the book of X" across the served languages ===');
for (const lang of ['spa_Latn','por_Latn','fra_Latn','zho_Hans','kor_Hang','vie_Latn','hat_Latn','arb_Arab','hin_Deva']) {
const o=await pipe('Open up to the book of John.',{src_lang:'eng_Latn',tgt_lang:lang});
console.log(' '+lang+' '+(Array.isArray(o)?o[0]:o).translation_text.trim());
}