How can I use it in locally on CPU

#8
by Jahanzaib006201 - opened

Hi,
kindly guide me how can i use this model locally on CPU. I want to explore this model if anyone knows about it kindly share the way to use it. Thank you!

Here's how to use emilyalsentzer/Bio_ClinicalBERT with Hugging Face's transformers library:

from transformers import AutoTokenizer, AutoModel

tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
model = AutoModel.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")

Encode Text:

text = "The patient was prescribed 5mg of Coumadin."
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
outputs = model(**inputs)

# Extract embeddings
last_hidden_state = outputs.last_hidden_state  # shape: (1, seq_len, hidden_dim)
cls_embedding = last_hidden_state[:, 0, :]     # [CLS] token embedding

Sign up or log in to comment