Views
No views yet
allenai/scibert_scivocab_uncasedallenai/scibert_scivocab_uncased tokenizer.1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model_id = "linh101201/scibert-concept-annotation"
6tokenizer_id = "allenai/scibert_scivocab_uncased"
7
8model = AutoModelForSequenceClassification.from_pretrained(model_id, num_labels=2).to("cuda")
9tokenizer = AutoTokenizer.from_pretrained(tokenizer_id)
10
11# Example inputs: Document text and the Concept to annotate
12text = "Large Language Model in Law Documents Hub"
13concept = "natural language processing"
14
15inputs = tokenizer(text, concept, return_tensors="pt").to("cuda")
16
17with torch.no_grad():
18 logits = model(**inputs).logits
19 # Apply softmax to get probabilities
20 probs = torch.nn.functional.softmax(logits, dim=-1)
21 print(f"Logits: {logits}")
22 print(f"Probabilities: {probs}")