ghazal-zamani commited on
Commit
14dd09e
·
verified ·
1 Parent(s): c2834d8

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +163 -0
README.md ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - fa
4
+ library_name: sentence-transformers
5
+ pipeline_tag: sentence-similarity
6
+ tags:
7
+ - sentence-transformers
8
+ - sentence-similarity
9
+ - feature-extraction
10
+ - loss:CachedMultipleNegativesRankingLoss
11
+ widget:
12
+ - source_sentence: درنا از پرندگان مهاجر با پاهای بلند و گردن دراز است.
13
+ sentences:
14
+ - >-
15
+ درناها با قامتی بلند و بال‌های پهن، از زیباترین پرندگان مهاجر به شمار
16
+ می‌روند.
17
+ - درناها پرندگانی کوچک با پاهای کوتاه هستند که مهاجرت نمی‌کنند.
18
+ - ایران برای بار دیگر توانست به مدال طلا دست یابد.
19
+ - source_sentence: در زمستان هوای تهران بسیار آلوده است.
20
+ sentences:
21
+ - تهران هوای پاکی در فصل زمستان دارد.
22
+ - مشهد و تهران شلوغ‌ترین شهرهای ایران هستند.
23
+ - در زمستان‌ها هوای تهران پاک نیست.
24
+ - source_sentence: یادگیری زبان خارجی فرصت‌های شغلی را افزایش می‌دهد.
25
+ sentences:
26
+ - تسلط بر چند زبان، شانس استخدام در شرکت‌های بین‌المللی را بالا می‌برد.
27
+ - دانستن زبان‌های خارجی تأثیری در موفقیت شغلی ندارد.
28
+ - دمای هوا در قطب جنوب به پایین‌ترین حد خود در 50 سال اخیر رسید.
29
+ - source_sentence: سفر کردن باعث گسترش دیدگاه‌های فرهنگی می‌شود.
30
+ sentences:
31
+ - بازدید از کشورهای مختلف به درک بهتر تنوع فرهنگی کمک می‌کند.
32
+ - سفر کردن هیچ تأثیری بر دیدگاه‌های فرهنگی افراد ندارد
33
+ - دمای هوا در قطب جنوب به پایین‌ترین حد خود در 50 سال اخیر رسید.
34
+ base_model:
35
+ - PartAI/TookaBERT-Base
36
+ ---
37
+
38
+ # TookaSBERT-Base1
39
+
40
+
41
+ This model is a Sentence Transformers model trained for semantic textual similarity and embedding tasks. It maps sentences and paragraphs to a dense vector space, where semantically similar texts are close together.
42
+
43
+ The model is trained in two sizes: **Base** and **Large**
44
+
45
+ ## Usage
46
+
47
+ ### Direct Usage (Sentence Transformers)
48
+
49
+ First install the Sentence Transformers library:
50
+
51
+ ```bash
52
+ pip install sentence-transformers==3.4.1
53
+ ```
54
+
55
+ Then you can load this model and run inference.
56
+ ```python
57
+ from sentence_transformers import SentenceTransformer
58
+
59
+ # Download from the 🤗 Hub
60
+ model = SentenceTransformer("PartAI/TookaSBERT-Base1")
61
+ # Run inference
62
+ sentences = [
63
+ 'درنا از پرندگان مهاجر با پاهای بلند و گردن دراز است.',
64
+ 'درناها با قامتی بلند و بال‌های پهن، از زیباترین پرندگان مهاجر به شمار می‌روند.',
65
+ 'درناها پرندگانی کوچک با پاهای کوتاه هستند که مهاجرت نمی‌کنند.'
66
+ ]
67
+ embeddings = model.encode(sentences)
68
+ print(embeddings.shape)
69
+ # [3, 1024]
70
+
71
+ # Get the similarity scores for the embeddings
72
+ similarities = model.similarity(embeddings, embeddings)
73
+ print(similarities.shape)
74
+ # [3, 3]
75
+ ```
76
+
77
+ ## 🛠️ Training Details
78
+ The training is performed in two stages:
79
+
80
+ 1. **Pretraining** on the *Targoman News* dataset
81
+ 2. **Fine-tuning** on multiple synthetic datasets
82
+
83
+ ### Stage 1: Pretraining
84
+ - We use an **asymmetric** setup.
85
+ - Input formatting:
86
+ - Titles are prepended with `"سوال: "`
87
+ - Texts are prepended with `"متن: "`
88
+ - Loss function: `CachedMultipleNegativesRankingLoss`
89
+
90
+ ### Stage 2: Fine-tuning
91
+ - Loss functions:
92
+ - `CachedMultipleNegativesRankingLoss`
93
+ - `CoSENTLoss`
94
+ - Used across multiple synthetic datasets
95
+
96
+
97
+ # 📊 Evaluation
98
+ We evaluate our model on the [**PTEB Benchmark**](https://huggingface.co/spaces/PartAI/pteb-leaderboard). Our model **outperforms mE5-Base on average across PTEB tasks**.
99
+
100
+ For *Retrieval* and *Reranking* tasks, we follow the same asymmetric structure, prepending:
101
+ - `"سوال: "` to queries
102
+ - `"متن: "` to documents
103
+
104
+
105
+ | Model | #Params | Pair-Classification-Avg | Classification-Avg | Retrieval-Avg | Reranking-Avg | Tasks-Avg |
106
+ |--------------------------------------------------------------------------------|:-------:|-------------------------|--------------------|---------------|---------------|-----------|
107
+ | [multilingual-e5-base](https://huggingface.co/intfloat/multilingual-e5-base) | 278M | 70.76 | 69.71 | 63.90 | 76.01 | 70.09 |
108
+ | [multilingual-e5-large](https://huggingface.co/intfloat/multilingual-e5-large) | 560M | 72.55 | 72.18 | **65.36** | **78.52** | **72.15** |
109
+ | [jina-embeddings-v3](https://huggingface.co/jinaai/jina-embeddings-v3) | 572M | 71.88 | **79.27** | 65.18 | 64.62 | 70.24 |
110
+ | tooka-sbert-large-v1 | 353M | **81.52** | 71.54 | 45.61 | 60.44 | 64.78 |
111
+ | tooka-sbert-base-v2 | 123M | 75.69 | 72.16 | 61.24 | 73.40 | 70.62 |
112
+ | tooka-sbert-large-v2 | 353M | 80.24 | 74.73 | 59.80 | 73.44 | 72.05 |
113
+
114
+
115
+ ### Task-Specific Datasets in PTEB
116
+
117
+ - **Pair-Classification**:
118
+ - FarsTail
119
+
120
+ - **Classification**:
121
+ - MassiveIntentClassification
122
+ - MassiveScenarioClassification
123
+ - MultilingualSentimentClassification
124
+ - PersianFoodSentimentClassification
125
+
126
+ - **Retrieval**:
127
+ - MIRACLRetrieval
128
+ - NeuCLIR2023Retrieval
129
+ - WikipediaRetrievalMultilingual
130
+
131
+ - **Reranking**:
132
+ - MIRACLReranking
133
+ - WikipediaRerankingMultilingual
134
+
135
+
136
+ ## Citation
137
+
138
+ ### BibTeX
139
+
140
+ #### Sentence Transformers
141
+ ```bibtex
142
+ @inproceedings{reimers-2019-sentence-bert,
143
+ title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
144
+ author = "Reimers, Nils and Gurevych, Iryna",
145
+ booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
146
+ month = "11",
147
+ year = "2019",
148
+ publisher = "Association for Computational Linguistics",
149
+ url = "https://arxiv.org/abs/1908.10084",
150
+ }
151
+ ```
152
+
153
+ #### CachedMultipleNegativesRankingLoss
154
+ ```bibtex
155
+ @misc{gao2021scaling,
156
+ title={Scaling Deep Contrastive Learning Batch Size under Memory Limited Setup},
157
+ author={Luyu Gao and Yunyi Zhang and Jiawei Han and Jamie Callan},
158
+ year={2021},
159
+ eprint={2101.06983},
160
+ archivePrefix={arXiv},
161
+ primaryClass={cs.LG}
162
+ }
163
+ ```