14 lines
502 B
TypeScript
14 lines
502 B
TypeScript
import { pipeline } from '@xenova/transformers';
|
|
|
|
const [modelDir, model] = process.argv.slice(2);
|
|
|
|
let text = '';
|
|
process.stdin.on('data', chunk => text += chunk);
|
|
process.stdin.on('end', async () => {
|
|
const embedder = await pipeline('feature-extraction', 'Xenova/' + model, {quantized: true, cache_dir: modelDir});
|
|
const output = await embedder(text, { pooling: 'mean', normalize: true });
|
|
const embedding = Array.from(output.data);
|
|
console.log(JSON.stringify({embedding}));
|
|
process.exit();
|
|
});
|