mirror of
https://github.com/wassname/Castor.git
synced 2026-09-10 11:40:44 +08:00
Add seed and thread arguments (#43)
So that any experiments can be controlled from the command line, I've set the defaults to what they were hardcoded (for the seed) and num_threads in kim_cnn to be consistent with the default in sm_cnn.
This commit is contained in:
+9
-5
@@ -11,10 +11,6 @@ import os
|
||||
if __name__=='__main__':
|
||||
|
||||
import argparse
|
||||
torch.manual_seed(3435)
|
||||
np.random.seed(3435)
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.manual_seed(3435)
|
||||
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
@@ -22,12 +18,20 @@ if __name__=='__main__':
|
||||
argparser.add_argument('--validate', action='store_true')
|
||||
argparser.add_argument('--test', action='store_true')
|
||||
argparser.add_argument('--load', action='store_true')
|
||||
argparser.add_argument('--seed', help='Random seed', type=int, default=3435)
|
||||
argparser.add_argument('--num_threads', help='The number of threads to use', type=int, default=4)
|
||||
|
||||
args, extra_args = argparser.parse_known_args()
|
||||
# args.train = True/False ...
|
||||
# extra_args['--some': "xxxx"]
|
||||
cargs = {k: v for (k, v) in vars(Configurable.argparser.parse_args(extra_args)).items() if v is not None}
|
||||
|
||||
torch.manual_seed(args.seed)
|
||||
np.random.seed(args.seed)
|
||||
if torch.cuda.is_available():
|
||||
torch.cuda.manual_seed(args.seed)
|
||||
torch.set_num_threads(args.num_threads)
|
||||
|
||||
if 'model_type' not in cargs:
|
||||
print("You need to specify the model_type")
|
||||
exit()
|
||||
@@ -78,4 +82,4 @@ if __name__=='__main__':
|
||||
print(network.test(validate=True))
|
||||
elif args.test:
|
||||
print("### The accuracy for test set: ")
|
||||
print(network.test(validate=False))
|
||||
print(network.test(validate=False))
|
||||
|
||||
+3
-2
@@ -118,11 +118,12 @@ if __name__ == "__main__":
|
||||
ap.add_argument("--dash-split", help="split words containing hyphens", action="store_true")
|
||||
ap.add_argument("--index-for-corpusIDF", help="fetches idf from Index. provide index path. will\
|
||||
generate a vocabFile")
|
||||
ap.add_argument('--seed', help='Random seed', type=int, default=1234)
|
||||
|
||||
args = ap.parse_args()
|
||||
|
||||
torch.manual_seed(1234)
|
||||
np.random.seed(1234)
|
||||
torch.manual_seed(args.seed)
|
||||
np.random.seed(args.seed)
|
||||
torch.set_num_threads(args.num_threads)
|
||||
|
||||
train_set, dev_set, test_set = 'train-all', 'raw-dev', 'raw-test'
|
||||
|
||||
Reference in New Issue
Block a user