-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestOfTheCode.py
43 lines (29 loc) · 969 Bytes
/
RestOfTheCode.py
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
def load_config(file_path):
with open(file_path,'r') as file:
return yaml.safe_load(file)
def load_data(file_path):
pass
def evaluate(model, texts, labels):
predictions = model.predict(texts)
accuracy = ((predictions > 0.5).float() == labels).float().mean()
return accuracy.item()
# main script
def main():
config = load_config('config.yaml')
train_texts, train_labels = load_data('train_data.txt')
test_texts,test_labels = load_data('test_data.txt')
classifier = GPT2Classifier(config)
classifier.train(train_texts,train_labels)
accuracy = evaluate(classifier,test_texts,test_labels)
print(f"test accuracy:{accuracy}")
# Inference
new_text = "This is a new prompt to classify."
prediction = classifier.predict([new_text])
print(f"Prediction for '{new_text}': {prediction.item()}")
# 9. Testing
def run_tests():
# Implement test cases here
pass
if __name__ == "__main__":
main()
run_tests()