Update README.md
Browse files
README.md
CHANGED
@@ -4,4 +4,36 @@ library_name: "transformers.js"
|
|
4 |
|
5 |
https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english with ONNX weights to be compatible with Transformers.js.
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|
|
|
4 |
|
5 |
https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english with ONNX weights to be compatible with Transformers.js.
|
6 |
|
7 |
+
|
8 |
+
## Usage (Transformers.js)
|
9 |
+
|
10 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@xenova/transformers) using:
|
11 |
+
```bash
|
12 |
+
npm i @xenova/transformers
|
13 |
+
```
|
14 |
+
|
15 |
+
You can then use the model to classify text like this:
|
16 |
+
|
17 |
+
```js
|
18 |
+
import { pipeline } from "@xenova/transformers";
|
19 |
+
|
20 |
+
// Create a sentiment analysis pipeline
|
21 |
+
const classifier = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');
|
22 |
+
|
23 |
+
// Classify input text
|
24 |
+
const output = await classifier('I love transformers!');
|
25 |
+
console.log(output);
|
26 |
+
// [{ label: 'POSITIVE', score: 0.999788761138916 }]
|
27 |
+
|
28 |
+
// Classify input text (and return all classes)
|
29 |
+
const output2 = await classifier('I love transformers!', { topk: null });
|
30 |
+
console.log(output2);
|
31 |
+
// [
|
32 |
+
// { label: 'POSITIVE', score: 0.999788761138916 },
|
33 |
+
// { label: 'NEGATIVE', score: 0.00021126774663571268 }
|
34 |
+
// ]
|
35 |
+
```
|
36 |
+
|
37 |
+
---
|
38 |
+
|
39 |
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|