File size: 4,666 Bytes
cb0bdfc
 
3f565cb
 
cb0bdfc
 
 
 
 
 
aa9530c
0b9b1e3
aa9530c
cb0bdfc
3f565cb
cb0bdfc
 
3f565cb
 
cb0bdfc
3f565cb
 
 
cb0bdfc
0b9b1e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb0bdfc
3f565cb
cb0bdfc
 
0b9b1e3
cb0bdfc
 
 
 
 
 
 
 
 
 
 
 
 
 
3f565cb
cb0bdfc
3f565cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb0bdfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
100
101
---
base_model: colbert-ir/colbertv2.0
language:
- en
library_name: sentence-transformers
pipeline_tag: sentence-similarity
tags:
- sentence-transformers
- sentence-similarity
- feature-extraction
- ColBERT
- multi-vector
- PyLate
widget: []
license: mit
---

# PyLate version of colbert-ir/colbertv2.0
This checkpoint is a version of [colbert-ir/colbertv2.0](https://huggingface.co/colbert-ir/colbertv2.0) compatible with the [PyLate](https://github.com/lightonai/pylate) library.

All the credits belong to the original authors and we thank Omar Khattab for allowing us to share this version of the model.

Please refer to the [original repository](https://huggingface.co/colbert-ir/colbertv2.0) and [paper](https://arxiv.org/abs/2112.01488) for more information about the model and to [PyLate repository](https://github.com/lightonai/pylate) for information about usage of the model.

## Usage

### Sentence Transformers

This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:

```bash
pip install "sentence-transformers>=6.0.0"
```

```python
from sentence_transformers import MultiVectorEncoder

model = MultiVectorEncoder("lightonai/colbertv2.0")

query = "Which planet is known as the Red Planet?"
documents = [
    "Venus is often called Earth's twin because of its similar size and proximity.",
    "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
    "Jupiter, the largest planet in our solar system, has a prominent red spot.",
    "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
]

query_embeddings = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embeddings.shape, document_embeddings[0].shape)
# (32, 128) (17, 128)

# MaxSim late-interaction scoring (higher is more relevant)
scores = model.similarity(query_embeddings, document_embeddings)
print(scores)
# tensor([[12.7970, 27.1945, 23.8495, 24.5656]])
```

## Model Details
The model maps query and documents to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.

### Model Description
- **Model Type:** Multi-vector embedding model
- **Base model:** [colbert-ir/colbertv2.0](https://huggingface.co/colbert-ir/colbertv2.0) <!-- at revision c1e84128e85ef755c096a95bdb06b47793b13acf -->
- **Maximum Sequence Length:** 512 tokens
- **Output Dimensionality:** 128 tokens
- **Similarity Function:** Cosine Similarity

### Full Model Architecture

```
ColBERT(
  (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel 
  (1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity'})
)
```

### Citation
```
@inproceedings{santhanam-etal-2022-colbertv2,
    title = "{C}ol{BERT}v2: Effective and Efficient Retrieval via Lightweight Late Interaction",
    author = "Santhanam, Keshav  and
      Khattab, Omar  and
      Saad-Falcon, Jon  and
      Potts, Christopher  and
      Zaharia, Matei",
    editor = "Carpuat, Marine  and
      de Marneffe, Marie-Catherine  and
      Meza Ruiz, Ivan Vladimir",
    booktitle = "Proceedings of the 2022 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
    month = jul,
    year = "2022",
    address = "Seattle, United States",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2022.naacl-main.272",
    doi = "10.18653/v1/2022.naacl-main.272",
    pages = "3715--3734",
    abstract = "Neural information retrieval (IR) has greatly advanced search and other knowledge-intensive language tasks. While many neural IR methods encode queries and documents into single-vector representations, late interaction models produce multi-vector representations at the granularity of each token and decompose relevance modeling into scalable token-level computations. This decomposition has been shown to make late interaction more effective, but it inflates the space footprint of these models by an order of magnitude. In this work, we introduce ColBERTv2, a retriever that couples an aggressive residual compression mechanism with a denoised supervision strategy to simultaneously improve the quality and space footprint of late interaction. We evaluate ColBERTv2 across a wide range of benchmarks, establishing state-of-the-art quality within and outside the training domain while reducing the space footprint of late interaction models by 6{--}10x.",
}
```