Views
No views yet
npm i @huggingface/transformers1import { pipeline } from "@huggingface/transformers";
2
3// Create a sentiment analysis pipeline
4const classifier = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');
5
6// Classify input text
7const output = await classifier('I love transformers!');
8console.log(output);
9// [{ label: 'POSITIVE', score: 0.999788761138916 }]
10
11// Classify input text (and return all classes)
12const output2 = await classifier('I love transformers!', { top_k: null });
13console.log(output2);
14// [
15// { label: 'POSITIVE', score: 0.999788761138916 },
16// { label: 'NEGATIVE', score: 0.00021126774663571268 }
17// ]onnx).