Transformers.js v2 -> v3
#2
by
Xenova
HF Staff
- opened
README.md
CHANGED
|
@@ -7,15 +7,15 @@ https://huggingface.co/thenlper/gte-small with ONNX weights to be compatible wit
|
|
| 7 |
|
| 8 |
## Usage (Transformers.js)
|
| 9 |
|
| 10 |
-
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/@
|
| 11 |
```bash
|
| 12 |
-
npm i @
|
| 13 |
```
|
| 14 |
|
| 15 |
You can then use the model to compute embeddings like this:
|
| 16 |
|
| 17 |
```js
|
| 18 |
-
import { pipeline } from '@
|
| 19 |
|
| 20 |
// Create a feature-extraction pipeline
|
| 21 |
const extractor = await pipeline('feature-extraction', 'Xenova/gte-small');
|
|
@@ -32,7 +32,7 @@ console.log(output);
|
|
| 32 |
// }
|
| 33 |
|
| 34 |
// Compute cosine similarity
|
| 35 |
-
import { cos_sim } from '@
|
| 36 |
console.log(cos_sim(output[0].data, output[1].data))
|
| 37 |
// 0.9798319649182318
|
| 38 |
```
|
|
@@ -46,9 +46,9 @@ console.log(output.tolist());
|
|
| 46 |
// ]
|
| 47 |
```
|
| 48 |
|
| 49 |
-
By default, an 8-bit quantized version of the model is used, but you can choose to use the full-precision (fp32) version by specifying `{
|
| 50 |
```js
|
| 51 |
-
const extractor = await pipeline('feature-extraction', 'Xenova/gte-small', {
|
| 52 |
```
|
| 53 |
|
| 54 |
---
|
|
|
|
| 7 |
|
| 8 |
## Usage (Transformers.js)
|
| 9 |
|
| 10 |
+
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:
|
| 11 |
```bash
|
| 12 |
+
npm i @huggingface/transformers
|
| 13 |
```
|
| 14 |
|
| 15 |
You can then use the model to compute embeddings like this:
|
| 16 |
|
| 17 |
```js
|
| 18 |
+
import { pipeline } from '@huggingface/transformers';
|
| 19 |
|
| 20 |
// Create a feature-extraction pipeline
|
| 21 |
const extractor = await pipeline('feature-extraction', 'Xenova/gte-small');
|
|
|
|
| 32 |
// }
|
| 33 |
|
| 34 |
// Compute cosine similarity
|
| 35 |
+
import { cos_sim } from '@huggingface/transformers';
|
| 36 |
console.log(cos_sim(output[0].data, output[1].data))
|
| 37 |
// 0.9798319649182318
|
| 38 |
```
|
|
|
|
| 46 |
// ]
|
| 47 |
```
|
| 48 |
|
| 49 |
+
By default, an 8-bit quantized version of the model is used, but you can choose to use the full-precision (fp32) version by specifying `{ dtype: 'fp32' }` in the `pipeline` function:
|
| 50 |
```js
|
| 51 |
+
const extractor = await pipeline('feature-extraction', 'Xenova/gte-small', { dtype: 'fp32' });
|
| 52 |
```
|
| 53 |
|
| 54 |
---
|