
Transformers.js Has a Free API That Runs AI Models Directly in the Browser
Transformers.js brings Hugging Face models to JavaScript. Run NLP, vision, and audio models locally — no server, no API keys, no costs. Text Generation import { pipeline } from " @xenova/transformers " ; const generator = await pipeline ( " text-generation " , " Xenova/gpt2 " ); const result = await generator ( " The future of web scraping is " , { max_new_tokens : 100 , temperature : 0.7 , }); console . log ( result [ 0 ]. generated_text ); Sentiment Analysis const classifier = await pipeline ( " sentiment-analysis " ); const results = await classifier ([ " This product is amazing, best purchase ever! " , " Terrible quality, broke after one day. " , " It's okay, nothing special. " , ]); // [{ label: 'POSITIVE', score: 0.99 }, { label: 'NEGATIVE', score: 0.98 }, ...] Text Embeddings: Semantic Search const embedder = await pipeline ( " feature-extraction " , " Xenova/all-MiniLM-L6-v2 " ); const embedding1 = await embedder ( " web scraping tools " , { pooling : " mean " , normalize : tru
Continue reading on Dev.to Webdev
Opens in a new tab


