Downloads · 30 days
10
16% of all-time downloads
HausaNLP/afrisenti-pcm-regression
afrisenti-pcm-regression is a text classification model from HausaNLP. Use it when you need a label for a piece of text. It is set up for transformers.
Takes a text and predicts the sentiment value between -1 (Negative) to 1 (Positive) with 0 being Neutral.
Downloads · 30 days
10
16% of all-time downloads
All-time downloads
61
Public
Parameters
178M
711 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors711 MB · 99%
From the Hugging Face model README
Takes a text and predicts the sentiment value between -1 (Negative) to 1 (Positive) with 0 being Neutral.
Regression Value Description:
| Value | Sentiment |
|---|---|
| -1 | Negative |
| 0 | Neutral |
| 1 | Positive |
Use the code below to get started with the model.
import math
import torch
import pandas as pd
from transformers import AutoModelForSequenceClassification, AutoTokenizer
BATCH_SIZE = 32
ds = pd.read_csv('test.csv')
BASE_MODEL = 'HausaNLP/afrisenti-pcm-regression'
device = 'cuda' if torch.cuda.is_available() else 'cpu'
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
model = AutoModelForSequenceClassification.from_pretrained(BASE_MODEL)
nb_batches = math.ceil(len(ds)/BATCH_SIZE)
y_preds = []
for i in range(nb_batches):
input_texts = ds[i * BATCH_SIZE: (i+1) * BATCH_SIZE]["tweet"]
encoded = tokenizer(input_texts, truncation=True, padding="max_length", max_length=256, return_tensors="pt").to(device)
y_preds += model(**encoded).logits.reshape(-1).tolist()
df = pd.DataFrame([ds['tweet'], ds['label'], y_preds], ["Text", "Label", "Prediction"]).T
df.to_csv('predictions.csv', index=False)