NohTow commited on
Commit
10d85a8
·
verified ·
1 Parent(s): f900429

Upload README.md

Browse files
Files changed (2) hide show
  1. .gitattributes +1 -0
  2. README.md +3 -238
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ README.md filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,238 +1,3 @@
1
- ---
2
- tags:
3
- - ColBERT
4
- - PyLate
5
- - sentence-transformers
6
- - sentence-similarity
7
- - feature-extraction
8
- pipeline_tag: sentence-similarity
9
- library_name: PyLate
10
- ---
11
-
12
- # PyLate
13
-
14
- This is a [PyLate](https://github.com/lightonai/pylate) model trained. It maps sentences & paragraphs to sequences of 48-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
15
-
16
- ## Model Details
17
-
18
- ### Model Description
19
- - **Model Type:** PyLate model
20
- <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
21
- - **Document Length:** 2048 tokens
22
- - **Query Length:** 256 tokens
23
- - **Output Dimensionality:** 48 tokens
24
- - **Similarity Function:** MaxSim
25
- <!-- - **Training Dataset:** Unknown -->
26
- <!-- - **Language:** Unknown -->
27
- <!-- - **License:** Unknown -->
28
-
29
- ### Model Sources
30
-
31
- - **Documentation:** [PyLate Documentation](https://lightonai.github.io/pylate/)
32
- - **Repository:** [PyLate on GitHub](https://github.com/lightonai/pylate)
33
- - **Hugging Face:** [PyLate models on Hugging Face](https://huggingface.co/models?library=PyLate)
34
-
35
- ### Full Model Architecture
36
-
37
- ```
38
- ColBERT(
39
- (0): Transformer({'max_seq_length': 2047, 'do_lower_case': True, 'architecture': 'ModernBertModel'})
40
- (1): Dense({'in_features': 256, 'out_features': 512, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
41
- (2): Dense({'in_features': 512, 'out_features': 48, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
42
- )
43
- ```
44
-
45
- ## Usage
46
- First install the PyLate library:
47
-
48
- ```bash
49
- pip install -U pylate
50
- ```
51
-
52
- ### Retrieval
53
-
54
- Use this model with PyLate to index and retrieve documents. The index uses [FastPLAID](https://github.com/lightonai/fast-plaid) for efficient similarity search.
55
-
56
- #### Indexing documents
57
-
58
- Load the ColBERT model and initialize the PLAID index, then encode and index your documents:
59
-
60
- ```python
61
- from pylate import indexes, models, retrieve
62
-
63
- # Step 1: Load the ColBERT model
64
- model = models.ColBERT(
65
- model_name_or_path="lightonai/LateOn-Code-v0-edge",
66
- )
67
-
68
- # Step 2: Initialize the PLAID index
69
- index = indexes.PLAID(
70
- index_folder="pylate-index",
71
- index_name="index",
72
- override=True, # This overwrites the existing index if any
73
- )
74
-
75
- # Step 3: Encode the documents
76
- documents_ids = ["1", "2", "3"]
77
- documents = ["document 1 text", "document 2 text", "document 3 text"]
78
-
79
- documents_embeddings = model.encode(
80
- documents,
81
- batch_size=32,
82
- is_query=False, # Ensure that it is set to False to indicate that these are documents, not queries
83
- show_progress_bar=True,
84
- )
85
-
86
- # Step 4: Add document embeddings to the index by providing embeddings and corresponding ids
87
- index.add_documents(
88
- documents_ids=documents_ids,
89
- documents_embeddings=documents_embeddings,
90
- )
91
- ```
92
-
93
- 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:
94
-
95
- ```python
96
- # To load an index, simply instantiate it with the correct folder/name and without overriding it
97
- index = indexes.PLAID(
98
- index_folder="pylate-index",
99
- index_name="index",
100
- )
101
- ```
102
-
103
- #### Retrieving top-k documents for queries
104
-
105
- Once the documents are indexed, you can retrieve the top-k most relevant documents for a given set of queries.
106
- 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:
107
-
108
- ```python
109
- # Step 1: Initialize the ColBERT retriever
110
- retriever = retrieve.ColBERT(index=index)
111
-
112
- # Step 2: Encode the queries
113
- queries_embeddings = model.encode(
114
- ["query for document 3", "query for document 1"],
115
- batch_size=32,
116
- is_query=True, # # Ensure that it is set to False to indicate that these are queries
117
- show_progress_bar=True,
118
- )
119
-
120
- # Step 3: Retrieve top-k documents
121
- scores = retriever.retrieve(
122
- queries_embeddings=queries_embeddings,
123
- k=10, # Retrieve the top 10 matches for each query
124
- )
125
- ```
126
-
127
- ### Reranking
128
- 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:
129
-
130
- ```python
131
- from pylate import rank, models
132
-
133
- queries = [
134
- "query A",
135
- "query B",
136
- ]
137
-
138
- documents = [
139
- ["document A", "document B"],
140
- ["document 1", "document C", "document B"],
141
- ]
142
-
143
- documents_ids = [
144
- [1, 2],
145
- [1, 3, 2],
146
- ]
147
-
148
- model = models.ColBERT(
149
- model_name_or_path="lightonai/LateOn-Code-v0-edge",
150
- )
151
-
152
- queries_embeddings = model.encode(
153
- queries,
154
- is_query=True,
155
- )
156
-
157
- documents_embeddings = model.encode(
158
- documents,
159
- is_query=False,
160
- )
161
-
162
- reranked_documents = rank.rerank(
163
- documents_ids=documents_ids,
164
- queries_embeddings=queries_embeddings,
165
- documents_embeddings=documents_embeddings,
166
- )
167
- ```
168
-
169
- <!--
170
- ### Direct Usage (Transformers)
171
-
172
- <details><summary>Click to see the direct usage in Transformers</summary>
173
-
174
- </details>
175
- -->
176
-
177
- <!--
178
- ### Downstream Usage (Sentence Transformers)
179
-
180
- You can finetune this model on your own dataset.
181
-
182
- <details><summary>Click to expand</summary>
183
-
184
- </details>
185
- -->
186
-
187
- <!--
188
- ### Out-of-Scope Use
189
-
190
- *List how the model may foreseeably be misused and address what users ought not to do with the model.*
191
- -->
192
-
193
- <!--
194
- ## Bias, Risks and Limitations
195
-
196
- *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
197
- -->
198
-
199
- <!--
200
- ### Recommendations
201
-
202
- *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
203
- -->
204
-
205
- ## Training Details
206
-
207
- ### Framework Versions
208
- - Python: 3.12.11
209
- - Sentence Transformers: 5.1.1
210
- - PyLate: 1.3.4
211
- - Transformers: 4.52.3
212
- - PyTorch: 2.8.0+cu128
213
- - Accelerate: 1.10.1
214
- - Datasets: 4.4.1
215
- - Tokenizers: 0.21.4
216
-
217
-
218
- ## Citation
219
-
220
- ### BibTeX
221
-
222
- <!--
223
- ## Glossary
224
-
225
- *Clearly define terms in order to be accessible across audiences.*
226
- -->
227
-
228
- <!--
229
- ## Model Card Authors
230
-
231
- *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
232
- -->
233
-
234
- <!--
235
- ## Model Card Contact
236
-
237
- *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
238
- -->
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c04df7b177f372eaf275f458662fd8a208201f2d235bc5d4c33fad558c494207
3
+ size 50328388