Xenova HF staff commited on
Commit
015e1c9
1 Parent(s): f802600

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -0
README.md CHANGED
@@ -4,4 +4,39 @@ library_name: transformers.js
4
 
5
  https://huggingface.co/cross-encoder/ms-marco-TinyBERT-L-2-v2 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/cross-encoder/ms-marco-TinyBERT-L-2-v2 with ONNX weights to be compatible with Transformers.js.
6
 
7
+ ## Usage (Transformers.js)
8
+
9
+ 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:
10
+ ```bash
11
+ npm i @xenova/transformers
12
+ ```
13
+
14
+ **Example:** Information Retrieval w/ `Xenova/ms-marco-TinyBERT-L-2-v2`.
15
+ ```js
16
+ import { AutoTokenizer, AutoModelForSequenceClassification } from '@xenova/transformers';
17
+
18
+ const model = await AutoModelForSequenceClassification.from_pretrained('Xenova/ms-marco-TinyBERT-L-2-v2');
19
+ const tokenizer = await AutoTokenizer.from_pretrained('Xenova/ms-marco-TinyBERT-L-2-v2');
20
+
21
+ const features = tokenizer(
22
+ ['How many people live in Berlin?', 'How many people live in Berlin?'],
23
+ {
24
+ text_pair: [
25
+ 'Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.',
26
+ 'New York City is famous for the Metropolitan Museum of Art.',
27
+ ],
28
+ padding: true,
29
+ truncation: true,
30
+ }
31
+ )
32
+
33
+ const scores = await model(features)
34
+ console.log(scores);
35
+ // quantized: [ 7.210887908935547, -11.559350967407227 ]
36
+ // unquantized: [ 7.235750675201416, -11.562294006347656 ]
37
+ ```
38
+
39
+ ---
40
+
41
+
42
  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`).