File size: 1,273 Bytes
0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 0d7c83a 5ffbd85 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
---
library_name: transformers
tags: []
---
## AfriSenti Twi Sentiment Regressor Description
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 |
## How to Get Started with the Model
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-twi-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)
``` |