adbaral commited on
Commit
c25a596
·
verified ·
1 Parent(s): 5cc88cc

Add new CrossEncoder model

Browse files
Files changed (7) hide show
  1. README.md +223 -0
  2. config.json +35 -0
  3. model.safetensors +3 -0
  4. special_tokens_map.json +37 -0
  5. tokenizer.json +0 -0
  6. tokenizer_config.json +58 -0
  7. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ tags:
6
+ - cross-encoder
7
+ - sentence-transformers
8
+ - text-classification
9
+ - sentence-pair-classification
10
+ - semantic-similarity
11
+ - semantic-search
12
+ - retrieval
13
+ - reranking
14
+ - generated_from_trainer
15
+ - dataset_size:1452533
16
+ - loss:MultipleNegativesRankingLoss
17
+ base_model: cross-encoder/ms-marco-MiniLM-L6-v2
18
+ datasets:
19
+ - redis/langcache-sentencepairs-v1
20
+ pipeline_tag: text-ranking
21
+ library_name: sentence-transformers
22
+ ---
23
+
24
+ # Redis fine-tuned CrossEncoder model for semantic caching on LangCache
25
+
26
+ This is a [Cross Encoder](https://www.sbert.net/docs/cross_encoder/usage/usage.html) model finetuned from [cross-encoder/ms-marco-MiniLM-L6-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L6-v2) on the [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1) dataset using the [sentence-transformers](https://www.SBERT.net) library. It computes scores for pairs of texts, which can be used for sentence pair classification.
27
+
28
+ ## Model Details
29
+
30
+ ### Model Description
31
+ - **Model Type:** Cross Encoder
32
+ - **Base model:** [cross-encoder/ms-marco-MiniLM-L6-v2](https://huggingface.co/cross-encoder/ms-marco-MiniLM-L6-v2) <!-- at revision c5ee24cb16019beea0893ab7796b1df96625c6b8 -->
33
+ - **Maximum Sequence Length:** 512 tokens
34
+ - **Number of Output Labels:** 1 label
35
+ - **Training Dataset:**
36
+ - [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1)
37
+ - **Language:** en
38
+ - **License:** apache-2.0
39
+
40
+ ### Model Sources
41
+
42
+ - **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
43
+ - **Documentation:** [Cross Encoder Documentation](https://www.sbert.net/docs/cross_encoder/usage/usage.html)
44
+ - **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)
45
+ - **Hugging Face:** [Cross Encoders on Hugging Face](https://huggingface.co/models?library=sentence-transformers&other=cross-encoder)
46
+
47
+ ## Usage
48
+
49
+ ### Direct Usage (Sentence Transformers)
50
+
51
+ First install the Sentence Transformers library:
52
+
53
+ ```bash
54
+ pip install -U sentence-transformers
55
+ ```
56
+
57
+ Then you can load this model and run inference.
58
+ ```python
59
+ from sentence_transformers import CrossEncoder
60
+
61
+ # Download from the 🤗 Hub
62
+ model = CrossEncoder("redis/langcache-reranker-v1-miniL6-softmnrl-triplet")
63
+ # Get scores for pairs of texts
64
+ pairs = [
65
+ [' What high potential jobs are there other than computer science?', ' What high potential jobs are there other than computer science?'],
66
+ [' Would India ever be able to develop a missile system like S300 or S400 missile?', ' Would India ever be able to develop a missile system like S300 or S400 missile?'],
67
+ [' water from the faucet is being drunk by a yellow dog', 'A yellow dog is drinking water from the faucet'],
68
+ [' water from the faucet is being drunk by a yellow dog', 'The yellow dog is drinking water from a bottle'],
69
+ ['! colspan = `` 14 `` `` Players who appeared for Colchester who left during the season ``', '! colspan = `` 14 `` `` Players who appeared for Colchester who left during the season ``'],
70
+ ]
71
+ scores = model.predict(pairs)
72
+ print(scores.shape)
73
+ # (5,)
74
+
75
+ # Or rank different texts based on similarity to a single text
76
+ ranks = model.rank(
77
+ ' What high potential jobs are there other than computer science?',
78
+ [
79
+ ' What high potential jobs are there other than computer science?',
80
+ ' Would India ever be able to develop a missile system like S300 or S400 missile?',
81
+ 'A yellow dog is drinking water from the faucet',
82
+ 'The yellow dog is drinking water from a bottle',
83
+ '! colspan = `` 14 `` `` Players who appeared for Colchester who left during the season ``',
84
+ ]
85
+ )
86
+ # [{'corpus_id': ..., 'score': ...}, {'corpus_id': ..., 'score': ...}, ...]
87
+ ```
88
+
89
+ <!--
90
+ ### Direct Usage (Transformers)
91
+
92
+ <details><summary>Click to see the direct usage in Transformers</summary>
93
+
94
+ </details>
95
+ -->
96
+
97
+ <!--
98
+ ### Downstream Usage (Sentence Transformers)
99
+
100
+ You can finetune this model on your own dataset.
101
+
102
+ <details><summary>Click to expand</summary>
103
+
104
+ </details>
105
+ -->
106
+
107
+ <!--
108
+ ### Out-of-Scope Use
109
+
110
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
111
+ -->
112
+
113
+ <!--
114
+ ## Bias, Risks and Limitations
115
+
116
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
117
+ -->
118
+
119
+ <!--
120
+ ### Recommendations
121
+
122
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
123
+ -->
124
+
125
+ ## Training Details
126
+
127
+ ### Training Dataset
128
+
129
+ #### LangCache Sentence Pairs (subsets=['all'], train+val=True)
130
+
131
+ * Dataset: [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1)
132
+ * Size: 1,452,533 training samples
133
+ * Columns: <code>anchor</code>, <code>positive</code>, and <code>negative_1</code>
134
+ * Approximate statistics based on the first 1000 samples:
135
+ | | anchor | positive | negative_1 |
136
+ |:--------|:-------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------|
137
+ | type | string | string | string |
138
+ | details | <ul><li>min: 24 characters</li><li>mean: 114.25 characters</li><li>max: 268 characters</li></ul> | <ul><li>min: 19 characters</li><li>mean: 114.1 characters</li><li>max: 226 characters</li></ul> | <ul><li>min: 4 characters</li><li>mean: 93.04 characters</li><li>max: 234 characters</li></ul> |
139
+ * Samples:
140
+ | anchor | positive | negative_1 |
141
+ |:-----------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------|
142
+ | <code> Any Canadian teachers (B.Ed. holders) teaching in U.S. schools?</code> | <code> Any Canadian teachers (B.Ed. holders) teaching in U.S. schools?</code> | <code>Are there many Canadians living and working illegally in the United States?</code> |
143
+ | <code> Are there any underlying psychological tricks/tactics that are used when designing the lines for rides at amusement parks?</code> | <code> Are there any underlying psychological tricks/tactics that are used when designing the lines for rides at amusement parks?</code> | <code>Is there any tricks for straight lines mcqs?</code> |
144
+ | <code> Can I pay with a debit card on PayPal?</code> | <code> Can I pay with a debit card on PayPal?</code> | <code>Can you transfer PayPal funds onto a debit card/credit card?</code> |
145
+ * Loss: [<code>MultipleNegativesRankingLoss</code>](https://sbert.net/docs/package_reference/cross_encoder/losses.html#multiplenegativesrankingloss) with these parameters:
146
+ ```json
147
+ {
148
+ "scale": 20.0,
149
+ "num_negatives": 1,
150
+ "activation_fn": "torch.nn.modules.activation.Sigmoid"
151
+ }
152
+ ```
153
+
154
+ ### Evaluation Dataset
155
+
156
+ #### LangCache Sentence Pairs (split=test)
157
+
158
+ * Dataset: [LangCache Sentence Pairs (split=test)](https://huggingface.co/datasets/aditeyabaral-redis/langcache-sentencepairs-v1)
159
+ * Size: 110,066 evaluation samples
160
+ * Columns: <code>anchor</code>, <code>positive</code>, and <code>negative_1</code>
161
+ * Approximate statistics based on the first 1000 samples:
162
+ | | anchor | positive | negative_1 |
163
+ |:--------|:-----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------|
164
+ | type | string | string | string |
165
+ | details | <ul><li>min: 3 characters</li><li>mean: 97.95 characters</li><li>max: 314 characters</li></ul> | <ul><li>min: 3 characters</li><li>mean: 97.03 characters</li><li>max: 314 characters</li></ul> | <ul><li>min: 11 characters</li><li>mean: 74.49 characters</li><li>max: 295 characters</li></ul> |
166
+ * Samples:
167
+ | anchor | positive | negative_1 |
168
+ |:----------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------|
169
+ | <code> What high potential jobs are there other than computer science?</code> | <code> What high potential jobs are there other than computer science?</code> | <code>Why IT or Computer Science jobs are being over rated than other Engineering jobs?</code> |
170
+ | <code> Would India ever be able to develop a missile system like S300 or S400 missile?</code> | <code> Would India ever be able to develop a missile system like S300 or S400 missile?</code> | <code>Should India buy the Russian S400 air defence missile system?</code> |
171
+ | <code> water from the faucet is being drunk by a yellow dog</code> | <code>A yellow dog is drinking water from the faucet</code> | <code>Do you get more homework in 9th grade than 8th?</code> |
172
+ * Loss: [<code>MultipleNegativesRankingLoss</code>](https://sbert.net/docs/package_reference/cross_encoder/losses.html#multiplenegativesrankingloss) with these parameters:
173
+ ```json
174
+ {
175
+ "scale": 20.0,
176
+ "num_negatives": 1,
177
+ "activation_fn": "torch.nn.modules.activation.Sigmoid"
178
+ }
179
+ ```
180
+
181
+ ### Framework Versions
182
+ - Python: 3.12.3
183
+ - Sentence Transformers: 5.1.0
184
+ - Transformers: 4.56.0
185
+ - PyTorch: 2.8.0+cu128
186
+ - Accelerate: 1.10.1
187
+ - Datasets: 4.0.0
188
+ - Tokenizers: 0.22.0
189
+
190
+ ## Citation
191
+
192
+ ### BibTeX
193
+
194
+ #### Sentence Transformers
195
+ ```bibtex
196
+ @inproceedings{reimers-2019-sentence-bert,
197
+ title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
198
+ author = "Reimers, Nils and Gurevych, Iryna",
199
+ booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
200
+ month = "11",
201
+ year = "2019",
202
+ publisher = "Association for Computational Linguistics",
203
+ url = "https://arxiv.org/abs/1908.10084",
204
+ }
205
+ ```
206
+
207
+ <!--
208
+ ## Glossary
209
+
210
+ *Clearly define terms in order to be accessible across audiences.*
211
+ -->
212
+
213
+ <!--
214
+ ## Model Card Authors
215
+
216
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
217
+ -->
218
+
219
+ <!--
220
+ ## Model Card Contact
221
+
222
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
223
+ -->
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "bfloat16",
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 384,
12
+ "id2label": {
13
+ "0": "LABEL_0"
14
+ },
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 1536,
17
+ "label2id": {
18
+ "LABEL_0": 0
19
+ },
20
+ "layer_norm_eps": 1e-12,
21
+ "max_position_embeddings": 512,
22
+ "model_type": "bert",
23
+ "num_attention_heads": 12,
24
+ "num_hidden_layers": 6,
25
+ "pad_token_id": 0,
26
+ "position_embedding_type": "absolute",
27
+ "sentence_transformers": {
28
+ "activation_fn": "torch.nn.modules.linear.Identity",
29
+ "version": "5.1.0"
30
+ },
31
+ "transformers_version": "4.56.0",
32
+ "type_vocab_size": 2,
33
+ "use_cache": true,
34
+ "vocab_size": 30522
35
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34be19140398a1d70986b272a71ace1bf034ea4e88783015370f169f054d8d4c
3
+ size 45439314
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff