Update README.md
Browse files
README.md
CHANGED
|
@@ -5,4 +5,25 @@ pipeline_tag: feature-extraction
|
|
| 5 |
|
| 6 |
https://huggingface.co/jinaai/jina-embeddings-v2-small-en with ONNX weights to be compatible with Transformers.js.
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
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`).
|
|
|
|
| 5 |
|
| 6 |
https://huggingface.co/jinaai/jina-embeddings-v2-small-en with ONNX weights to be compatible with Transformers.js.
|
| 7 |
|
| 8 |
+
## Usage with 🤗 Transformers.js
|
| 9 |
+
|
| 10 |
+
```js
|
| 11 |
+
// npm i @xenova/transformers
|
| 12 |
+
import { pipeline, cos_sim } from '@xenova/transformers';
|
| 13 |
+
|
| 14 |
+
// Create feature extraction pipeline
|
| 15 |
+
const extractor = await pipeline('feature-extraction', 'Xenova/jina-embeddings-v2-small-en',
|
| 16 |
+
{ quantized: false } // Comment out this line to use the quantized version
|
| 17 |
+
);
|
| 18 |
+
|
| 19 |
+
// Generate embeddings
|
| 20 |
+
const output = await extractor(
|
| 21 |
+
['How is the weather today?', 'What is the current weather like today?'],
|
| 22 |
+
{ pooling: 'mean' }
|
| 23 |
+
);
|
| 24 |
+
|
| 25 |
+
// Compute cosine similarity
|
| 26 |
+
console.log(cos_sim(output[0].data, output[1].data)); // 0.9399812684139274 (unquantized) vs. 0.9341121503699659 (quantized)
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
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`).
|