NaolTaye commited on
Commit
8021f3c
·
verified ·
1 Parent(s): 1814075

Update tasks/text.py

Browse files
Files changed (1) hide show
  1. tasks/text.py +29 -6
tasks/text.py CHANGED
@@ -75,21 +75,44 @@ async def evaluate_text(request: TextEvaluationRequest):
75
  tokenized_test = test_dataset.map(lambda batch: tokenize_frugal(batch, tokenizer), batched=True)
76
 
77
 
78
- dataloader = DataLoader(tokenized_test, batch_size=16, shuffle=False)
79
- print("Started prediction run")
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  model.eval()
 
 
82
  with torch.no_grad():
83
- predictions = np.array([])
84
  for batch in dataloader:
85
- test_input_ids = batch["input_ids"].to(device)
86
- test_attention_mask = batch["attention_mask"].to(device)
87
- outputs = model(test_input_ids, test_attention_mask)
88
  p = torch.argmax(outputs.logits, dim=1)
89
  predictions = np.append(predictions, p.cpu().numpy())
90
 
91
  print("Finished prediction run")
92
 
 
 
 
93
 
94
 
95
  # Make random predictions (placeholder for actual model inference)
 
75
  tokenized_test = test_dataset.map(lambda batch: tokenize_frugal(batch, tokenizer), batched=True)
76
 
77
 
78
+ # dataloader = DataLoader(tokenized_test, batch_size=16, shuffle=False)
79
+ # print("Started prediction run")
80
 
81
+ # model.eval()
82
+ # with torch.no_grad():
83
+ # predictions = np.array([])
84
+ # for batch in dataloader:
85
+ # test_input_ids = batch["input_ids"].to(device)
86
+ # test_attention_mask = batch["attention_mask"].to(device)
87
+ # outputs = model(test_input_ids, test_attention_mask)
88
+ # p = torch.argmax(outputs.logits, dim=1)
89
+ # predictions = np.append(predictions, p.cpu().numpy())
90
+
91
+ # print("Finished prediction run")
92
+ data_collator = DataCollatorWithPadding(tokenizer=tokenizer)
93
+
94
+ # Create DataLoader
95
+ dataloader = DataLoader(tokenized_test, batch_size=16, shuffle=False, collate_fn=data_collator)
96
+
97
+ print("Started prediction run")
98
+
99
+ # Model inference
100
  model.eval()
101
+ predictions = np.array([])
102
+
103
  with torch.no_grad():
 
104
  for batch in dataloader:
105
+ batch = {k: v.to(device) for k, v in batch.items()} # Move batch to GPU
106
+
107
+ outputs = model(**batch) # Correct way to pass inputs
108
  p = torch.argmax(outputs.logits, dim=1)
109
  predictions = np.append(predictions, p.cpu().numpy())
110
 
111
  print("Finished prediction run")
112
 
113
+ # Ensure "label" column exists in dataset
114
+ print(test_dataset.column_names) # Debugging step
115
+
116
 
117
 
118
  # Make random predictions (placeholder for actual model inference)