Model reference · open weights
SapBERT-UMLS-2020AB-all-lang-from-XLMR is an open-weight embedding model from cambridgeltl. AxForge deploys and operates it for you on dedicated EU-owned hardware — with the licence handled where one is required.
Available as managed deployment — configured and operated for you on dedicated EU hardware, quoted per deployment.
What it is
| Released by | cambridgeltl |
|---|---|
| Type | Embedding models |
| Task | Embeddings |
| Parameters (lead) | 278M |
| Context | 514 tokens |
| Runs with | transformers |
| Released | 2022-03-02 |
| Popularity | 200k downloads / month |
| Licence | Unknown |
About
language: multilingual
tags:
datasets:
[news] A cross-lingual extension of SapBERT will appear in the main onference of ACL 2021! [news] SapBERT will appear in the conference proceedings of NAACL 2021!
SapBERT (Liu et al. 2020) trained with UMLS 2020AB, using xlm-roberta-base as the base model. Please use [CLS] as the representation of the input.
The following script converts a list of strings (entity names) into embeddings.
import numpy as np
import torch
from tqdm.auto import tqdm
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("cambridgeltl/SapBERT-from-PubMedBERT-fulltext")
model = AutoModel.from_pretrained("cambridgeltl/SapBERT-from-PubMedBERT-fulltext").cuda()
# replace with your own list of entity names
all_names = ["covid-19", "Coronavirus infection", "high fever", "Tumor of posterior wall of oropharynx"]
bs = 128 # batch size during inference
all_embs = []
for i in tqdm(np.arange(0, len(all_names), bs)):
toks = tokenizer.batch_encode_plus(all_names[i:i+bs],
padding="max_length",
max_length=25,
truncation=True,
return_tensors="pt")
toks_cuda = {}
for k,v in toks.items():
toks_cuda[k] = v.cuda()
cls_rep = model(**toks_cuda)[0][:,0,:] # use CLS representation as the embedding
all_embs.append(cls_rep.cpu().detach().numpy())
all_embs = np.concatenate(all_embs, axis=0)
For more details about training and eval, see SapBERT github repo.
@inproceedings{liu2021learning,
title={Learning Domain-Specialised Representations for Cross-Lingual Biomedical Entity Linking},
author={Liu, Fangyu and Vuli{\'c}, Ivan and Korhonen, Anna and Collier, Nigel},
booktitle={Proceedings of ACL-IJCNLP 2021},
month = aug,
year={2021}
}
From the published model card. Full card on the HuggingFace links in the sidebar.
Using it via the API
Once AxForge deploys sapbert-umls-2020ab-all-lang-from-xlmr for you, it answers on the OpenAI-compatible API — the same base URL and keys as every other model. (sapbert-umls-2020ab-all-lang-from-xlmr below is illustrative; you get the exact model name on deployment.)
$ curl -sS https://api.axforge.ai/v1/embeddings \
-H "Authorization: Bearer $AXFORGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"sapbert-umls-2020ab-all-lang-from-xlmr","input":"text to embed"}'
Create an account — your API key is available in the console. 3M free tokens every 30 days with every new account.