juliuslipp
commited on
Commit
•
acfe001
1
Parent(s):
4dc2fec
Update README.md
Browse files
README.md
CHANGED
@@ -2691,6 +2691,31 @@ similarities = cos_sim(embeddings[0], embeddings[1:])
|
|
2691 |
print('similarities:', similarities)
|
2692 |
```
|
2693 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2694 |
### Using API
|
2695 |
|
2696 |
You’ll be able to use the models through our API as well. The API is coming soon and will have some exciting features. Stay tuned!
|
|
|
2691 |
print('similarities:', similarities)
|
2692 |
```
|
2693 |
|
2694 |
+
### Transformers.js
|
2695 |
+
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:
|
2696 |
+
```bash
|
2697 |
+
npm i @xenova/transformers
|
2698 |
+
```
|
2699 |
+
You can then use the model to compute embeddings as follows:
|
2700 |
+
```js
|
2701 |
+
import { pipeline, cos_sim } from '@xenova/transformers';
|
2702 |
+
// Create a feature-extraction pipeline
|
2703 |
+
const extractor = await pipeline('feature-extraction', 'mixedbread-ai/mxbai-embed-2d-large-v1', {
|
2704 |
+
quantized: false, // (Optional) remove this line to use the 8-bit quantized model
|
2705 |
+
});
|
2706 |
+
|
2707 |
+
// Compute sentence embeddings (with `cls` pooling)
|
2708 |
+
const sentences = ['Who is german and likes bread?', 'Everybody in Germany.' ];
|
2709 |
+
const output = await extractor(sentences, { pooling: 'cls' });
|
2710 |
+
|
2711 |
+
// Set embedding size and truncate embeddings
|
2712 |
+
const new_embedding_size = 768;
|
2713 |
+
const truncated = output.slice(null, [0, new_embedding_size]);
|
2714 |
+
|
2715 |
+
// Compute cosine similarity
|
2716 |
+
console.log(cos_sim(truncated[0].data, truncated[1].data)); // 0.6979532021425204
|
2717 |
+
```
|
2718 |
+
|
2719 |
### Using API
|
2720 |
|
2721 |
You’ll be able to use the models through our API as well. The API is coming soon and will have some exciting features. Stay tuned!
|