Update README.md
Browse files
README.md
CHANGED
@@ -19,6 +19,46 @@ NeoBERT is a **next-generation encoder** model for English text representation,
|
|
19 |
|
20 |
## Usage
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
### ONNXRuntime
|
23 |
|
24 |
```py
|
|
|
19 |
|
20 |
## Usage
|
21 |
|
22 |
+
### Transformers.js
|
23 |
+
|
24 |
+
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:
|
25 |
+
```bash
|
26 |
+
npm i @huggingface/transformers
|
27 |
+
```
|
28 |
+
|
29 |
+
You can then compute embeddings using the pipeline API:
|
30 |
+
|
31 |
+
```js
|
32 |
+
import { pipeline } from "@huggingface/transformers";
|
33 |
+
|
34 |
+
// Create feature extraction pipeline
|
35 |
+
const extractor = await pipeline("feature-extraction", "onnx-community/NeoBERT-ONNX");
|
36 |
+
|
37 |
+
// Compute embeddings
|
38 |
+
const text = "NeoBERT is the most efficient model of its kind!";
|
39 |
+
const embedding = await extractor(text, { pooling: "cls" });
|
40 |
+
console.log(embedding.dims); // [1, 768]
|
41 |
+
```
|
42 |
+
|
43 |
+
Or manually with the model and tokenizer classes:
|
44 |
+
```js
|
45 |
+
import { AutoModel, AutoTokenizer } from "@huggingface/transformers";
|
46 |
+
|
47 |
+
// Load model and tokenizer
|
48 |
+
const model_id = "onnx-community/NeoBERT-ONNX";
|
49 |
+
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
|
50 |
+
const model = await AutoModel.from_pretrained(model_id);
|
51 |
+
|
52 |
+
// Tokenize input text
|
53 |
+
const text = "NeoBERT is the most efficient model of its kind!";
|
54 |
+
const inputs = tokenizer(text);
|
55 |
+
|
56 |
+
// Generate embeddings
|
57 |
+
const outputs = await model(inputs);
|
58 |
+
const embedding = outputs.last_hidden_state.slice(null, 0);
|
59 |
+
console.log(embedding.dims); // [1, 768]
|
60 |
+
```
|
61 |
+
|
62 |
### ONNXRuntime
|
63 |
|
64 |
```py
|