Xenova HF Staff commited on
Commit
d888829
·
verified ·
1 Parent(s): 63aa41e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -1
README.md CHANGED
@@ -30,4 +30,42 @@ datasets:
30
  - embedding-data/WikiAnswers
31
  tags:
32
  - feature-extraction
33
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  - embedding-data/WikiAnswers
31
  tags:
32
  - feature-extraction
33
+ ---
34
+
35
+ https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2 with ONNX weights to be compatible with Transformers.js.
36
+
37
+ ## Usage (Transformers.js)
38
+
39
+ 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:
40
+ ```bash
41
+ npm i @huggingface/transformers
42
+ ```
43
+
44
+ You can then use the model to compute embeddings like this:
45
+
46
+ ```js
47
+ import { pipeline } from '@huggingface/transformers';
48
+
49
+ // Create a feature-extraction pipeline
50
+ const extractor = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2');
51
+
52
+ // Compute sentence embeddings
53
+ const sentences = ['This is an example sentence', 'Each sentence is converted'];
54
+ const output = await extractor(sentences, { pooling: 'mean', normalize: true });
55
+ console.log(output);
56
+ // Tensor {
57
+ // dims: [ 2, 384 ],
58
+ // type: 'float32',
59
+ // data: Float32Array(768) [ 0.04592696577310562, 0.07328180968761444, ... ],
60
+ // size: 768
61
+ // }
62
+ ```
63
+
64
+ You can convert this Tensor to a nested JavaScript array using `.tolist()`:
65
+ ```js
66
+ console.log(output.tolist());
67
+ // [
68
+ // [ 0.04592696577310562, 0.07328180968761444, 0.05400655046105385, ... ],
69
+ // [ 0.08188057690858841, 0.10760223120450974, -0.013241755776107311, ... ]
70
+ // ]
71
+ ```