deepmorpheus/tag.py
def attempt_checkpoint_load(checkpoint_path, vocab, device, force_compatibility=False):
    """This function tries to load a pytorch checkpoint, if it fails it aborts the program"""
    if not os.path.isfile(checkpoint_path):
        print("Model checkpoint file does not exist: %s" % checkpoint_path)
        exit()

    print("Loading model from checkpoint: %s" % checkpoint_path)
    checkpoint = torch.load(checkpoint_path, map_location=torch.device(device))
    checkpoint_params = checkpoint.get('hparams')
    hparams = Namespace(**checkpoint_params)

    # Only turn this on if we need to load an older model which had different hparams
    if force_compatibility:
        hparams.disable_bidirectional = False
        hparams.disable_char_level = False
        hparams.dropout = 0.3
        # vocab.tag_names = ["word_type", "person", "number", "tense", "mode", "voice", "gender", "case", "degree_of_comparison"]

    # Creates the model and loads the state dict, then return it
    model = LSTMCharTagger(hparams, vocab)
    model.load_state_dict(checkpoint['state_dict'])
    model.eval()
    return model
This function tries to load a pytorch checkpoint, if it fails it aborts the program
This function tries to load a pytorch checkpoint, if it fails it aborts the program
This function tries to load a pytorch checkpoint if it fails it aborts the program
def attempt_checkpoint_load(checkpoint_path, vocab, device, force_compatibility=False):
    if not os.path.isfile(checkpoint_path):
        print("Model checkpoint file does not exist: %s" % checkpoint_path)
        exit()
    print("Loading model from checkpoint: %s" % checkpoint_path)
    checkpoint = torch.load(checkpoint_path, map_location=torch.device(device))
    checkpoint_params = checkpoint.get('hparams')
    hparams = Namespace(**checkpoint_params)
    if force_compatibility:
        hparams.disable_bidirectional = False
        hparams.disable_char_level = False
        hparams.dropout = 0.3
    model = LSTMCharTagger(hparams, vocab)
    model.load_state_dict(checkpoint['state_dict'])
    model.eval()
    return model
def attempt_checkpoint_load ( checkpoint_path , vocab , device , force_compatibility = False ) : if not os . path . isfile ( checkpoint_path ) : print ( "Model checkpoint file does not exist: %s" % checkpoint_path ) exit ( ) print ( "Loading model from checkpoint: %s" % checkpoint_path ) checkpoint = torch . load ( checkpoint_path , map_location = torch . device ( device ) ) checkpoint_params = checkpoint . get ( 'hparams' ) hparams = Namespace ( ** checkpoint_params ) if force_compatibility : hparams . disable_bidirectional = False hparams . disable_char_level = False hparams . dropout = 0.3 model = LSTMCharTagger ( hparams , vocab ) model . load_state_dict ( checkpoint [ 'state_dict' ] ) model . eval ( ) return model
This function tries to load a pytorch checkpoint, if it fails it aborts the program
This function tries to load a pytorch checkpoint if it fails it aborts the program
"""This function tries to load a pytorch checkpoint, if it fails it aborts the program""" # Only turn this on if we need to load an older model which had different hparams # vocab.tag_names = ["word_type", "person", "number", "tense", "mode", "voice", "gender", "case", "degree_of_comparison"] # Creates the model and loads the state dict, then return it
checkpoint_path
vocab
device
force_compatibility