Views
No views yet
distilbert-base-uncased1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load the model and tokenizer
5model_name = "your-username/SciTopicSentimentClassifier" # Replace with actual HuggingFace path
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Sample Abstract
10abstract = "We propose a novel architecture combining convolutional and recurrent neural networks for multi-modal data fusion, demonstrating significant performance gains in complex classification tasks, overcoming prior limitations."
11
12# Preprocess the input
13inputs = tokenizer(abstract, return_tensors="pt", truncation=True, padding=True)
14
15# Run inference
16with torch.no_grad():
17 logits = model(**inputs).logits
18
19# Apply sigmoid for multi-label scores
20probs = torch.sigmoid(logits)
21
22# Get predicted labels (e.g., probability > 0.5)
23labels = model.config.id2label
24predictions = []
25for i, prob in enumerate(probs[0]):
26 if prob > 0.5:
27 predictions.append(labels[i])
28
29print(f"Abstract: {abstract[:80]}...")
30print(f"Predicted Labels: {predictions}")
31# Expected Output: ['Deep Learning/AI', 'High-Positive-Sentiment']