raise exception when arguments to pipeline are incomplete (#12548)

* raise exception when arguments are incomplete

* change exception to runtime error
This commit is contained in:
Hwijeen Ahn 2021-07-08 17:17:34 +09:00 committed by GitHub
parent 122d7dc34f
commit b29c394586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -387,6 +387,18 @@ def pipeline(
>>> tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
>>> pipeline('ner', model=model, tokenizer=tokenizer)
"""
if model is None and tokenizer is not None:
raise RuntimeError(
"Impossible to instantiate a pipeline with tokenizer specified but not the model "
"as the provided tokenizer may not be compatible with the default model. "
"Please provide a PreTrainedModel class or a path/identifier to a pretrained model when providing tokenizer."
)
if model is None and feature_extractor is not None:
raise RuntimeError(
"Impossible to instantiate a pipeline with feature_extractor specified but not the model "
"as the provided feature_extractor may not be compatible with the default model. "
"Please provide a PreTrainedModel class or a path/identifier to a pretrained model when providing feature_extractor."
)
# Retrieve the task
targeted_task, task_options = check_task(task)