Loading saved model not working
Do we know do to load the saved model pipeline back up and make predictions again locally? The from_pretrained()is not working.
Pls provide few instructions how to load the model using from pretrained
What do you mean it's not working? Could you provide all the information required in the template? What is your environment? What code are you running? What is the error shown? How do you use `from_pretrained`?<|||||>What is meant is how do we utilize the “from_pretrained” functionality after saving the pipeline? I want to load the pipeline back up to start making predictions locally the saved file(s) below:


import transformers

ner_original = pipeline("ner")
ner = pipeline("ner",grouped_entities=True)

path = 'path to folder'

ner.save_pretrained(path)

I am currently running transformers==2.11.0 and python 3.7.4. I have tried:

pipe = transformers.pipeline(task="ner", model="pytorch_model.bin",
tokenizer="tokenizer_config.json")

This gave an error: ValueError: Unrecognized model in tokenizer_config.json. Should have a `model_type` key in its config.json

pipe = transformers.TokenClassificationPipeline(model="pytorch_model.bin",
tokenizer="tokenizer_config.json")

This gave an error: AttributeError: 'str' object has no attribute 'config'

Changing the tokenizer to "config.json" yielded the following error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte
<|||||>This is the code which gives the error

from transformers import AutoModel, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(path)
model = AutoModel.from_pretrained(path)

label_list = [
    "O",       # Outside of a named entity
    "B-MISC",  # Beginning of a miscellaneous entity right after another miscellaneous entity
    "I-MISC",  # Miscellaneous entity
    "B-PER",   # Beginning of a person's name right after another person's name
    "I-PER",   # Person's name
    "B-ORG",   # Beginning of an organisation right after another organisation
    "I-ORG",   # Organisation
    "B-LOC",   # Beginning of a location right after another location
    "I-LOC"    # Location
]

sequence = "Hugging Face Inc. is a company based in New York City. Its headquarters are in DUMBO, therefore very" \
           "close to the Manhattan Bridge."

# Bit of a hack to get the tokens with the special tokens
tokens = tokenizer.tokenize(tokenizer.decode(tokenizer.encode(sequence)))
inputs = tokenizer.encode(sequence, return_tensors="pt")

outputs = model(inputs)[0]
predictions = torch.argmax(outputs, dim=2)

print([(token, label_list[prediction]) for token, prediction in zip(tokens, predictions[0].tolist())])
<|||||>This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
