Add Sentence Transformers usage

#2
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +35 -1
README.md CHANGED
@@ -1,6 +1,7 @@
1
  ---
2
  tags:
3
  - ColBERT
 
4
  - PyLate
5
  - sentence-transformers
6
  - sentence-similarity
@@ -20,7 +21,7 @@ language:
20
  ## Model Details
21
 
22
  ### Model Description
23
- - **Model Type:** PyLate model
24
  - **Document Length:** 1024 tokens
25
  - **Query Length:** 32 tokens
26
  - **Output Dimensionality:** 128 tokens
@@ -61,6 +62,39 @@ We omit MIRACLRetrieval and MrTidyRetrieval in evalution due to our device condi
61
  | [jina-colbert-v2](https://huggingface.co/jinaai/jina-colbert-v2) | 0.5B | 0.7518 | 0.0888 | 0.6671 | 0.1577 |
62
 
63
  ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  ### PyLate for reranking
65
 
66
  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:
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
21
  ## Model Details
22
 
23
  ### Model Description
24
+ - **Model Type:** Multi-vector embedding model
25
  - **Document Length:** 1024 tokens
26
  - **Query Length:** 32 tokens
27
  - **Output Dimensionality:** 128 tokens
 
62
  | [jina-colbert-v2](https://huggingface.co/jinaai/jina-colbert-v2) | 0.5B | 0.7518 | 0.0888 | 0.6671 | 0.1577 |
63
 
64
  ## Usage
65
+
66
+ ### Sentence Transformers
67
+
68
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
69
+
70
+ ```bash
71
+ pip install "sentence-transformers>=6.0.0"
72
+ ```
73
+
74
+ ```python
75
+ from sentence_transformers import MultiVectorEncoder
76
+
77
+ model = MultiVectorEncoder("yjoonjang/colbert-ko-v1")
78
+
79
+ query = "๋ถ‰์€ ํ–‰์„ฑ์œผ๋กœ ์•Œ๋ ค์ง„ ํ–‰์„ฑ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?"
80
+ documents = [
81
+ "๊ธˆ์„ฑ์€ ํฌ๊ธฐ์™€ ๊ทผ์ ‘์„ฑ์ด ๋น„์Šทํ•˜์—ฌ ์ข…์ข… ์ง€๊ตฌ์˜ ์Œ๋‘ฅ์ด๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.",
82
+ "ํ™”์„ฑ์€ ๋ถ‰์€ ๊ฒ‰๋ชจ์Šต ๋•Œ๋ฌธ์— ์ข…์ข… ๋ถ‰์€ ํ–‰์„ฑ์ด๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.",
83
+ "ํƒœ์–‘๊ณ„์—์„œ ๊ฐ€์žฅ ํฐ ํ–‰์„ฑ์ธ ๋ชฉ์„ฑ์—๋Š” ๋šœ๋ ทํ•œ ๋ถ‰์€ ๋ฐ˜์ ์ด ์žˆ๋‹ค.",
84
+ "๊ณ ๋ฆฌ๋กœ ์œ ๋ช…ํ•œ ํ† ์„ฑ์€ ๋•Œ๋•Œ๋กœ ๋ถ‰์€ ํ–‰์„ฑ์œผ๋กœ ์˜ค์ธ๋œ๋‹ค.",
85
+ ]
86
+
87
+ query_embeddings = model.encode_query(query)
88
+ document_embeddings = model.encode_document(documents)
89
+ print(query_embeddings.shape, document_embeddings[0].shape)
90
+ # (32, 128) (19, 128)
91
+
92
+ # MaxSim late-interaction scoring (higher is more relevant)
93
+ scores = model.similarity(query_embeddings, document_embeddings)
94
+ print(scores)
95
+ # tensor([[10.9423, 22.7836, 19.7410, 22.4239]])
96
+ ```
97
+
98
  ### PyLate for reranking
99
 
100
  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: