File size: 7,107 Bytes
795f800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39b5722
795f800
 
52b9509
 
795f800
 
 
 
 
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52b9509
 
795f800
 
 
 
 
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
52b9509
795f800
 
 
 
 
763d116
795f800
ebeede7
 
 
9389a36
f1a407c
3a86fba
f1a407c
9389a36
 
 
 
 
 
 
ebeede7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ddf73b
 
ebeede7
 
69c3963
 
 
ebeede7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1a407c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
---
base_model: FacebookAI/xlm-roberta-large
library_name: sentence-transformers
metrics:
- pearson_cosine
- spearman_cosine
- pearson_manhattan
- spearman_manhattan
- pearson_euclidean
- spearman_euclidean
- pearson_dot
- spearman_dot
- pearson_max
- spearman_max
pipeline_tag: sentence-similarity
tags:
- sentence-transformers
- sentence-similarity
- feature-extraction
- mteb
- bilingual
model-index:
- name: omarelshehy/arabic-english-sts-matryoshka
  results:
  - dataset:
      config: en-en
      name: MTEB STS17 (en-en)
      revision: faeb762787bd10488a50c8b5be4a3b82e411949c
      split: test
      type: mteb/sts17-crosslingual-sts
    metrics:
    - type: cosine_pearson
      value: 87.17053120821998
    - type: cosine_spearman
      value: 87.05959159411456
    - type: euclidean_pearson
      value: 87.63706739480517
    - type: euclidean_spearman
      value: 87.7675347222274
    - type: main_score
      value: 87.05959159411456
    - type: manhattan_pearson
      value: 87.7006832512623
    - type: manhattan_spearman
      value: 87.80128473941168
    - type: pearson
      value: 87.17053012311975
    - type: spearman
      value: 87.05959159411456
    task:
      type: STS
  - dataset:
      config: ar-ar
      name: MTEB STS17 (ar-ar)
      revision: faeb762787bd10488a50c8b5be4a3b82e411949c
      split: test
      type: mteb/sts17-crosslingual-sts
    metrics:
    - type: cosine_pearson
      value: 82.22889478671283
    - type: cosine_spearman
      value: 83.0533648934447
    - type: euclidean_pearson
      value: 81.15891941165452
    - type: euclidean_spearman
      value: 82.14034597386936
    - type: main_score
      value: 83.0533648934447
    - type: manhattan_pearson
      value: 81.17463976232014
    - type: manhattan_spearman
      value: 82.09804987736345
    - type: pearson
      value: 82.22889389569819
    - type: spearman
      value: 83.0529662284269
    task:
      type: STS
  - dataset:
      config: en-ar
      name: MTEB STS17 (en-ar)
      revision: faeb762787bd10488a50c8b5be4a3b82e411949c
      split: test
      type: mteb/sts17-crosslingual-sts
    metrics:
    - type: cosine_pearson
      value: 79.79480510851795
    - type: cosine_spearman
      value: 79.67609346073252
    - type: euclidean_pearson
      value: 81.64087935350051
    - type: euclidean_spearman
      value: 80.52588414802709
    - type: main_score
      value: 79.67609346073252
    - type: manhattan_pearson
      value: 81.57042957417305
    - type: manhattan_spearman
      value: 80.44331526051143
    - type: pearson
      value: 79.79480418294698
    - type: spearman
      value: 79.67609346073252
    task:
      type: STS
language:
- ar
- en
license: apache-2.0
---

# SentenceTransformer based on FacebookAI/xlm-roberta-large

This is a **Bilingual** (Arabic-English) [sentence-transformers](https://www.SBERT.net) model finetuned from [FacebookAI/xlm-roberta-large](https://huggingface.co/FacebookAI/xlm-roberta-large). It maps sentences & paragraphs to a 1024-dimensional dense vector space and can be used for **semantic textual similarity, semantic search, paraphrase mining, text classification, clustering**, and more.

The model handles both languages separately 🌐, but also **interchangeably**, which unlocks flexible applications for developers and researchers who want to further build on Arabic models! 💡

📊 Metrics from MTEB are promising, but don't just rely on them — test the model yourself and see if it fits your needs! ✅

## Matryoshka Embeddings 🪆 

This model supports Matryoshka embeddings, allowing you to truncate embeddings into smaller sizes to optimize performance and memory usage, based on your task requirements. Available truncation sizes include: **1024, 768, 512, 256, 128, and 64**

You can select the appropriate embedding size for your use case, ensuring flexibility in resource management.

## Model Details

### Model Description
- **Model Type:** Sentence Transformer
- **Base model:** [FacebookAI/xlm-roberta-large](https://huggingface.co/FacebookAI/xlm-roberta-large) <!-- at revision c23d21b0620b635a76227c604d44e43a9f0ee389 -->
- **Maximum Sequence Length:** 512 tokens
- **Output Dimensionality:** 1024 tokens
- **Similarity Function:** Cosine Similarity
<!-- - **Training Dataset:** Unknown -->
<!-- - **Language:** Unknown -->
<!-- - **License:** Unknown -->



## Usage

### Direct Usage (Sentence Transformers)

First install the Sentence Transformers library:

```bash
pip install -U sentence-transformers
```

Then you can load this model and run inference.
```python
from sentence_transformers import SentenceTransformer

# Download from the 🤗 Hub
matryoshka_dim = 786
model = SentenceTransformer("omarelshehy/arabic-english-sts-matryoshka", truncate_dim=matryoshka_dim)
# Run inference
sentences = [
    "She enjoyed reading books by the window as the rain poured outside.",
    "كانت تستمتع بقراءة الكتب بجانب النافذة بينما كانت الأمطار تتساقط في الخارج.",
    "Reading by the window was her favorite thing, especially during rainy days."
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 1024]

# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [3, 3]
```

<!--
### Direct Usage (Transformers)

<details><summary>Click to see the direct usage in Transformers</summary>

</details>
-->

<!--
### Downstream Usage (Sentence Transformers)

You can finetune this model on your own dataset.

<details><summary>Click to expand</summary>

</details>
-->

<!--
### Out-of-Scope Use

*List how the model may foreseeably be misused and address what users ought not to do with the model.*
-->


## Citation

### BibTeX

#### Sentence Transformers
```bibtex
@inproceedings{reimers-2019-sentence-bert,
    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
    author = "Reimers, Nils and Gurevych, Iryna",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
    month = "11",
    year = "2019",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/1908.10084",
}
```

#### MatryoshkaLoss
```bibtex
@misc{kusupati2024matryoshka,
    title={Matryoshka Representation Learning},
    author={Aditya Kusupati and Gantavya Bhatt and Aniket Rege and Matthew Wallingford and Aditya Sinha and Vivek Ramanujan and William Howard-Snyder and Kaifeng Chen and Sham Kakade and Prateek Jain and Ali Farhadi},
    year={2024},
    eprint={2205.13147},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}
```

#### MultipleNegativesRankingLoss
```bibtex
@misc{henderson2017efficient,
    title={Efficient Natural Language Response Suggestion for Smart Reply},
    author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
    year={2017},
    eprint={1705.00652},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}
```