Master Assignment - NLP ๐
Collection
Models trained for master coursework assignment
โข
4 items
โข
Updated
This model fine-tunes BERT (bert-base-uncased) to perform sentiment analysis on climate change-related tweets. It classifies tweets into four sentiment categories: anti-climate (negative), neutral, pro-climate (positive), and news.
This model was trained on the Twitter Climate Change Sentiment Dataset, which contains tweets related to climate change labeled with sentiment categories:
The dataset was cleaned with the following steps:
Features | Strategy |
---|---|
Hashtag | Removed |
Mention | Removed |
RT Tag | Removed |
URL | Removed |
Stop Words | Removed |
Special Characters | Removed |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("google/bert-base-uncased")
model = AutoModelForSequenceClassification.from_pretrained("keanteng/bert-base-clean-climate-sentiment-wqf7007")
# Prepare text
text = "Climate change is real and we need to act now!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
# Make prediction
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.argmax(outputs.logits, dim=1)
# Map prediction to sentiment
sentiment_map = {-1: "anti", 0: "neutral", 1: "pro", 2: "news"}
predicted_sentiment = sentiment_map[predictions.item()]
print("Predicted sentiment: " + predicted_sentiment)
This model should be used responsibly for analyzing climate sentiment and should not be deployed in ways that might:
Base model
google-bert/bert-base-uncased