Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +37 -1
README.md CHANGED
@@ -1,6 +1,7 @@
1
  ---
2
  tags:
3
  - ColBERT
 
4
  - PyLate
5
  - sentence-transformers
6
  - sentence-similarity
@@ -977,7 +978,7 @@ For production deployment of ColBERT-Zero and other multi-vector models, check o
977
  ## Model Details
978
 
979
  ### Model Description
980
- - **Model Type:** PyLate model
981
  <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
982
  - **Document Length:** 519 tokens
983
  - **Query Length:** 39 tokens
@@ -1004,6 +1005,41 @@ ColBERT(
1004
  ```
1005
 
1006
  ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1007
  First install the PyLate library:
1008
 
1009
  ```bash
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
978
  ## Model Details
979
 
980
  ### Model Description
981
+ - **Model Type:** Multi-vector embedding model
982
  <!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
983
  - **Document Length:** 519 tokens
984
  - **Query Length:** 39 tokens
 
1005
  ```
1006
 
1007
  ## Usage
1008
+
1009
+ ### Sentence Transformers
1010
+
1011
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
1012
+
1013
+ ```bash
1014
+ pip install "sentence-transformers>=6.0.0"
1015
+ ```
1016
+
1017
+ ```python
1018
+ from sentence_transformers import MultiVectorEncoder
1019
+
1020
+ model = MultiVectorEncoder("lightonai/ColBERT-Zero")
1021
+
1022
+ query = "Which planet is known as the Red Planet?"
1023
+ documents = [
1024
+ "Venus is often called Earth's twin because of its similar size and proximity.",
1025
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
1026
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
1027
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
1028
+ ]
1029
+
1030
+ query_embeddings = model.encode_query(query)
1031
+ document_embeddings = model.encode_document(documents)
1032
+ print(query_embeddings.shape, document_embeddings[0].shape)
1033
+ # (15, 128) (18, 128)
1034
+
1035
+ # MaxSim late-interaction scoring (higher is more relevant)
1036
+ scores = model.similarity(query_embeddings, document_embeddings)
1037
+ print(scores)
1038
+ # tensor([[11.8153, 12.9256, 12.2893, 12.6730]])
1039
+ ```
1040
+
1041
+ ### PyLate
1042
+
1043
  First install the PyLate library:
1044
 
1045
  ```bash