'How to load transformers pipeline from folder?
According to here pipeline provides an interface to save a pretrained pipeline locally with a save_pretrained method. When I use it, I see a folder created with a bunch of json and bin files presumably for the tokenizer and the model.
But the documentation does not specify a load method. How does one initialize a pipeline using a locally saved pipeline?
Solution 1:[1]
If you read the specification for save_pretrained, it simply states that it
Save[s] the pipeline’s model and tokenizer.
I've also given a slightly related answer here on how custom models and tokenizers can be loaded. Essentially, you can simply specify the specific models/paths in the pipeline:
from transformers import pipeline, AutoModel, AutoTokenizer
# Replace with your custom model of choice
model = AutoTokenizer.from_pretrained('/path/to/your/model')
tokenizer = AutoTokenizer.from_pretrained('/path/to/your/tokenizer')
pipe = pipeline(task='summarization', # replace with whatever task you have
model=model,
tokenizer=tokenizer)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dennlinger |
