Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +34 -1
README.md CHANGED
@@ -1,5 +1,6 @@
1
  ---
2
  tags:
 
3
  - ColBERT
4
  - PyLate
5
  - sentence-transformers
@@ -16,7 +17,7 @@ license: apache-2.0
16
 
17
  # BiomedBERT ColBERT
18
 
19
- This is a [PyLate](https://github.com/lightonai/pylate) model finetuned from [microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext](https://huggingface.co/microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext). It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
20
 
21
  ## Usage (txtai)
22
 
@@ -45,6 +46,38 @@ ranker = Reranker(embeddings, similarity)
45
  ranker("query to run")
46
  ```
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  ## Usage (PyLate)
49
 
50
  Alternatively, the model can be loaded with [PyLate](https://github.com/lightonai/pylate).
 
1
  ---
2
  tags:
3
+ - multi-vector
4
  - ColBERT
5
  - PyLate
6
  - sentence-transformers
 
17
 
18
  # BiomedBERT ColBERT
19
 
20
+ This is a multi-vector (ColBERT-style late interaction) embedding model finetuned from [microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext](https://huggingface.co/microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext). It maps sentences & paragraphs to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
21
 
22
  ## Usage (txtai)
23
 
 
46
  ranker("query to run")
47
  ```
48
 
49
+ ## Usage (Sentence Transformers)
50
+
51
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
52
+
53
+ ```bash
54
+ pip install "sentence-transformers>=6.0.0"
55
+ ```
56
+
57
+ ```python
58
+ from sentence_transformers import MultiVectorEncoder
59
+
60
+ model = MultiVectorEncoder("NeuML/biomedbert-base-colbert")
61
+
62
+ query = "Which planet is known as the Red Planet?"
63
+ documents = [
64
+ "Venus is often called Earth's twin because of its similar size and proximity.",
65
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
66
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
67
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
68
+ ]
69
+
70
+ query_embeddings = model.encode_query(query)
71
+ document_embeddings = model.encode_document(documents)
72
+ print(query_embeddings.shape, document_embeddings[0].shape)
73
+ # (14, 128) (17, 128)
74
+
75
+ # MaxSim late-interaction scoring (higher is more relevant)
76
+ scores = model.similarity(query_embeddings, document_embeddings)
77
+ print(scores)
78
+ # tensor([[9.9712, 12.4123, 11.0444, 11.9934]])
79
+ ```
80
+
81
  ## Usage (PyLate)
82
 
83
  Alternatively, the model can be loaded with [PyLate](https://github.com/lightonai/pylate).