Views
No views yet
thomas-sounack/BioClinical-ModernBERT-large BERT encoder for RAG applications.thomas-sounack/BioClinical-ModernBERT-large encoder supports up to 8192, but I think this is too long
to support regular popular medical texts which often jump from one topic to another topic.hf command or manually.1# https://huggingface.co/thomas-sounack/BioClinical-ModernBERT-large
2$ mkdir -p "./work/base"
3$ hf download "thomas-sounack/BioClinical-ModernBERT-large" --local-dir "./work/base/BIOCLINICAL_LARGE"1# https://huggingface.co/mazurkin/medclinical
2$ mkdir -p "./work/export/trial-release"
3$ hf download "mazurkin/medclinical" --local-dir "./work/export/trial-release"thomas-sounack/BioClinical-ModernBERT-large to the ./work/base/BIOCLINICAL_LARGE folder):1base = transformers.AutoModel.from_pretrained(
2 './work/base/BIOCLINICAL_LARGE',
3 trust_remote_code=True,
4 local_files_only=True,
5)1base = transformers.AutoModel.from_pretrained(
2 'thomas-sounack/BioClinical-ModernBERT-large',
3 trust_remote_code=True,
4)thomas-sounack/BioClinical-ModernBERT-large to the ./work/base/BIOCLINICAL_LARGE folder):1tokenizer = transformers.AutoTokenizer.from_pretrained(
2 './work/base/BIOCLINICAL_LARGE',
3 local_files_only=True,
4)1tokenizer = transformers.AutoTokenizer.from_pretrained(
2 'thomas-sounack/BioClinical-ModernBERT-large',
3)1model = transformers.AutoModel.from_pretrained(
2 './work/medformer/trial-release',
3 trust_remote_code=True,
4 local_files_only=True,
5 base_encoder=base,
6)1model = transformers.AutoModel.from_pretrained(
2 'mazurkin/medclinical',
3 trust_remote_code=True,
4 base_encoder=base,
5)1texts = [
2 'Type 2 diabetes mellitus with insulin resistance and metabolic syndrome.',
3 'Started on metformin 500mg twice daily for glycemic control in adult-onset diabetes.',
4 'The stock market closed higher today with tech shares leading the gains.',
5]
6
7encoded = tokenizer(
8 texts,
9 padding=True,
10 truncation=True,
11 max_length=1024, # not 8192 as 'thomas-sounack/BioClinical-ModernBERT-base' reports
12 return_tensors='pt',
13)1with torch.inference_mode():
2 outputs = model(
3 input_ids=encoded['input_ids'],
4 attention_mask=encoded['attention_mask'],
5 return_dict=True,
6 )embeddings: torch.Tensor = outputs.norm_embeddingssimilarity_matrix: torch.Tensor = embeddings @ embeddings.T