Kais Radwan
commited on
Commit
·
ca22f99
1
Parent(s):
0d83adb
Updated usage in README
Browse files
README.md
CHANGED
|
@@ -9,7 +9,7 @@ language:
|
|
| 9 |
license: mit
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
# gte-small
|
| 15 |
|
|
@@ -43,43 +43,10 @@ We compared the performance of the GTE models with other popular text embedding
|
|
| 43 |
|
| 44 |
## Usage
|
| 45 |
|
| 46 |
-
### Node JS
|
| 47 |
-
|
| 48 |
-
first install transformers.js using `npm i @xenova/transformers`.
|
| 49 |
-
|
| 50 |
-
```javascript
|
| 51 |
-
import { env, pipeline } from '@xenova/transformers'
|
| 52 |
-
|
| 53 |
-
(async () => {
|
| 54 |
-
// Give it any input you want
|
| 55 |
-
const input = "Hello AI";
|
| 56 |
-
|
| 57 |
-
// Create the pipeline
|
| 58 |
-
const pipe = await pipeline(
|
| 59 |
-
"feature-extraction",
|
| 60 |
-
"koxy-ai/gte-small"
|
| 61 |
-
);
|
| 62 |
-
|
| 63 |
-
// Generate the embedding
|
| 64 |
-
const output = await pipe(input, {
|
| 65 |
-
pooling: "mean",
|
| 66 |
-
normalize: true
|
| 67 |
-
});
|
| 68 |
-
|
| 69 |
-
// Extract the embedding from the output
|
| 70 |
-
const embedding = Array.from(output.data);
|
| 71 |
-
|
| 72 |
-
// Do anything with the embedding
|
| 73 |
-
console.log(embedding);
|
| 74 |
-
});
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
### Deno
|
| 78 |
|
| 79 |
-
No need to install anything.
|
| 80 |
-
|
| 81 |
```javascript
|
| 82 |
-
import { env, pipeline } from
|
| 83 |
|
| 84 |
// Some config for Deno
|
| 85 |
env.useBrowserCache = false;
|
|
@@ -107,6 +74,68 @@ const embedding = Array.from(output.data);
|
|
| 107 |
console.log(embedding);
|
| 108 |
```
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
### Limitation
|
| 111 |
|
| 112 |
This model exclusively caters to English texts, and any lengthy texts will be truncated to a maximum of 512 tokens.
|
|
|
|
| 9 |
license: mit
|
| 10 |
---
|
| 11 |
|
| 12 |
+
_Fork of [thenlper/gte-small](huggingface.co/thenlper/gte-small) with ONNX to work with Transformers.js.
|
| 13 |
|
| 14 |
# gte-small
|
| 15 |
|
|
|
|
| 43 |
|
| 44 |
## Usage
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
### Deno
|
| 47 |
|
|
|
|
|
|
|
| 48 |
```javascript
|
| 49 |
+
import { env, pipeline } from "https://cdn.jsdelivr.net/npm/@xenova/[email protected]";
|
| 50 |
|
| 51 |
// Some config for Deno
|
| 52 |
env.useBrowserCache = false;
|
|
|
|
| 74 |
console.log(embedding);
|
| 75 |
```
|
| 76 |
|
| 77 |
+
### Browser
|
| 78 |
+
Using Javascript modules.
|
| 79 |
+
```javascript
|
| 80 |
+
<script type="module">
|
| 81 |
+
|
| 82 |
+
import { pipeline } from "https://cdn.jsdelivr.net/npm/@xenova/[email protected]";
|
| 83 |
+
|
| 84 |
+
// Create the pipeline
|
| 85 |
+
const setPipe = async () => {
|
| 86 |
+
return await pipeline(
|
| 87 |
+
"feature-extraction",
|
| 88 |
+
"koxy-ai/gte-small"
|
| 89 |
+
);
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
const generateEmbedding = async (input) => {
|
| 93 |
+
const pipe = await setPipe();
|
| 94 |
+
const output = await pipe(input, {
|
| 95 |
+
pooling: "mean",
|
| 96 |
+
normalize: true
|
| 97 |
+
});
|
| 98 |
+
return Array.from(output.data);
|
| 99 |
+
};
|
| 100 |
+
|
| 101 |
+
export default generateEmbedding;
|
| 102 |
+
|
| 103 |
+
</script>
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
### Node JS
|
| 107 |
+
|
| 108 |
+
```bash
|
| 109 |
+
npm i @xenova/transformers
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
```javascript
|
| 113 |
+
import { pipeline } from "@xenova/transformers";
|
| 114 |
+
|
| 115 |
+
(async () => {
|
| 116 |
+
// Give it any input you want
|
| 117 |
+
const input = "Hello AI";
|
| 118 |
+
|
| 119 |
+
// Create the pipeline
|
| 120 |
+
const pipe = await pipeline(
|
| 121 |
+
"feature-extraction",
|
| 122 |
+
"koxy-ai/gte-small"
|
| 123 |
+
);
|
| 124 |
+
|
| 125 |
+
// Generate the embedding
|
| 126 |
+
const output = await pipe(input, {
|
| 127 |
+
pooling: "mean",
|
| 128 |
+
normalize: true
|
| 129 |
+
});
|
| 130 |
+
|
| 131 |
+
// Extract the embedding from the output
|
| 132 |
+
const embedding = Array.from(output.data);
|
| 133 |
+
|
| 134 |
+
// Do anything with the embedding
|
| 135 |
+
console.log(embedding);
|
| 136 |
+
})();
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
### Limitation
|
| 140 |
|
| 141 |
This model exclusively caters to English texts, and any lengthy texts will be truncated to a maximum of 512 tokens.
|