Views
No views yet
bert-base-uncased architecture and is ideal for automating the categorization and high-level assessment of large volumes of academic literature.BertForSequenceClassification head, configured for a multi-label setup.bert-base-uncased1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "Your-HF-Username/SciAbstract-MultiLabel-BERT-Base"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Sample abstract
10abstract = "Development of a quantum entanglement system achieving coherence for over 10 seconds at room temperature, a significant breakthrough for quantum computing."
11
12# Tokenize input
13inputs = tokenizer(abstract, return_tensors="pt", truncation=True, padding=True)
14
15# Make prediction
16with torch.no_grad():
17 logits = model(**inputs).logits
18
19# Apply sigmoid to get probabilities for each label
20probabilities = torch.sigmoid(logits).squeeze()
21
22# Get the label IDs and names
23id2label = model.config.id2label
24predicted_labels = [id2label[i] for i, prob in enumerate(probabilities) if prob > 0.5] # Threshold at 0.5
25
26print(f"Abstract: {abstract}")
27print("-" * 30)
28print(f"Predicted Labels: {predicted_labels}")
29# Expected Output Example: ['Topic: Physics', 'Sentiment: Highly Positive']