Skip to content

Commit

Permalink
Raise error for mismatched transformer component + listener (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianeboyd authored Dec 4, 2023
1 parent 12f17d3 commit 511ebe1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions spacy_transformers/layers/trfs2arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def forward(model: Model, trf_datas: List[TransformerData], is_train: bool):
output_width = 0

for i, trf_data in enumerate(trf_datas):
if not isinstance(trf_data, TransformerData):
raise ValueError(
"Expected spacy_transformers.data_classes.TransformerData "
f"in trf_data, got: {type(trf_data)}\n"
"Check that your pipeline contains a transformer component "
"with a spacy-transformers TransformerModel architecture."
)
if "last_hidden_state" in trf_data.model_output:
tensor_t_i = cast(BaseModelOutput, trf_data.model_output).last_hidden_state
if tensor_t_i.size == 0:
Expand Down

0 comments on commit 511ebe1

Please sign in to comment.