Update README.md
Browse files
README.md
CHANGED
|
@@ -4,4 +4,38 @@ library_name: transformers.js
|
|
| 4 |
|
| 5 |
https://huggingface.co/cross-encoder/ms-marco-MiniLM-L-12-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-MiniLM-L-12-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-MiniLM-L-12-v2`.
|
| 15 |
+
```js
|
| 16 |
+
import { AutoTokenizer, AutoModelForSequenceClassification } from '@xenova/transformers';
|
| 17 |
+
|
| 18 |
+
const model = await AutoModelForSequenceClassification.from_pretrained('Xenova/ms-marco-MiniLM-L-12-v2');
|
| 19 |
+
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/ms-marco-MiniLM-L-12-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: [ 9.597102165222168, -11.141762733459473 ]
|
| 36 |
+
// unquantized: [ 9.450557708740234, -11.160483360290527 ]
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
---
|
| 40 |
+
|
| 41 |
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`).
|