Views
No views yet
1import txtai
2
3embeddings = txtai.Embeddings(
4 path="neuml/biomedbert-base-colbert",
5 content=True
6)
7embeddings.index(documents())
8
9# Run a query
10embeddings.search("query to run")1from txtai.pipeline import Reranker, Similarity
2
3similarity = Similarity(path="neuml/biomedbert-base-colbert", lateencode=True)
4ranker = Reranker(embeddings, similarity)
5ranker("query to run")MultiVectorEncoder:pip install "sentence-transformers>=6.0.0"1from sentence_transformers import MultiVectorEncoder
2
3model = MultiVectorEncoder("NeuML/biomedbert-base-colbert")
4
5query = "Which planet is known as the Red Planet?"
6documents = [
7 "Venus is often called Earth's twin because of its similar size and proximity.",
8 "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
9 "Jupiter, the largest planet in our solar system, has a prominent red spot.",
10 "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
11]
12
13query_embeddings = model.encode_query(query)
14document_embeddings = model.encode_document(documents)
15print(query_embeddings.shape, document_embeddings[0].shape)
16# (14, 128) (17, 128)
17
18# MaxSim late-interaction scoring (higher is more relevant)
19scores = model.similarity(query_embeddings, document_embeddings)
20print(scores)
21# tensor([[9.9712, 12.4123, 11.0444, 11.9934]])1from pylate import rank, models
2
3queries = [
4 "query A",
5 "query B",
6]
7
8documents = [
9 ["document A", "document B"],
10 ["document 1", "document C", "document B"],
11]
12
13documents_ids = [
14 [1, 2],
15 [1, 3, 2],
16]
17
18model = models.ColBERT(
19 model_name_or_path="neuml/biomedbert-base-colbert",
20)
21
22queries_embeddings = model.encode(
23 queries,
24 is_query=True,
25)
26
27documents_embeddings = model.encode(
28 documents,
29 is_query=False,
30)
31
32reranked_documents = rank.rerank(
33 documents_ids=documents_ids,
34 queries_embeddings=queries_embeddings,
35 documents_embeddings=documents_embeddings,
36)| Model | PubMed QA | PubMed Subset | PubMed Summary | Average |
|---|---|---|---|---|
| all-MiniLM-L6-v2 | 90.40 | 95.92 | 94.07 | 93.46 |
| bioclinical-modernbert-base-embeddings | 92.49 | 97.10 | 97.04 | 95.54 |
| biomedbert-base-colbert | 94.59 | 97.18 | 96.21 | 95.99 |
| biomedbert-base-reranker | 97.66 | 99.76 | 98.81 | 98.74 |
| pubmedbert-base-embeddings | 93.27 | 97.00 | 96.58 | 95.62 |
| pubmedbert-base-embeddings-8M | 90.05 | 94.29 | 94.15 | 92.83 |
ColBERT(
(0): Transformer({'max_seq_length': 511, 'do_lower_case': False, 'architecture': 'BertModel'})
(1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
)