Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,90 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
10 |
|
11 |
|
12 |
-
##
|
|
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
- **Funded by [optional]:** [More Information Needed]
|
22 |
-
- **Shared by [optional]:** [More Information Needed]
|
23 |
-
- **Model type:** [More Information Needed]
|
24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
25 |
-
- **License:** [More Information Needed]
|
26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
27 |
-
|
28 |
-
### Model Sources [optional]
|
29 |
-
|
30 |
-
<!-- Provide the basic links for the model. -->
|
31 |
-
|
32 |
-
- **Repository:** [More Information Needed]
|
33 |
-
- **Paper [optional]:** [More Information Needed]
|
34 |
-
- **Demo [optional]:** [More Information Needed]
|
35 |
-
|
36 |
-
## Uses
|
37 |
-
|
38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
39 |
|
40 |
### Direct Use
|
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 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
100 |
-
|
101 |
-
[More Information Needed]
|
102 |
-
|
103 |
-
## Evaluation
|
104 |
-
|
105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
106 |
-
|
107 |
-
### Testing Data, Factors & Metrics
|
108 |
-
|
109 |
-
#### Testing Data
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
tags:
|
4 |
+
- retrieval
|
5 |
+
- constbert
|
6 |
+
- colbert
|
7 |
+
- multi-vector
|
8 |
+
- embedding
|
9 |
+
license: apache-2.0
|
10 |
+
language:
|
11 |
+
- en
|
12 |
+
base_model:
|
13 |
+
- google-bert/bert-base-uncased
|
14 |
---
|
15 |
|
16 |
+
# ConstBERT
|
17 |
|
18 |
+
ConstBERT (Constant-Space BERT) is a multi-vector retrieval model designed for efficient and effective passage retrieval. It modifies the ColBERT architecture by encoding documents into a fixed number of learned embeddings, rather than one embedding per token. This approach significantly reduces storage costs and can improve OS paging management due to fixed-size document representations, while retaining most of the original effectiveness of multi-vector models.
|
19 |
|
20 |
|
21 |
|
22 |
+
## Details
|
23 |
+
ConstBERT addresses the high storage cost associated with traditional multi-vector retrieval methods like ColBERT, where each token in a document collection is stored as a vector. Instead, ConstBERT proposes a learned pooling mechanism that projects the token-level embeddings of a document into a smaller, fixed number (`C`) of document-level embeddings. Each of these `C` embeddings captures distinct semantic facets of the document. This projection is achieved through an additional linear transformation layer learned end-to-end during training. The relevance score between a query and a document is then computed using a late interaction mechanism (MaxSim) over these `C` document embeddings and the query's token embeddings.
|
24 |
|
25 |
+
This approach offers a trade-off between storage/computational efficiency and retrieval effectiveness, configurable by the choice of `C`. The paper demonstrates that ConstBERT can achieve performance comparable to ColBERT on benchmarks like MSMARCO and BEIR, with substantially smaller index sizes.
|
26 |
|
27 |
+
This model has been trained to produce 32 vectors of size 128.
|
28 |
|
29 |
+
### Model Sources
|
30 |
|
31 |
+
For more details, please refer to our [official repository](https://github.com/pisa-engine/ConstBERT), [paper](https://www.pinecone.io/research/efficient-constant-space-multi-vector-retrieval/) and [blog](https://www.pinecone.io/blog/cascading-retrieval-with-multi-vector-representations/)!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
### Direct Use
|
34 |
|
35 |
+
ConstBERT is intended for semantic search and passage retrieval tasks. It can be used for:
|
36 |
+
|
37 |
+
- First-stage retrieval in large document collections.
|
38 |
+
- Reranking candidates produced by another retrieval system.
|
39 |
+
|
40 |
+
The model produces fixed-size multi-vector representations for documents, which can be indexed efficiently. Queries are represented as sets of token embeddings.
|
41 |
+
|
42 |
+
Example code:
|
43 |
+
```python
|
44 |
+
from transformers import AutoModel
|
45 |
+
import numpy as np
|
46 |
+
|
47 |
+
def max_sim(q: np.ndarray, d: np.ndarray) -> float:
|
48 |
+
# Ensure the dimensions are correct
|
49 |
+
assert q.ndim == 2, "Q must be a 2-dimensional array"
|
50 |
+
assert d.ndim == 2, "d must be a 2-dimensional array"
|
51 |
+
scores = np.dot(d, q.T)
|
52 |
+
max_scores = np.max(scores, axis=0)
|
53 |
+
return float(np.sum(max_scores))
|
54 |
+
|
55 |
+
model = AutoModel.from_pretrained("pinecone/ConstBERT", trust_remote_code=True)
|
56 |
+
|
57 |
+
# Example queries and documents
|
58 |
+
queries = ["What is the capital of France?", "latest advancements in AI"]
|
59 |
+
documents = [
|
60 |
+
"Paris is the capital and most populous city of France.",
|
61 |
+
"Artificial intelligence is rapidly evolving with new breakthroughs.",
|
62 |
+
"The Eiffel Tower is a famous landmark in Paris."
|
63 |
+
]
|
64 |
+
|
65 |
+
# Encode queries and documents
|
66 |
+
query_embeddings = model.encode_queries(queries).numpy()
|
67 |
+
document_embeddings = model.encode_documents(documents).numpy()
|
68 |
+
|
69 |
+
max_sim(query_embeddings[0], document_embeddings[0]) > max_sim(query_embeddings[0], document_embeddings[1])
|
70 |
+
# Returns: True
|
71 |
+
```
|
72 |
+
|
73 |
+
## Citation (BibTeX)
|
74 |
+
```
|
75 |
+
@inproceedings{macavaney2025constbert,
|
76 |
+
author = {MacAvaney, Sean and Mallia, Antonio and Tonellotto, Nicola},
|
77 |
+
title = {Efficient Constant-Space Multi-vector Retrieval},
|
78 |
+
year = {2025},
|
79 |
+
isbn = {978-3-031-88713-0},
|
80 |
+
publisher = {Springer-Verlag},
|
81 |
+
address = {Berlin, Heidelberg},
|
82 |
+
url = {https://doi.org/10.1007/978-3-031-88714-7_22},
|
83 |
+
doi = {10.1007/978-3-031-88714-7_22},
|
84 |
+
booktitle = {Advances in Information Retrieval: 47th European Conference on Information Retrieval, ECIR 2025, Lucca, Italy, April 6–10, 2025, Proceedings, Part III},
|
85 |
+
pages = {237–245},
|
86 |
+
numpages = {9},
|
87 |
+
keywords = {Multi-Vector Retrieval, Efficiency, Dense Retrieval},
|
88 |
+
location = {Lucca, Italy}
|
89 |
+
}
|
90 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|