-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (40 loc) · 1.7 KB
/
main.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
44
45
46
47
48
49
50
51
import os
import tensorflow as tf
import tensorflow.keras as keras
from src.encoder_decoder.training_loop import TrainingLoop
from src.utils.dataset_creators import QADataset
path = 'final_dataset_clean_v2 .tsv'
#os.remove('checkpoint_first')
max_epochs = 2
dataset_creator = QADataset(path)
gpu = True
if gpu:
with tf.device('/GPU:1'):
optimizer = keras.optimizers.Adam()
training_loop = TrainingLoop(dataset_creator, optimizer, D = 14, frac=0.5, checkpoint_folder='checkpoint_first')
training_loop.train(max_epochs, case = 'initial')
else:
print('No GPU!')
optimizer = keras.optimizers.Adam()
training_loop = TrainingLoop(dataset_creator, optimizer, D = 14, frac=1, checkpoint_folder='checkpoint_first')
training_loop.train(10, case = 'initial')
#Expanding dataset:
if gpu:
with tf.device('/GPU:1'):
optimizer = keras.optimizers.Adam()
training_loop = TrainingLoop(dataset_creator, optimizer, D = 14, frac=0.1, checkpoint_folder='checkpoint_KG')
training_loop.train(max_epochs, case = 'anchor')
EM = training_loop.exact_match()
F1 = training_loop.F1_metric(0.5, 0.1)
with open('output.txt', 'w+') as file:
file.write(f'Exact Match--->{EM}')
file.write(f'F1 Metric--->{F1}')
else:
optimizer = keras.optimizers.Adam()
training_loop = TrainingLoop(dataset_creator, optimizer, D = 14, frac=0.1, checkpoint_folder='checkpoint_KG')
training_loop.train(10, case = 'anchor')
EM = training_loop.exact_match()
F1 = training_loop.F1_metric(0.5, 0.1)
with open('output.txt', 'w+') as file:
file.write(f'Exact Match--->{EM}')
file.write(f'F1 Metric--->{F1}')