numb3r3 Xenova HF staff commited on
Commit
298e48c
1 Parent(s): 8469b0a

Upload ONNX weights (+ Transformers.js integration) (#9)

Browse files

- Upload ONNX weights (+ Transformers.js integration) (04f011c37c844fe7514ee242bd3a41ace9e3b084)
- Update README.md (104f50512c622895d71e59ecc24d59912e0eb4d2)
- Update README.md (97c3b9990f31dc030c2594a2730240bbcaa5670f)
- Update README.md (43e15cb1bc6ba7205d428f3f3776be94d1a25d45)
- Update README.md (c1b09b142ab8261a338eae36ae79afb83a2f0a32)


Co-authored-by: Joshua <Xenova@users.noreply.huggingface.co>

README.md CHANGED
@@ -4,6 +4,7 @@ tags:
4
  - transformers
5
  - reranker
6
  - cross-encoder
 
7
  language:
8
  - multilingual
9
  inference: false
@@ -127,6 +128,67 @@ pip install flash-attn --no-build-isolation
127
  ```
128
  Enjoy the 3x-6x speedup with flash attention! ⚡️⚡️⚡️
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  That's it! You can now use the `jina-reranker-v2-base-multilingual` model in your projects.
131
 
132
 
 
4
  - transformers
5
  - reranker
6
  - cross-encoder
7
+ - transformers.js
8
  language:
9
  - multilingual
10
  inference: false
 
128
  ```
129
  Enjoy the 3x-6x speedup with flash attention! ⚡️⚡️⚡️
130
 
131
+
132
+ 3. You can also use the `transformers.js` library to run the model directly in JavaScript (in-browser, Node.js, Deno, etc.)!
133
+
134
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library (v3) using:
135
+ ```bash
136
+ npm i xenova/transformers.js#v3
137
+ ```
138
+
139
+ Then, you can use the following code to interact with the model:
140
+ ```js
141
+ import { AutoTokenizer, XLMRobertaModel } from '@xenova/transformers';
142
+
143
+ const model_id = 'jinaai/jina-reranker-v2-base-multilingual';
144
+ const model = await XLMRobertaModel.from_pretrained(model_id, { dtype: 'fp32' });
145
+ const tokenizer = await AutoTokenizer.from_pretrained(model_id);
146
+
147
+ /**
148
+ * Performs ranking with the CrossEncoder on the given query and documents. Returns a sorted list with the document indices and scores.
149
+ * @param {string} query A single query
150
+ * @param {string[]} documents A list of documents
151
+ * @param {Object} options Options for ranking
152
+ * @param {number} [options.top_k=undefined] Return the top-k documents. If undefined, all documents are returned.
153
+ * @param {number} [options.return_documents=false] If true, also returns the documents. If false, only returns the indices and scores.
154
+ */
155
+ async function rank(query, documents, {
156
+ top_k = undefined,
157
+ return_documents = false,
158
+ } = {}) {
159
+ const inputs = tokenizer(
160
+ new Array(documents.length).fill(query),
161
+ { text_pair: documents, padding: true, truncation: true }
162
+ )
163
+ const { logits } = await model(inputs);
164
+ return logits.sigmoid().tolist()
165
+ .map(([score], i) => ({
166
+ corpus_id: i,
167
+ score,
168
+ ...(return_documents ? { text: documents[i] } : {})
169
+ })).sort((a, b) => b.score - a.score).slice(0, top_k);
170
+ }
171
+
172
+ // Example usage:
173
+ const query = "Organic skincare products for sensitive skin"
174
+ const documents = [
175
+ "Organic skincare for sensitive skin with aloe vera and chamomile.",
176
+ "New makeup trends focus on bold colors and innovative techniques",
177
+ "Bio-Hautpflege für empfindliche Haut mit Aloe Vera und Kamille",
178
+ "Neue Make-up-Trends setzen auf kräftige Farben und innovative Techniken",
179
+ "Cuidado de la piel orgánico para piel sensible con aloe vera y manzanilla",
180
+ "Las nuevas tendencias de maquillaje se centran en colores vivos y técnicas innovadoras",
181
+ "针对敏感肌专门设计的天然有机护肤产品",
182
+ "新的化妆趋势注重鲜艳的颜色和创新的技巧",
183
+ "敏感肌のために特別に設計された天然有機スキンケア製品",
184
+ "新しいメイクのトレンドは鮮やかな色と革新的な技術に焦点を当てています",
185
+ ]
186
+
187
+ const results = await rank(query, documents, { return_documents: true, top_k: 3 });
188
+ console.log(results);
189
+ ```
190
+
191
+
192
  That's it! You can now use the `jina-reranker-v2-base-multilingual` model in your projects.
193
 
194
 
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ef3f7978f7bc52360864d74edc1a0e03d159af770a7767c4d5943496e616012
3
+ size 1114040223
onnx/model_bnb4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df70759eb3ebb4e96b7d82e9af1e99c4979f76b96205ea18dddb101d32b07f80
3
+ size 822084838
onnx/model_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ad94bcc1d7313ec5f76e18de8ffa7469e3f34b76810b8fd7206619b9cde1bc4
3
+ size 557164815
onnx/model_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5220cf8fe023f8aa0ed2a3eb787d4451a7f17cf53f6b787e35718dd4b8815c3
3
+ size 279577152
onnx/model_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a3744ee702adeb08230fba13258cc4ad441b73310a1060df2066bebbda080de7
3
+ size 827392882
onnx/model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5220cf8fe023f8aa0ed2a3eb787d4451a7f17cf53f6b787e35718dd4b8815c3
3
+ size 279577152
onnx/model_uint8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9498f606988b84e23b98d04101f3623c084baf3f1e16fd43a46ea6259b4f5924
3
+ size 279577151