Upload README.md
Browse files
README.md
CHANGED
|
@@ -103,15 +103,22 @@ for i, query in enumerate(queries):
|
|
| 103 |
print(f"Query: {query}")
|
| 104 |
for j, doc in enumerate(documents):
|
| 105 |
print(f" Similarity: {scores[i, j]:.4f} | Document {j}: {doc[:80]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
# Query: What is machine learning?
|
| 108 |
-
# Similarity: 0.6857 | Document 0: Machine learning is a subset of ...
|
| 109 |
-
# Similarity: 0.4598 | Document 1: Neural networks are trained ...
|
| 110 |
-
#
|
| 111 |
-
# Query: How does neural network training work?
|
| 112 |
-
# Similarity: 0.4238 | Document 0: Machine learning is a subset of ...
|
| 113 |
-
# Similarity: 0.5723 | Document 1: Neural networks are trained ...
|
| 114 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
## Transformers.js
|
| 117 |
|
|
@@ -216,13 +223,20 @@ similarities = model.similarity(query_embeds, doc_embeds)
|
|
| 216 |
print('After MRL:')
|
| 217 |
print(f"* Embeddings dimension: {query_embeds.shape[1]}")
|
| 218 |
print(f"* Similarities: \n\t{similarities}")
|
|
|
|
| 219 |
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
```
|
|
|
|
| 226 |
|
| 227 |
## Vector Quantization
|
| 228 |
Vector quantization, for example to `int8` or `binary`, can be performed as follows:
|
|
@@ -257,6 +271,19 @@ print(f"* Similarities: \n{similarities}")
|
|
| 257 |
# [ 72961 98333]]
|
| 258 |
```
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
# Evaluation
|
| 261 |
|
| 262 |
Please [see here](https://huggingface.co/MongoDB/mdbr-leaf-ir/blob/main/evaluate_models.ipynb).
|
|
|
|
| 103 |
print(f"Query: {query}")
|
| 104 |
for j, doc in enumerate(documents):
|
| 105 |
print(f" Similarity: {scores[i, j]:.4f} | Document {j}: {doc[:80]}...")
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
<details>
|
| 109 |
+
|
| 110 |
+
<summary>See example output</summary>
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
```
|
| 113 |
+
Query: What is machine learning?
|
| 114 |
+
Similarity: 0.6857 | Document 0: Machine learning is a subset of ...
|
| 115 |
+
Similarity: 0.4598 | Document 1: Neural networks are trained ...
|
| 116 |
+
|
| 117 |
+
Query: How does neural network training work?
|
| 118 |
+
Similarity: 0.4238 | Document 0: Machine learning is a subset of ...
|
| 119 |
+
Similarity: 0.5723 | Document 1: Neural networks are trained ...
|
| 120 |
+
```
|
| 121 |
+
</details>
|
| 122 |
|
| 123 |
## Transformers.js
|
| 124 |
|
|
|
|
| 223 |
print('After MRL:')
|
| 224 |
print(f"* Embeddings dimension: {query_embeds.shape[1]}")
|
| 225 |
print(f"* Similarities: \n\t{similarities}")
|
| 226 |
+
```
|
| 227 |
|
| 228 |
+
<details>
|
| 229 |
+
|
| 230 |
+
<summary>See example output</summary>
|
| 231 |
+
|
| 232 |
+
```
|
| 233 |
+
After MRL:
|
| 234 |
+
* Embeddings dimension: 256
|
| 235 |
+
* Similarities:
|
| 236 |
+
tensor([[0.7136, 0.4989],
|
| 237 |
+
[0.4567, 0.6022]])
|
| 238 |
```
|
| 239 |
+
</details>
|
| 240 |
|
| 241 |
## Vector Quantization
|
| 242 |
Vector quantization, for example to `int8` or `binary`, can be performed as follows:
|
|
|
|
| 271 |
# [ 72961 98333]]
|
| 272 |
```
|
| 273 |
|
| 274 |
+
<details>
|
| 275 |
+
|
| 276 |
+
<summary>See example output</summary>
|
| 277 |
+
|
| 278 |
+
```
|
| 279 |
+
After quantization:
|
| 280 |
+
* Embeddings type: int8
|
| 281 |
+
* Similarities:
|
| 282 |
+
[[118022 79111]
|
| 283 |
+
[ 72961 98333]]
|
| 284 |
+
```
|
| 285 |
+
</details>
|
| 286 |
+
|
| 287 |
# Evaluation
|
| 288 |
|
| 289 |
Please [see here](https://huggingface.co/MongoDB/mdbr-leaf-ir/blob/main/evaluate_models.ipynb).
|