tomaarsen HF Staff commited on
Commit
2813c78
·
verified ·
1 Parent(s): 0fef457

Add Sentence Transformers usage

Browse files
Files changed (1) hide show
  1. README.md +35 -0
README.md CHANGED
@@ -40,6 +40,41 @@ objective, while a false-negative-masked InfoNCE term preserves a direct retriev
40
 
41
  ## Usage
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  ```python
44
  from pylate import models
45
 
 
40
 
41
  ## Usage
42
 
43
+ ### Sentence Transformers
44
+
45
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector
46
+ (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
47
+
48
+ ```bash
49
+ pip install "sentence-transformers>=6.0.0"
50
+ ```
51
+
52
+ ```python
53
+ from sentence_transformers import MultiVectorEncoder
54
+
55
+ model = MultiVectorEncoder("chungimungi/GLInt")
56
+
57
+ query = "Which planet is known as the Red Planet?"
58
+ documents = [
59
+ "Venus is often called Earth's twin because of its similar size and proximity.",
60
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
61
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
62
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
63
+ ]
64
+
65
+ query_embeddings = model.encode_query(query)
66
+ document_embeddings = model.encode_document(documents)
67
+ print(query_embeddings.shape, document_embeddings[0].shape)
68
+ # torch.Size([12, 128]) torch.Size([18, 128])
69
+
70
+ # MaxSim late-interaction scoring (higher is more relevant)
71
+ scores = model.similarity(query_embeddings, document_embeddings)
72
+ print(scores)
73
+ # tensor([[11.6192, 11.7344, 11.6513, 11.7105]], device='cuda:0')
74
+ ```
75
+
76
+ ### PyLate
77
+
78
  ```python
79
  from pylate import models
80