def load_map(self, path):
"""Load a index map file. Mappings should be bijections, but
there is no sanity check in place to verify this.
Args:
path (string): Path to the mapping file
Returns:
dict. Mapping from SGNMT index to slave predictor index
"""
with open(path) as f:
d = dict(map(int, line.strip().split(None, 1)) for line in f)
if (d[utils.UNK_ID] != utils.UNK_ID
or d[utils.EOS_ID] != utils.EOS_ID
or d[utils.GO_ID] != utils.GO_ID):
logging.fatal(
"idxmap %s contains non-identical maps for reserved indices"
% path)
logging.debug("Loaded wmap from %s" % path)
return [d[idx] if idx in d else 0 for idx in range(max(d)+1)]
评论列表
文章目录