Learning Transformers.js

October 26, 2025 · View on GitHub

Just one of the things I'm learning. https://github.com/hchiam/learning

https://huggingface.co/docs/transformers.js

https://github.com/huggingface/transformers

import { pipeline } from '@huggingface/transformers';
const type = 'sentiment-analysis';
const pipe = await pipeline(type);
const out = await pipe('I love transformers!');
console.log(out);

Notes on [Transformers.js: State-of-the-art Machine Learning for the web](https://www.youtube.com/watch?v=n18Lrbo8VU8] video

import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.8.0';
const type = 'automatic-speech-recognition';
const model = 'Xenova/whisper-tiny.en';
const transcriber = await pipeline(type, model, /* { device: 'webgpu', } */);
const file = 'mlk.wav';
const output = await transcriber(file);
console.log(output);
// continuing the code above
const outputWithWordLevelTimestamps = await transcriber('mlk.wav', { return_timestamps: 'word' });
console.log(outputWithWordLevelTimestamps);