(model, val_dataloader)
| 195 | break |
| 196 | |
| 197 | def validate(model, val_dataloader): |
| 198 | model.eval() |
| 199 | total_val_accuracy = 0 |
| 200 | |
| 201 | with torch.no_grad(): |
| 202 | for batch in val_dataloader: |
| 203 | input_ids = batch['input_ids'].to(device) |
| 204 | attention_mask = batch['attention_mask'].to(device) |
| 205 | approaches = batch['approaches'].to(device) |
| 206 | ranks = batch['ranks'].to(device) |
| 207 | tokens = batch['tokens'].to(device) |
| 208 | |
| 209 | effort = (tokens - tokens.min()) / (tokens.max() - tokens.min()) |
| 210 | best_approach_indices = ranks.argmin(dim=1) |
| 211 | |
| 212 | logits = model(input_ids, attention_mask, effort[:, 0]) |
| 213 | predictions = torch.argmax(logits, dim=-1) |
| 214 | total_val_accuracy += calculate_accuracy(predictions, best_approach_indices) |
| 215 | |
| 216 | return total_val_accuracy / len(val_dataloader) |
| 217 | |
| 218 | def inference(model, tokenizer, prompt, effort_levels): |
| 219 | model.eval() |
no test coverage detected