GLiNER icon indicating copy to clipboard operation
GLiNER copied to clipboard

Load local model example gives config error

Open sglbl opened this issue 6 months ago • 0 comments

In the previous version I was using this example to load local model. But I needed to update GLiNER, because I needed to update flair, because previous flair version was using very old urllib version that created pip conflicts with every other package.

But with the new gliner==0.2.8 version, example notebook doesn't work anymore:

My code:

def load_model(path, model_name=None):
    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    dict_load = torch.load(path, map_location=device)
    config = dict_load["config"]

    print(f"Using '{config.model_name}' for local processing (device: {device})")

    if model_name is not None:
        config.model_name = model_name

    loaded_model = GLiNER(config)
    loaded_model = loaded_model.to(device)
    loaded_model.load_state_dict(dict_load["model_weights"])
    return loaded_model

def create_nlp_model(local_mode=True):
    global ner_pipeline, loaded_model
    # Load the named entity recognition model
    if local_mode:
        loaded_model = load_model("./models/gliner_model_weight.pt", "./models/mdeberta-v3-base")

It gave

AttributeError: 'Namespace' object has no attribute 'words_splitter_type'

When I added words_splitter_type as 'spacy' or 'whitespace', this time another attr gives error.

sglbl avatar Aug 06 '24 15:08 sglbl