only load if model file doesn't exist
@@ -18,10 +18,7 @@ def add_cmdline_args(parser):
# Basics
agent.add_argument('--embedding_file', type=str, default=None,
- help='[deprecated: use embedding_type] '
- 'file of space separated embeddings: w e1 ... ed')
- agent.add_argument('--embedding_type', type=str, default='random',
- choices=['fasttext', 'fasttext_cc', 'random', 'glove'],
+ help='file of space separated embeddings: w e1 ... ed')
help='embeddings from model zoo')
agent.add_argument('--init_model', type=str, default=None,
help='Load dict/features/weights/opts from this file')
@@ -89,26 +86,19 @@ def add_cmdline_args(parser):
def set_defaults(opt):
+ init_model = None
+ # check first for 'init_model' for loading model from file
+ if opt.get('init_model') and os.path.isfile(opt['init_model']):
+ init_model = opt['init_model']
+ # next check for 'model_file', this would override init_model
+ if opt.get('model_file') and os.path.isfile(opt['model_file']):
+ init_model = opt['model_file']
+
+ if init_model is None:
# Embeddings options
- if (opt.get('embedding_file') is not None and
- opt.get('embedding_type') == 'random'):
- # backwards compatibility for older models
- vec_zoo = ['fasttext_cc_vectors', 'fasttext_vectors', 'glove_vectors']
- for vec in vec_zoo:
- if vec in opt.get('embedding_file'):
- opt['embedding_type'] = vec
- break
- if opt.get('embedding_type') != 'random':
- old = opt.get('embedding_file')
opt['embedding_file'] = modelzoo_path(
- opt.get('datapath'), 'models:' + opt['embedding_type'])
- if old is not None:
- print("[ warning: overriding opt['embedding_file'] to {} "
- "(previously: {})]".format(opt['embedding_file'],
- old))
- elif opt.get('embedding_file'):
- # backwards compatibility for specifying embedding file from place
- # other than model zoo
+ opt.get('datapath'), opt['embedding_file'])
+ if opt.get('embedding_file'):
if not os.path.isfile(opt['embedding_file']):
raise IOError('No such file: %s' % opt['embedding_file'])
with open(opt['embedding_file']) as f:
@@ -127,12 +117,10 @@ def set_defaults(opt):
opt['fix_embeddings'] = False
# Make sure fix_embeddings and embedding_file are consistent
- if opt['fix_embeddings']:
- if not opt.get('embedding_file') and not opt.get('init_model'):
+ if opt['fix_embeddings'] and not opt.get('embedding_file'):
print('Setting fix_embeddings to False as embeddings are random.')
opt['fix_embeddings'] = False
-
def override_args(opt, override_opt):
# Major model args are reset to the values in override_opt.
# Non-architecture args (like dropout) are kept.
