| |
| |
|
|
| from transformers import AutoTokenizer, AutoModel |
| import torch |
|
|
| def load_scibert(): |
| """ |
| Downloads and loads the SciBERT model from Hugging Face. |
| Model: allenai/scibert_scivocab_uncased |
| """ |
| model_name = "allenai/scibert_scivocab_uncased" |
|
|
| print(f"๐ฝ Downloading and loading model: {model_name}") |
|
|
| |
| tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
|
| |
| model = AutoModel.from_pretrained(model_name, torch_dtype="auto") |
|
|
| print("โ
SciBERT model and tokenizer successfully loaded!") |
| return tokenizer, model |
|
|
| if __name__ == "__main__": |
| tokenizer, model = load_scibert() |
|
|
| |
| text = "Artificial intelligence is revolutionizing scientific research." |
| inputs = tokenizer(text, return_tensors="pt") |
| with torch.no_grad(): |
| outputs = model(**inputs) |
|
|
| print("๐ Model output shape:", outputs.last_hidden_state.shape) |