Update to Transformers.js v3
Browse files
README.md
CHANGED
@@ -8,13 +8,18 @@ https://huggingface.co/jinaai/jina-embeddings-v2-small-en with ONNX weights to b
|
|
8 |
|
9 |
## Usage with 🤗 Transformers.js
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
```js
|
12 |
-
|
13 |
-
import { pipeline, cos_sim } from '@xenova/transformers';
|
14 |
|
15 |
// Create feature extraction pipeline
|
16 |
const extractor = await pipeline('feature-extraction', 'Xenova/jina-embeddings-v2-small-en',
|
17 |
-
{
|
18 |
);
|
19 |
|
20 |
// Generate embeddings
|
@@ -27,4 +32,6 @@ const output = await extractor(
|
|
27 |
console.log(cos_sim(output[0].data, output[1].data)); // 0.9399812684139274 (unquantized) vs. 0.9341121503699659 (quantized)
|
28 |
```
|
29 |
|
|
|
|
|
30 |
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`).
|
|
|
8 |
|
9 |
## Usage with 🤗 Transformers.js
|
10 |
|
11 |
+
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/@huggingface/transformers) using:
|
12 |
+
```bash
|
13 |
+
npm i @huggingface/transformers
|
14 |
+
```
|
15 |
+
|
16 |
+
You can then use the model as follows:
|
17 |
```js
|
18 |
+
import { pipeline, cos_sim } from '@huggingface/transformers';
|
|
|
19 |
|
20 |
// Create feature extraction pipeline
|
21 |
const extractor = await pipeline('feature-extraction', 'Xenova/jina-embeddings-v2-small-en',
|
22 |
+
{ dtype: "fp32" } // Options: "fp32", "fp16", "q8", "q4"
|
23 |
);
|
24 |
|
25 |
// Generate embeddings
|
|
|
32 |
console.log(cos_sim(output[0].data, output[1].data)); // 0.9399812684139274 (unquantized) vs. 0.9341121503699659 (quantized)
|
33 |
```
|
34 |
|
35 |
+
---
|
36 |
+
|
37 |
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`).
|