Store task-specific params on model object
@@ -118,7 +118,8 @@ def build_model(args, vocab, pretrained_embs, tasks):
# Build model and classifiers
model = MultiTaskModel(args, sent_encoder, vocab)
- build_modules(tasks, model, d_sent, vocab, embedder, args)
+ for task in tasks:
+ build_module(task, model, d_sent, vocab, embedder, args)
if args.cuda >= 0:
model = model.cuda()
log.info(model)
@@ -212,10 +213,12 @@ def build_embeddings(args, vocab, pretrained_embs=None):
return d_emb, embedder, cove_emb
-def build_modules(tasks, model, d_sent, vocab, embedder, args):
- ''' Build task-specific components for each task and add them to model '''
- for task in tasks:
+def build_module(task, model, d_sent, vocab, embedder, args):
+ ''' Build task-specific components for a task and add them to model. '''
task_params = get_task_specific_params(args, task.name)
+ # Store task-specific params in case we want to access later
+ setattr(model, '%s_task_params' % task.name, task_params)
+
if isinstance(task, SingleClassificationTask):
module = build_single_sentence_module(task, d_sent, task_params)
setattr(model, '%s_mdl' % task.name, module)
@@ -266,7 +269,6 @@ def build_modules(tasks, model, d_sent, vocab, embedder, args):
#print("NEED TO ADD DNN to RESPONSE INPUT -- TO DO: IMPLEMENT QUICKLY")
else:
raise ValueError("Module not found for %s" % task.name)
- return
def get_task_specific_params(args, task):
