Views
No views yet
| Features | Strategy |
|---|---|
| Hashtag | Kept |
| Mention | Generalized |
| RT Tag | Generalized |
| URL | Generalized |
| Stop Words | Kept |
| Special Characters | Removed |


1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("google/bert-base-uncased")
6model = AutoModelForSequenceClassification.from_pretrained("keanteng/bert-base-generalized-climate-sentiment-wqf7007")
7
8# Prepare text
9text = "Climate change is real and we need to act now!"
10inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
11
12# Make prediction
13with torch.no_grad():
14 outputs = model(**inputs)
15 predictions = torch.argmax(outputs.logits, dim=1)
16
17# Map prediction to sentiment
18sentiment_map = {-1: "anti", 0: "neutral", 1: "pro", 2: "news"}
19predicted_sentiment = sentiment_map[predictions.item()]
20print("Predicted sentiment: " + predicted_sentiment)