Example #1
0
# Combine layer, task and layer, attention maps
# layer_task_config = {}
# layer_attention_config = {}
# for task_or_attn_name, layer in layer_config.items():
#   if task_or_attn_name in attention_config:
#     layer_attention_config[layer] = attention_config[task_or_attn_name]
#   elif task_or_attn_name in task_config:
#     if layer not in layer_task_config:
#       layer_task_config[layer] = {}
#     layer_task_config[layer][task_or_attn_name] = task_config[task_or_attn_name]
#   else:
#     util.fatal_error('No task or attention config "%s"' % task_or_attn_name)
layer_task_config, layer_attention_config = util.combine_attn_maps(
    layer_config, attention_config, task_config)

hparams = train_utils.load_hparams(args, model_config)

dev_filenames = args.dev_files.split(',')
test_filenames = args.test_files.split(',') if args.test_files else []

vocab = Vocab(data_config, args.save_dir)
vocab.update(test_filenames)

embedding_files = [
    embeddings_map['pretrained_embeddings']
    for embeddings_map in model_config['embeddings'].values()
    if 'pretrained_embeddings' in embeddings_map
]

# Generate mappings from feature/label names to indices in the model_fn inputs
# feature_idx_map = {}
Example #2
0
model_config = train_utils.load_json_configs(args.model_configs)
task_config = train_utils.load_json_configs(args.task_configs, args)
# print("debug <task_config>: ", task_config)
layer_config = train_utils.load_json_configs(args.layer_configs)
attention_config = train_utils.load_json_configs(args.attention_configs)

# attention_config = {}
# if args.attention_configs and args.attention_configs != '':
#   attention_config = train_utils.load_json_configs(args.attention_configs)

# Combine layer, task and layer, attention maps
# todo save these maps in save_dir
layer_task_config, layer_attention_config = util.combine_attn_maps(layer_config, attention_config, task_config)

hparams = train_utils.load_hparams(args, model_config, neptune_handler)
## NEED TO REMOVE
if args.attn_debug:
  hparams.attn_debug = True

# Set the random seed. This defaults to int(time.time()) if not otherwise set.
np.random.seed(hparams.random_seed)
tf.set_random_seed(hparams.random_seed)

if not os.path.exists(args.save_dir):
  os.makedirs(args.save_dir)

train_filenames = args.train_files.split(',')
dev_filenames = args.dev_files.split(',')

vocab = Vocab(data_config, args.save_dir, train_filenames)