dnnsdunca commited on
Commit
690827e
1 Parent(s): 718f9ec

Create eval.csv

Browse files
Files changed (1) hide show
  1. eval.csv +32 -0
eval.csv ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import Trainer, AutoModelForSequenceClassification, AutoTokenizer
2
+ from datasets import load_dataset, load_metric
3
+ import json
4
+
5
+ # Load configuration
6
+ with open('../config/config.json') as f:
7
+ config = json.load(f)
8
+
9
+ # Load model and tokenizer
10
+ model = AutoModelForSequenceClassification.from_pretrained('../model')
11
+ tokenizer = AutoTokenizer.from_pretrained(config['model_name'])
12
+
13
+ # Load dataset
14
+ dataset = load_dataset('csv', data_files={'test': '../data/test.csv'})
15
+ tokenized_datasets = dataset.map(lambda x: tokenizer(x['text'], padding="max_length", truncation=True), batched=True)
16
+
17
+ # Evaluation
18
+ metric = load_metric("accuracy")
19
+
20
+ def compute_metrics(eval_pred):
21
+ logits, labels = eval_pred
22
+ predictions = logits.argmax(axis=-1)
23
+ return metric.compute(predictions=predictions, references=labels)
24
+
25
+ trainer = Trainer(
26
+ model=model,
27
+ tokenizer=tokenizer,
28
+ compute_metrics=compute_metrics
29
+ )
30
+
31
+ results = trainer.evaluate(tokenized_datasets['test'])
32
+ print(results)