-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
79 lines (61 loc) · 1.99 KB
/
Copy pathtesting.py
File metadata and controls
79 lines (61 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 23 09:00:00 2024
Author: Mehdi Abbasi
GitHub: abbassix
"""
# import the necessary libraries
import sys
import yaml
import warnings
import logging
from functions import load_model, load_dataset, accuracy
logging.basicConfig(level=logging.WARNING)
def tokenize_label(example: dict) -> dict:
"""
Tokenize the label columns
"""
return tokenizer(example["unmasked"])
print("Successfully imported the necessary libraries.\n")
# receive the configuration file name from the first argument
config_file = sys.argv[1]
print("Loading the configuration file...\n")
# check for errors in the configuration file
if config_file.endswith(".yaml"):
config_file = config_file[:-5]
try:
with open(f'{config_file}.yaml', 'r') as file:
config = yaml.safe_load(file)
except FileNotFoundError as e:
warnings.warn(
f"Error: The configuration file '{config_file}.yaml' does not exist."
)
logging.error(f"Encountered a problem: {str(e)}")
sys.exit(1)
model_checkpoint = config['model_checkpoint']
test_dataset_name = config['test_dataset_name']
model_name = model_checkpoint.split("/")[-1]
print("Loading the model...\n")
try:
model, tokenizer = load_model(model_checkpoint)
except FileNotFoundError as e:
warnings.warn(
f"Error: The model checkpoint '{model_checkpoint}' does not exist."
)
logging.error(f"Encountered a problem: {str(e)}")
sys.exit(1)
test_dataset_path = f"../datasets/{test_dataset_name}"
print("Loading the test datasets...\n")
try:
test_dataset = load_dataset(test_dataset_path)
except FileNotFoundError as e:
warnings.warn(
f"""
Error: The test datasets '{test_dataset_path}' do not exist.
"""
)
logging.error(f"Encountered a problem: {str(e)}")
sys.exit(1)
print("Calculating the initial test accuracies...\n")
test_dataset_accuracy = accuracy(model, tokenizer, test_dataset)
print(f"test dataset accuracy: {test_dataset_accuracy}")