abumafrim commited on
Commit
298c937
·
verified ·
1 Parent(s): f215b4c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +4 -1
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("cuda")
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