adding patience to cmd line args
This commit is contained in:
parent
c8a0b725fc
commit
7cf29732c5
43
src/main.py
43
src/main.py
|
@ -59,7 +59,7 @@ def instantiate_model(A, index, pad_index, device):
|
||||||
channels_out=opt.chout,
|
channels_out=opt.chout,
|
||||||
kernel_sizes=opt.kernelsizes),
|
kernel_sizes=opt.kernelsizes),
|
||||||
ff=FFProjection(input_size=len(opt.kernelsizes) * opt.chout,
|
ff=FFProjection(input_size=len(opt.kernelsizes) * opt.chout,
|
||||||
hidden_sizes=[512],
|
hidden_sizes=[1024, 512],
|
||||||
output_size=opt.repr,
|
output_size=opt.repr,
|
||||||
activation=nn.functional.relu,
|
activation=nn.functional.relu,
|
||||||
dropout=0.5,
|
dropout=0.5,
|
||||||
|
@ -107,10 +107,27 @@ def main(opt):
|
||||||
with open(f'results_feb_{opt.mode}.txt', 'wt') as foo:
|
with open(f'results_feb_{opt.mode}.txt', 'wt') as foo:
|
||||||
Xtr_, Xval_, ytr_, yval_ = train_test_split(Xtr, ytr, test_size=0.1, stratify=ytr)
|
Xtr_, Xval_, ytr_, yval_ = train_test_split(Xtr, ytr, test_size=0.1, stratify=ytr)
|
||||||
|
|
||||||
|
print('training end-to-end without self-supervision init')
|
||||||
|
cls, phi = instantiate_model(A, index, pad_index, device)
|
||||||
|
# train
|
||||||
|
val_microf1 = cls.fit(Xtr_, ytr_, Xval_, yval_,
|
||||||
|
batch_size=opt.batchsize, epochs=opt.epochs, alpha=opt.alpha, lr=opt.lr,
|
||||||
|
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
||||||
|
checkpointpath=opt.checkpoint, patience=opt.patience)
|
||||||
|
# test
|
||||||
|
yte_ = cls.predict(Xte)
|
||||||
|
print('end-to-end (w/o self-supervised initialization) network prediction')
|
||||||
|
acc, macrof1, microf1 = evaluation(yte, yte_)
|
||||||
|
foo.write(f'end-to-end (w/o self-supervised initialization) '
|
||||||
|
f'network prediction: acc={acc:.3f} macrof1={macrof1:.3f} microf1={microf1:.3f}\n')
|
||||||
|
|
||||||
|
|
||||||
|
cls, phi = instantiate_model(A, index, pad_index, device)
|
||||||
|
|
||||||
cls.supervised_contrastive_learning(Xtr_, ytr_, Xval_, yval_,
|
cls.supervised_contrastive_learning(Xtr_, ytr_, Xval_, yval_,
|
||||||
batch_size=opt.batchsize, epochs=opt.epochs, lr=opt.lr,
|
batch_size=opt.batchsize, epochs=opt.epochs, lr=opt.lr,
|
||||||
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
||||||
checkpointpath=opt.checkpoint)
|
checkpointpath=opt.checkpoint, patience=opt.patience)
|
||||||
|
|
||||||
# svm_experiment(cls.project(Xtr), ytr, cls.project(Xte), yte, foo, 'svm-pre')
|
# svm_experiment(cls.project(Xtr), ytr, cls.project(Xte), yte, foo, 'svm-pre')
|
||||||
Xtr_svm, Xte_svm = cls.project_kernel(Xtr), cls.project_kernel(Xte)
|
Xtr_svm, Xte_svm = cls.project_kernel(Xtr), cls.project_kernel(Xte)
|
||||||
|
@ -118,7 +135,7 @@ def main(opt):
|
||||||
val_microf1 = cls.train_linear_classifier(Xtr_, ytr_, Xval_, yval_,
|
val_microf1 = cls.train_linear_classifier(Xtr_, ytr_, Xval_, yval_,
|
||||||
batch_size=opt.batchsize, epochs=opt.epochs, lr=opt.lr,
|
batch_size=opt.batchsize, epochs=opt.epochs, lr=opt.lr,
|
||||||
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
||||||
checkpointpath=opt.checkpoint)
|
checkpointpath=opt.checkpoint, patience=opt.patience)
|
||||||
# test
|
# test
|
||||||
yte_ = cls.predict(Xte)
|
yte_ = cls.predict(Xte)
|
||||||
print('sav(fix)-lin(trained) network prediction')
|
print('sav(fix)-lin(trained) network prediction')
|
||||||
|
@ -129,8 +146,7 @@ def main(opt):
|
||||||
val_microf1 = cls.fit(Xtr_, ytr_, Xval_, yval_,
|
val_microf1 = cls.fit(Xtr_, ytr_, Xval_, yval_,
|
||||||
batch_size=opt.batchsize, epochs=opt.epochs, alpha=opt.alpha, lr=opt.lr,
|
batch_size=opt.batchsize, epochs=opt.epochs, alpha=opt.alpha, lr=opt.lr,
|
||||||
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
||||||
checkpointpath=opt.checkpoint
|
checkpointpath=opt.checkpoint, patience=opt.patience)
|
||||||
)
|
|
||||||
# test
|
# test
|
||||||
yte_ = cls.predict(Xte)
|
yte_ = cls.predict(Xte)
|
||||||
print('end-to-end-finetuning network prediction')
|
print('end-to-end-finetuning network prediction')
|
||||||
|
@ -138,21 +154,6 @@ def main(opt):
|
||||||
foo.write(f'end-to-end-finetuning network prediction: '
|
foo.write(f'end-to-end-finetuning network prediction: '
|
||||||
f'acc={acc:.3f} macrof1={macrof1:.3f} microf1={microf1:.3f}\n')
|
f'acc={acc:.3f} macrof1={macrof1:.3f} microf1={microf1:.3f}\n')
|
||||||
|
|
||||||
print('training end-to-end without self-supervision init')
|
|
||||||
cls, phi = instantiate_model(A, index, pad_index, device)
|
|
||||||
# train
|
|
||||||
val_microf1 = cls.fit(Xtr_, ytr_, Xval_, yval_,
|
|
||||||
batch_size=opt.batchsize, epochs=opt.epochs, alpha=opt.alpha, lr=opt.lr,
|
|
||||||
log=f'{opt.log}/{method}-{dataset_name}.csv',
|
|
||||||
checkpointpath=opt.checkpoint
|
|
||||||
)
|
|
||||||
# test
|
|
||||||
yte_ = cls.predict(Xte)
|
|
||||||
print('end-to-end (w/o self-supervised initialization) network prediction')
|
|
||||||
acc, macrof1, microf1 = evaluation(yte, yte_)
|
|
||||||
foo.write(f'end-to-end (w/o self-supervised initialization) '
|
|
||||||
f'network prediction: acc={acc:.3f} macrof1={macrof1:.3f} microf1={microf1:.3f}\n')
|
|
||||||
|
|
||||||
svm_experiment(Xtr_svm, ytr, Xte_svm, yte, foo, 'svm-kernel')
|
svm_experiment(Xtr_svm, ytr, Xte_svm, yte, foo, 'svm-kernel')
|
||||||
|
|
||||||
# results = Results(opt.output)
|
# results = Results(opt.output)
|
||||||
|
@ -206,7 +207,7 @@ def svm_experiment(Xtr, ytr, Xte, yte, foo, name):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='CNN with KTA regularization')
|
parser = argparse.ArgumentParser(description='CNN with KTA regularization')
|
||||||
parser.add_argument('-H', '--hidden', help='Hidden/embedding size', type=int, default=16)
|
parser.add_argument('-H', '--hidden', help='Hidden/embedding size', type=int, default=32)
|
||||||
parser.add_argument('-c', '--chout', help='Channels output size', type=int, default=128)
|
parser.add_argument('-c', '--chout', help='Channels output size', type=int, default=128)
|
||||||
parser.add_argument('-r', '--repr', help='Projection size (phi)', type=int, default=256)
|
parser.add_argument('-r', '--repr', help='Projection size (phi)', type=int, default=256)
|
||||||
parser.add_argument('-k', '--kernelsizes', help='Size of the convolutional kernels', nargs='+', default=[6,7,8])
|
parser.add_argument('-k', '--kernelsizes', help='Size of the convolutional kernels', nargs='+', default=[6,7,8])
|
||||||
|
|
Loading…
Reference in New Issue