Update README.md
Browse files
README.md
CHANGED
@@ -22,6 +22,7 @@ Use the code below to get started with the model.
|
|
22 |
|
23 |
```
|
24 |
import math
|
|
|
25 |
import pandas as pd
|
26 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
27 |
|
@@ -29,6 +30,8 @@ BATCH_SIZE = 32
|
|
29 |
ds = pd.read_csv('test.csv')
|
30 |
BASE_MODEL = 'HausaNLP/afrisenti-hau-regression'
|
31 |
|
|
|
|
|
32 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
33 |
model = AutoModelForSequenceClassification.from_pretrained(BASE_MODEL)
|
34 |
|
@@ -37,7 +40,7 @@ y_preds = []
|
|
37 |
|
38 |
for i in range(nb_batches):
|
39 |
input_texts = ds[i * BATCH_SIZE: (i+1) * BATCH_SIZE]["tweet"]
|
40 |
-
encoded = tokenizer(input_texts, truncation=True, padding="max_length", max_length=256, return_tensors="pt").to(
|
41 |
y_preds += model(**encoded).logits.reshape(-1).tolist()
|
42 |
|
43 |
df = pd.DataFrame([ds['tweet'], ds['label'], y_preds], ["Text", "Label", "Prediction"]).T
|
|
|
22 |
|
23 |
```
|
24 |
import math
|
25 |
+
import torch
|
26 |
import pandas as pd
|
27 |
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
28 |
|
|
|
30 |
ds = pd.read_csv('test.csv')
|
31 |
BASE_MODEL = 'HausaNLP/afrisenti-hau-regression'
|
32 |
|
33 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
34 |
+
|
35 |
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
36 |
model = AutoModelForSequenceClassification.from_pretrained(BASE_MODEL)
|
37 |
|
|
|
40 |
|
41 |
for i in range(nb_batches):
|
42 |
input_texts = ds[i * BATCH_SIZE: (i+1) * BATCH_SIZE]["tweet"]
|
43 |
+
encoded = tokenizer(input_texts, truncation=True, padding="max_length", max_length=256, return_tensors="pt").to(device)
|
44 |
y_preds += model(**encoded).logits.reshape(-1).tolist()
|
45 |
|
46 |
df = pd.DataFrame([ds['tweet'], ds['label'], y_preds], ["Text", "Label", "Prediction"]).T
|