🙏 If you are able to, please help me fund my open research. 🙏 Thank you for your generosity! 🤗
FremyCompany/BioLORD-2023
This model was trained using BioLORD, a new pre-training strategy for producing meaningful representations for clinical sentences and biomedical concepts.
State-of-the-art methodologies operate by maximizing the similarity in representation of names referring to the same concept, and preventing collapse through contrastive learning. However, because biomedical names are not always self-explanatory, it sometimes results in non-semantic representations.
BioLORD overcomes this issue by grounding its concept representations using definitions, as well as short descriptions derived from a multi-relational knowledge graph consisting of biomedical ontologies. Thanks to this grounding, our model produces more semantic concept representations that match more closely the hierarchical structure of ontologies. BioLORD-2023 establishes a new state of the art for text similarity on both clinical sentences (MedSTS) and biomedical concepts (EHR-Rel-B).
1@article{remy-etal-2023-biolord,
2 author = {Remy, François and Demuynck, Kris and Demeester, Thomas},
3 title = "{BioLORD-2023: semantic textual representations fusing large language models and clinical knowledge graph insights}",
4 journal = {Journal of the American Medical Informatics Association},
5 pages = {ocae029},
6 year = {2024},
7 month = {02},
8 issn = {1527-974X},
9 doi = {10.1093/jamia/ocae029},
10 url = {https://doi.org/10.1093/jamia/ocae029},
11 eprint = {https://academic.oup.com/jamia/advance-article-pdf/doi/10.1093/jamia/ocae029/56772025/ocae029.pdf},
12}
Usage (Sentence-Transformers)
This is a sentence-transformers model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search. This model has been finentuned for the biomedical domain. While it preserves a good ability to produce embeddings for general-purpose text, it will be more useful to you if you are trying to process medical documents such as EHR records or clinical notes. Both sentences and phrases can be embedded in the same latent space.
Without sentence-transformers, you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
python
1from transformers import AutoTokenizer, AutoModel
2import torch
3import torch.nn.functional as F
45#Mean Pooling - Take attention mask into account for correct averaging6defmean_pooling(model_output, attention_mask):7 token_embeddings = model_output[0]#First element of model_output contains all token embeddings8 input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()9return torch.sum(token_embeddings * input_mask_expanded,1)/ torch.clamp(input_mask_expanded.sum(1),min=1e-9)1011# Sentences we want sentence embeddings for12sentences =["Cat scratch injury","Cat scratch disease","Bartonellosis"]1314# Load model from HuggingFace Hub15tokenizer = AutoTokenizer.from_pretrained('FremyCompany/BioLORD-2023')16model = AutoModel.from_pretrained('FremyCompany/BioLORD-2023')1718# Tokenize sentences19encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')2021# Compute token embeddings22with torch.no_grad():23 model_output = model(**encoded_input)24# Perform pooling25sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])26# Normalize embeddings27sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)28print("Sentence embeddings:")29print(sentence_embeddings)
License
My own contributions for this model are covered by the MIT license.
However, given the data used to train this model originates from UMLS and SnomedCT, you will need to ensure you have proper licensing of UMLS and SnomedCT before using this model. Both UMLS and SnomedCT are free of charge in most countries, but you might have to create an account and report on your usage of the data yearly to keep a valid license.