davidmezzetti commited on
Commit
016e7d6
·
1 Parent(s): a61b777

Initial version

Browse files
1_Dense/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "in_features": 768,
3
+ "out_features": 128,
4
+ "bias": false,
5
+ "activation_function": "torch.nn.modules.linear.Identity",
6
+ "use_residual": false
7
+ }
1_Dense/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fb7c9578d288d3a99449896b8b51dd8baec9f9df3a660234d8f6536bc0e40458
3
+ size 393304
README.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - ColBERT
4
+ - PyLate
5
+ - sentence-transformers
6
+ - sentence-similarity
7
+ - feature-extraction
8
+ - generated_from_trainer
9
+ - loss:Distillation
10
+ base_model: microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext
11
+ pipeline_tag: sentence-similarity
12
+ library_name: PyLate
13
+ language: en
14
+ license: apache-2.0
15
+ ---
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
+
23
+ This model can be used to build embeddings databases with [txtai](https://github.com/neuml/txtai) for semantic search and/or as a knowledge source for retrieval augmented generation (RAG).
24
+
25
+ ```python
26
+ import txtai
27
+
28
+ embeddings = txtai.Embeddings(
29
+ path="neuml/biomedbert-base-colbert",
30
+ content=True
31
+ )
32
+ embeddings.index(documents())
33
+
34
+ # Run a query
35
+ embeddings.search("query to run")
36
+ ```
37
+
38
+ Late interaction models excel as reranker pipelines.
39
+
40
+ ```python
41
+ from txtai.pipeline import Reranker, Similarity
42
+
43
+ similarity = Similarity(path="neuml/biomedbert-base-colbert", lateencode=True)
44
+ 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).
51
+
52
+ ```python
53
+ from pylate import rank, models
54
+
55
+ queries = [
56
+ "query A",
57
+ "query B",
58
+ ]
59
+
60
+ documents = [
61
+ ["document A", "document B"],
62
+ ["document 1", "document C", "document B"],
63
+ ]
64
+
65
+ documents_ids = [
66
+ [1, 2],
67
+ [1, 3, 2],
68
+ ]
69
+
70
+ model = models.ColBERT(
71
+ model_name_or_path="neuml/biomedbert-base-colbert",
72
+ )
73
+
74
+ queries_embeddings = model.encode(
75
+ queries,
76
+ is_query=True,
77
+ )
78
+
79
+ documents_embeddings = model.encode(
80
+ documents,
81
+ is_query=False,
82
+ )
83
+
84
+ reranked_documents = rank.rerank(
85
+ documents_ids=documents_ids,
86
+ queries_embeddings=queries_embeddings,
87
+ documents_embeddings=documents_embeddings,
88
+ )
89
+ ```
90
+
91
+ ## Evaluation Results
92
+
93
+ Performance of these models are compared to previously released models trained on medical literature. The most commonly used small embeddings model is also included for comparison.
94
+
95
+ The following datasets were used to evaluate model performance.
96
+
97
+ - [PubMed QA](https://huggingface.co/datasets/qiaojin/PubMedQA)
98
+ - Subset: pqa_labeled, Split: train, Pair: (question, long_answer)
99
+ - [PubMed Subset](https://huggingface.co/datasets/awinml/pubmed_abstract_3_1k)
100
+ - Split: test, Pair: (title, text)
101
+ - [PubMed Summary](https://huggingface.co/datasets/armanc/scientific_papers)
102
+ - Subset: pubmed, Split: validation, Pair: (article, abstract)
103
+
104
+ Evaluation results are shown below. The [Pearson correlation coefficient](https://en.wikipedia.org/wiki/Pearson_correlation_coefficient) is used as the evaluation metric.
105
+
106
+ | Model | PubMed QA | PubMed Subset | PubMed Summary | Average |
107
+ | ----------------------------------------------------- | --------- | ------------- | -------------- | --------- |
108
+ | [all-MiniLM-L6-v2](https://hf.co/sentence-transformers/all-MiniLM-L6-v2) | 90.40 | 95.92 | 94.07 | 93.46 |
109
+ | [bioclinical-modernbert-base-embeddings](https://hf.co/neuml/bioclinical-modernbert-base-embeddings) | 92.49 | 97.10 | 97.04 | 95.54 |
110
+ | [**biomedbert-base-colbert**](https://hf.co/neuml/biomedbert-base-colbert) | **94.59** | **97.18** | **96.21** | **95.99**|
111
+ | [biomedbert-base-reranker](https://hf.co/neuml/biomedbert-base-reranker) | 97.66 | 99.76 | 98.81 | 98.74 |
112
+ | [pubmedbert-base-embeddings](https://hf.co/neuml/pubmedbert-base-embeddings) | 93.27 | 97.00 | 96.58 | 95.62 |
113
+ | [pubmedbert-base-embeddings-8M](https://hf.co/neuml/pubmedbert-base-embeddings-8M) | 90.05 | 94.29 | 94.15 | 92.83 |
114
+
115
+ This is the best performing model we've released that's not a cross-encoder. With [MUVERA encoding](https://arxiv.org/abs/2405.19504), this model can be used to index large datasets for semantic search. It can also be used as a faster re-ranker vs. a cross-encoder model.
116
+
117
+ ## Full Model Architecture
118
+
119
+ ```
120
+ ColBERT(
121
+ (0): Transformer({'max_seq_length': 511, 'do_lower_case': False, 'architecture': 'BertModel'})
122
+ (1): Dense({'in_features': 768, 'out_features': 128, 'bias': False, 'activation_function': 'torch.nn.modules.linear.Identity', 'use_residual': False})
123
+ )
124
+ ```
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "[D] ": 30523,
3
+ "[Q] ": 30522
4
+ }
config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "float32",
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "transformers_version": "4.56.2",
21
+ "type_vocab_size": 2,
22
+ "use_cache": true,
23
+ "vocab_size": 30524
24
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "ColBERT",
3
+ "__version__": {
4
+ "sentence_transformers": "5.1.1",
5
+ "transformers": "4.56.2",
6
+ "pytorch": "2.8.0+cu128"
7
+ },
8
+ "prompts": {
9
+ "query": "",
10
+ "document": ""
11
+ },
12
+ "default_prompt_name": null,
13
+ "similarity_fn_name": "MaxSim",
14
+ "query_prefix": "[Q] ",
15
+ "document_prefix": "[D] ",
16
+ "query_length": 512,
17
+ "document_length": 512,
18
+ "attend_to_expansion_tokens": false,
19
+ "skiplist_words": [
20
+ "!",
21
+ "\"",
22
+ "#",
23
+ "$",
24
+ "%",
25
+ "&",
26
+ "'",
27
+ "(",
28
+ ")",
29
+ "*",
30
+ "+",
31
+ ",",
32
+ "-",
33
+ ".",
34
+ "/",
35
+ ":",
36
+ ";",
37
+ "<",
38
+ "=",
39
+ ">",
40
+ "?",
41
+ "@",
42
+ "[",
43
+ "\\",
44
+ "]",
45
+ "^",
46
+ "_",
47
+ "`",
48
+ "{",
49
+ "|",
50
+ "}",
51
+ "~"
52
+ ],
53
+ "do_query_expansion": false
54
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4131c1dc7cffa118b6e4bb365621c4b73bba11ff331881c503ac5284950fc7e4
3
+ size 437957472
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Dense",
12
+ "type": "pylate.models.Dense.Dense"
13
+ }
14
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 511,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "[MASK]",
17
+ "sep_token": {
18
+ "content": "[SEP]",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ },
24
+ "unk_token": {
25
+ "content": "[UNK]",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "30522": {
44
+ "content": "[Q] ",
45
+ "lstrip": false,
46
+ "normalized": true,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": false
50
+ },
51
+ "30523": {
52
+ "content": "[D] ",
53
+ "lstrip": false,
54
+ "normalized": true,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": false
58
+ }
59
+ },
60
+ "clean_up_tokenization_spaces": true,
61
+ "cls_token": "[CLS]",
62
+ "do_basic_tokenize": true,
63
+ "do_lower_case": true,
64
+ "extra_special_tokens": {},
65
+ "mask_token": "[MASK]",
66
+ "max_length": 511,
67
+ "model_max_length": 511,
68
+ "never_split": null,
69
+ "pad_to_multiple_of": null,
70
+ "pad_token": "[MASK]",
71
+ "pad_token_type_id": 0,
72
+ "padding_side": "right",
73
+ "sep_token": "[SEP]",
74
+ "stride": 0,
75
+ "strip_accents": null,
76
+ "tokenize_chinese_chars": true,
77
+ "tokenizer_class": "BertTokenizer",
78
+ "truncation_side": "right",
79
+ "truncation_strategy": "longest_first",
80
+ "unk_token": "[UNK]"
81
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff