def get_model(args, filename, allow_mask=True): loader = HMMLoader(args.mathType) # TODO: rename HMMLoader to ModelLoader register_classifier_states(loader) register_annotation_states(loader) register_cannotation_states(loader) register_annotations(loader) for i in range(0, len(args.bind_file), 2): loader.addFile(args.bind_file[i], args.bind_file[i + 1]) for i in range(0, len(args.bind_constant_file), 2): loader.addConstant( args.bind_constant_file[i], loader.load(args.bind_constant_file[i + 1]) ) for i in range(0, len(args.bind_constant_file), 2): loader.addConstant( args.bind_constant_file[i], loader.loads(args.bind_constant_file[i + 1]), ) model = loader.load(filename) if type(model) is dict and 'model' in model: model = model["model"] if args.add_masked_to_distribution and allow_mask: model.add_soft_masking_to_distribution() return model
def load_model(self, fname): loader = HMMLoader(float) register_classifier_states(loader) register_annotation_states(loader) register_cannotation_states(loader) self.fname = fname self.model = loader.load(fname) self.states_dict = dict() for i, state in enumerate(self.model['model'].states): self.states_dict[state.onechar] = i
def get_model(args, filename, allow_mask=True): loader = HMMLoader(args.mathType) # TODO: rename HMMLoader to ModelLoader register_classifier_states(loader) register_annotation_states(loader) register_cannotation_states(loader) register_annotations(loader) for i in range(0, len(args.bind_file), 2): loader.addFile(args.bind_file[i], args.bind_file[i + 1]) for i in range(0, len(args.bind_constant_file), 2): loader.addConstant(args.bind_constant_file[i], loader.load(args.bind_constant_file[i + 1])) for i in range(0, len(args.bind_constant_file), 2): loader.addConstant( args.bind_constant_file[i], loader.loads(args.bind_constant_file[i + 1]), ) model = loader.load(filename) if type(model) is dict and 'model' in model: model = model["model"] if args.add_masked_to_distribution and allow_mask: model.add_soft_masking_to_distribution() return model