Update README.md
Browse files
README.md
CHANGED
@@ -1,7 +1,47 @@
|
|
1 |
---
|
2 |
library_name: transformers.js
|
|
|
3 |
---
|
4 |
|
5 |
https://huggingface.co/colbert-ir/colbertv2.0 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`).
|
|
|
1 |
---
|
2 |
library_name: transformers.js
|
3 |
+
pipeline_tag: feature-extraction
|
4 |
---
|
5 |
|
6 |
https://huggingface.co/colbert-ir/colbertv2.0 with ONNX weights to be compatible with Transformers.js.
|
7 |
|
8 |
+
|
9 |
+
## Usage (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/@xenova/transformers) using:
|
12 |
+
```bash
|
13 |
+
npm i @xenova/transformers
|
14 |
+
```
|
15 |
+
|
16 |
+
You can then use the model to compute embeddings like this:
|
17 |
+
|
18 |
+
```js
|
19 |
+
import { pipeline } from '@xenova/transformers';
|
20 |
+
|
21 |
+
// Create a feature-extraction pipeline
|
22 |
+
const extractor = await pipeline('feature-extraction', 'Xenova/colbertv2.0');
|
23 |
+
|
24 |
+
// Compute sentence embeddings
|
25 |
+
const sentences = ['Hello world', 'This is a sentence'];
|
26 |
+
const output = await extractor(sentences, { pooling: 'mean', normalize: true });
|
27 |
+
console.log(output);
|
28 |
+
// Tensor {
|
29 |
+
// dims: [ 2, 768 ],
|
30 |
+
// type: 'float32',
|
31 |
+
// data: Float32Array(768) [ -0.008133978582918644, 0.00663341861218214, ... ],
|
32 |
+
// size: 768
|
33 |
+
// }
|
34 |
+
```
|
35 |
+
|
36 |
+
You can convert this Tensor to a nested JavaScript array using `.tolist()`:
|
37 |
+
```js
|
38 |
+
console.log(output.tolist());
|
39 |
+
// [
|
40 |
+
// [ -0.008133978582918644, 0.00663341861218214, 0.06555338203907013, ... ],
|
41 |
+
// [ -0.02630571834743023, 0.011146597564220428, 0.008737687021493912, ... ]
|
42 |
+
// ]
|
43 |
+
```
|
44 |
+
|
45 |
+
---
|
46 |
+
|
47 |
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`).
|