aditeyabaral commited on
Commit
7600e1b
·
verified ·
1 Parent(s): bd5e3c5

Add new ColBERT model

Browse files
1_Dense/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "in_features": 768,
3
+ "out_features": 128,
4
+ "bias": false,
5
+ "activation_function": "torch.nn.modules.linear.Identity",
6
+ "use_residual": false
7
+ }
1_Dense/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1007620d55bfc51d217ef86a9bcbf4e51372dfd6c7bd5cddb6cb474074895be7
3
+ size 196696
README.md ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ tags:
6
+ - colbert
7
+ - PyLate
8
+ - feature-extraction
9
+ - text-classification
10
+ - sentence-pair-classification
11
+ - semantic-similarity
12
+ - semantic-search
13
+ - retrieval
14
+ - reranking
15
+ - generated_from_trainer
16
+ - dataset_size:76348209
17
+ - loss:Contrastive
18
+ base_model: colbert-ir/colbertv2.0
19
+ datasets:
20
+ - redis/langcache-sentencepairs-v3
21
+ pipeline_tag: sentence-similarity
22
+ library_name: PyLate
23
+ ---
24
+
25
+ # Fine-tuned ColBERT model for semantic caching
26
+
27
+ This is a [PyLate](https://github.com/lightonai/pylate) model finetuned from [colbert-ir/colbertv2.0](https://huggingface.co/colbert-ir/colbertv2.0) on the [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/redis/langcache-sentencepairs-v3) dataset. It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
28
+
29
+ ## Model Details
30
+
31
+ ### Model Description
32
+ - **Model Type:** PyLate model
33
+ - **Base model:** [colbert-ir/colbertv2.0](https://huggingface.co/colbert-ir/colbertv2.0) <!-- at revision c1e84128e85ef755c096a95bdb06b47793b13acf -->
34
+ - **Document Length:** 128 tokens
35
+ - **Query Length:** 128 tokens
36
+ - **Output Dimensionality:** 128 tokens
37
+ - **Similarity Function:** MaxSim
38
+ - **Training Dataset:**
39
+ - [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/redis/langcache-sentencepairs-v3)
40
+ - **Language:** en
41
+ - **License:** apache-2.0
42
+
43
+ ### Model Sources
44
+
45
+ - **Documentation:** [PyLate Documentation](https://lightonai.github.io/pylate/)
46
+ - **Repository:** [PyLate on GitHub](https://github.com/lightonai/pylate)
47
+ - **Hugging Face:** [PyLate models on Hugging Face](https://huggingface.co/models?library=PyLate)
48
+
49
+ ### Full Model Architecture
50
+
51
+ ```
52
+ ColBERT(
53
+ (0): Transformer({'max_seq_length': 127, 'do_lower_case': False, 'architecture': 'BertModel'})
54
+ (1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
55
+ )
56
+ ```
57
+
58
+ ## Usage
59
+ First install the PyLate library:
60
+
61
+ ```bash
62
+ pip install -U pylate
63
+ ```
64
+
65
+ ### Retrieval
66
+
67
+ Use this model with PyLate to index and retrieve documents. The index uses [FastPLAID](https://github.com/lightonai/fast-plaid) for efficient similarity search.
68
+
69
+ #### Indexing documents
70
+
71
+ Load the ColBERT model and initialize the PLAID index, then encode and index your documents:
72
+
73
+ ```python
74
+ from pylate import indexes, models, retrieve
75
+
76
+ # Step 1: Load the ColBERT model
77
+ model = models.ColBERT(
78
+ model_name_or_path="aditeyabaral/langcache-colbert-v2",
79
+ )
80
+
81
+ # Step 2: Initialize the PLAID index
82
+ index = indexes.PLAID(
83
+ index_folder="pylate-index",
84
+ index_name="index",
85
+ override=True, # This overwrites the existing index if any
86
+ )
87
+
88
+ # Step 3: Encode the documents
89
+ documents_ids = ["1", "2", "3"]
90
+ documents = ["document 1 text", "document 2 text", "document 3 text"]
91
+
92
+ documents_embeddings = model.encode(
93
+ documents,
94
+ batch_size=32,
95
+ is_query=False, # Ensure that it is set to False to indicate that these are documents, not queries
96
+ show_progress_bar=True,
97
+ )
98
+
99
+ # Step 4: Add document embeddings to the index by providing embeddings and corresponding ids
100
+ index.add_documents(
101
+ documents_ids=documents_ids,
102
+ documents_embeddings=documents_embeddings,
103
+ )
104
+ ```
105
+
106
+ Note that you do not have to recreate the index and encode the documents every time. Once you have created an index and added the documents, you can re-use the index later by loading it:
107
+
108
+ ```python
109
+ # To load an index, simply instantiate it with the correct folder/name and without overriding it
110
+ index = indexes.PLAID(
111
+ index_folder="pylate-index",
112
+ index_name="index",
113
+ )
114
+ ```
115
+
116
+ #### Retrieving top-k documents for queries
117
+
118
+ Once the documents are indexed, you can retrieve the top-k most relevant documents for a given set of queries.
119
+ To do so, initialize the ColBERT retriever with the index you want to search in, encode the queries and then retrieve the top-k documents to get the top matches ids and relevance scores:
120
+
121
+ ```python
122
+ # Step 1: Initialize the ColBERT retriever
123
+ retriever = retrieve.ColBERT(index=index)
124
+
125
+ # Step 2: Encode the queries
126
+ queries_embeddings = model.encode(
127
+ ["query for document 3", "query for document 1"],
128
+ batch_size=32,
129
+ is_query=True, # # Ensure that it is set to False to indicate that these are queries
130
+ show_progress_bar=True,
131
+ )
132
+
133
+ # Step 3: Retrieve top-k documents
134
+ scores = retriever.retrieve(
135
+ queries_embeddings=queries_embeddings,
136
+ k=10, # Retrieve the top 10 matches for each query
137
+ )
138
+ ```
139
+
140
+ ### Reranking
141
+ If you only want to use the ColBERT model to perform reranking on top of your first-stage retrieval pipeline without building an index, you can simply use rank function and pass the queries and documents to rerank:
142
+
143
+ ```python
144
+ from pylate import rank, models
145
+
146
+ queries = [
147
+ "query A",
148
+ "query B",
149
+ ]
150
+
151
+ documents = [
152
+ ["document A", "document B"],
153
+ ["document 1", "document C", "document B"],
154
+ ]
155
+
156
+ documents_ids = [
157
+ [1, 2],
158
+ [1, 3, 2],
159
+ ]
160
+
161
+ model = models.ColBERT(
162
+ model_name_or_path="aditeyabaral/langcache-colbert-v2",
163
+ )
164
+
165
+ queries_embeddings = model.encode(
166
+ queries,
167
+ is_query=True,
168
+ )
169
+
170
+ documents_embeddings = model.encode(
171
+ documents,
172
+ is_query=False,
173
+ )
174
+
175
+ reranked_documents = rank.rerank(
176
+ documents_ids=documents_ids,
177
+ queries_embeddings=queries_embeddings,
178
+ documents_embeddings=documents_embeddings,
179
+ )
180
+ ```
181
+
182
+ <!--
183
+ ### Direct Usage (Transformers)
184
+
185
+ <details><summary>Click to see the direct usage in Transformers</summary>
186
+
187
+ </details>
188
+ -->
189
+
190
+ <!--
191
+ ### Downstream Usage (Sentence Transformers)
192
+
193
+ You can finetune this model on your own dataset.
194
+
195
+ <details><summary>Click to expand</summary>
196
+
197
+ </details>
198
+ -->
199
+
200
+ <!--
201
+ ### Out-of-Scope Use
202
+
203
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
204
+ -->
205
+
206
+ <!--
207
+ ## Bias, Risks and Limitations
208
+
209
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
210
+ -->
211
+
212
+ <!--
213
+ ### Recommendations
214
+
215
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
216
+ -->
217
+
218
+ ## Training Details
219
+
220
+ ### Training Dataset
221
+
222
+ #### LangCache Sentence Pairs (subsets=['all'], train+val=True)
223
+
224
+ * Dataset: [LangCache Sentence Pairs (subsets=['all'], train+val=True)](https://huggingface.co/datasets/redis/langcache-sentencepairs-v3)
225
+ * Size: 76,348,209 training samples
226
+ * Columns: <code>anchor</code>, <code>positive</code>, and <code>negative_1</code>
227
+ * Approximate statistics based on the first 1000 samples:
228
+ | | anchor | positive | negative_1 |
229
+ |:--------|:----------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------|
230
+ | type | string | string | string |
231
+ | details | <ul><li>min: 4 tokens</li><li>mean: 17.0 tokens</li><li>max: 128 tokens</li></ul> | <ul><li>min: 4 tokens</li><li>mean: 17.14 tokens</li><li>max: 128 tokens</li></ul> | <ul><li>min: 5 tokens</li><li>mean: 19.96 tokens</li><li>max: 107 tokens</li></ul> |
232
+ * Samples:
233
+ | anchor | positive | negative_1 |
234
+ |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------|
235
+ | <code><br>"There aren't many places in Gold Coast where you can find a wide variety of wedding dresses."</code> | <code><br>"There aren't many places in Gold Coast where you can find a wide variety of wedding dresses."</code> | <code>Where can I get a wide variety of wedding dresses in Gold Coast?</code> |
236
+ | <code><br>It's easy to say it's good having siblings, but people often suggest it as a universal truth without considering that not everyone enjoys sibling relationships. Having siblings can lead to conflicts, competition, and stress, which might overshadow any potential benefits like companionship or support. Additionally, individual experiences with siblings can vary greatly depending on personality, family dynamics, and cultural background.</code> | <code><br>It's easy to say it's good having siblings, but people often suggest it as a universal truth without considering that not everyone enjoys sibling relationships. Having siblings can lead to conflicts, competition, and stress, which might overshadow any potential benefits like companionship or support. Additionally, individual experiences with siblings can vary greatly depending on personality, family dynamics, and cultural background.</code> | <code>What's it like having siblings?</code> |
237
+ | <code><br>To reconcile the idea that 'Education is the Key to Success' with the presence of underemployed graduates and successful criminals, it's important to emphasize that education is one among many factors that contribute to success. Education equips individuals with knowledge, critical thinking skills, and problem-solving abilities, which are essential tools for navigating life's challenges and seizing opportunities. However, success is also influenced by other elements such as personal drive, social connections, opportunities presented, and sometimes sheer luck. Education does not guarantee success on its own; rather, it provides a foundation upon which individuals can build their careers and personal lives. Additionally, the definition of success can be subjective and varies across different cultures and individuals. It's crucial to address practical considerations like ensuring that educational curricula are relevant to the current job market and fostering environments where both hard ...</code> | <code><br>To reconcile the idea that 'Education is the Key to Success' with the presence of underemployed graduates and successful criminals, it's important to emphasize that education is one among many factors that contribute to success. Education equips individuals with knowledge, critical thinking skills, and problem-solving abilities, which are essential tools for navigating life's challenges and seizing opportunities. However, success is also influenced by other elements such as personal drive, social connections, opportunities presented, and sometimes sheer luck. Education does not guarantee success on its own; rather, it provides a foundation upon which individuals can build their careers and personal lives. Additionally, the definition of success can be subjective and varies across different cultures and individuals. It's crucial to address practical considerations like ensuring that educational curricula are relevant to the current job market and fostering environments where both hard ...</code> | <code>How do you convince the upcoming generation that "Education is The Key of Success " when we are surrounded by poor graduates and rich criminals?</code> |
238
+ * Loss: <code>pylate.losses.contrastive.Contrastive</code>
239
+
240
+ ### Evaluation Dataset
241
+
242
+ #### LangCache Sentence Pairs (split=test)
243
+
244
+ * Dataset: [LangCache Sentence Pairs (split=test)](https://huggingface.co/datasets/redis/langcache-sentencepairs-v3)
245
+ * Size: 132,354 evaluation samples
246
+ * Columns: <code>anchor</code>, <code>positive</code>, and <code>negative_1</code>
247
+ * Approximate statistics based on the first 1000 samples:
248
+ | | anchor | positive | negative_1 |
249
+ |:--------|:-----------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------|:----------------------------------------------------------------------------------|
250
+ | type | string | string | string |
251
+ | details | <ul><li>min: 5 tokens</li><li>mean: 28.17 tokens</li><li>max: 121 tokens</li></ul> | <ul><li>min: 5 tokens</li><li>mean: 27.61 tokens</li><li>max: 121 tokens</li></ul> | <ul><li>min: 6 tokens</li><li>mean: 20.27 tokens</li><li>max: 64 tokens</li></ul> |
252
+ * Samples:
253
+ | anchor | positive | negative_1 |
254
+ |:----------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------|
255
+ | <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> |
256
+ | <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> |
257
+ | <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>Childlessness is low in Eastern European countries.</code> |
258
+ * Loss: <code>pylate.losses.contrastive.Contrastive</code>
259
+
260
+ ### Framework Versions
261
+ - Python: 3.12.12
262
+ - Sentence Transformers: 5.3.0
263
+ - PyLate: 1.5.0
264
+ - Transformers: 5.3.0
265
+ - PyTorch: 2.9.0+cu130
266
+ - Accelerate: 1.13.0
267
+ - Datasets: 4.8.5
268
+ - Tokenizers: 0.22.2
269
+
270
+
271
+ ## Citation
272
+
273
+ ### BibTeX
274
+
275
+ #### Sentence Transformers
276
+ ```bibtex
277
+ @inproceedings{reimers-2019-sentence-bert,
278
+ title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
279
+ author = "Reimers, Nils and Gurevych, Iryna",
280
+ booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
281
+ month = "11",
282
+ year = "2019",
283
+ publisher = "Association for Computational Linguistics",
284
+ url = "https://arxiv.org/abs/1908.10084"
285
+ }
286
+ ```
287
+
288
+ #### PyLate
289
+ ```bibtex
290
+ @inproceedings{DBLP:conf/cikm/ChaffinS25,
291
+ author = {Antoine Chaffin and
292
+ Rapha{"{e}}l Sourty},
293
+ editor = {Meeyoung Cha and
294
+ Chanyoung Park and
295
+ Noseong Park and
296
+ Carl Yang and
297
+ Senjuti Basu Roy and
298
+ Jessie Li and
299
+ Jaap Kamps and
300
+ Kijung Shin and
301
+ Bryan Hooi and
302
+ Lifang He},
303
+ title = {PyLate: Flexible Training and Retrieval for Late Interaction Models},
304
+ booktitle = {Proceedings of the 34th {ACM} International Conference on Information
305
+ and Knowledge Management, {CIKM} 2025, Seoul, Republic of Korea, November
306
+ 10-14, 2025},
307
+ pages = {6334--6339},
308
+ publisher = {{ACM}},
309
+ year = {2025},
310
+ url = {https://github.com/lightonai/pylate},
311
+ doi = {10.1145/3746252.3761608},
312
+ }
313
+ ```
314
+
315
+ <!--
316
+ ## Glossary
317
+
318
+ *Clearly define terms in order to be accessible across audiences.*
319
+ -->
320
+
321
+ <!--
322
+ ## Model Card Authors
323
+
324
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
325
+ -->
326
+
327
+ <!--
328
+ ## Model Card Contact
329
+
330
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
331
+ -->
config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_cross_attention": false,
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": null,
8
+ "classifier_dropout": null,
9
+ "dtype": "bfloat16",
10
+ "eos_token_id": null,
11
+ "gradient_checkpointing": false,
12
+ "hidden_act": "gelu",
13
+ "hidden_dropout_prob": 0.1,
14
+ "hidden_size": 768,
15
+ "initializer_range": 0.02,
16
+ "intermediate_size": 3072,
17
+ "is_decoder": false,
18
+ "layer_norm_eps": 1e-12,
19
+ "max_position_embeddings": 512,
20
+ "model_type": "bert",
21
+ "num_attention_heads": 12,
22
+ "num_hidden_layers": 12,
23
+ "pad_token_id": 0,
24
+ "position_embedding_type": "absolute",
25
+ "tie_word_embeddings": true,
26
+ "transformers_version": "5.3.0",
27
+ "type_vocab_size": 2,
28
+ "use_cache": true,
29
+ "vocab_size": 30522
30
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "ColBERT",
3
+ "__version__": {
4
+ "sentence_transformers": "5.3.0",
5
+ "transformers": "5.3.0",
6
+ "pytorch": "2.9.0+cu130"
7
+ },
8
+ "prompts": {
9
+ "query": "",
10
+ "document": ""
11
+ },
12
+ "default_prompt_name": null,
13
+ "similarity_fn_name": "MaxSim",
14
+ "query_prefix": "[unused0]",
15
+ "document_prefix": "[unused1]",
16
+ "query_length": 128,
17
+ "document_length": 128,
18
+ "attend_to_expansion_tokens": false,
19
+ "skiplist_words": [
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
+ "do_query_expansion": true
54
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c02c869510b7ce230fa5978b7532643b084c2a3a564f8e4f3cb24fb023e687a
3
+ size 218986904
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Dense",
12
+ "type": "pylate.models.Dense.Dense"
13
+ }
14
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 127,
3
+ "do_lower_case": false
4
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_lower_case": true,
5
+ "is_local": false,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 512,
8
+ "pad_token": "[MASK]",
9
+ "sep_token": "[SEP]",
10
+ "strip_accents": null,
11
+ "tokenize_chinese_chars": true,
12
+ "tokenizer_class": "BertTokenizer",
13
+ "unk_token": "[UNK]"
14
+ }