Skip to main content

521 posts tagged with "Fixes"

Fixes for Common Issues and Errors

View All Tags

Fixed: IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) in cosine_similarity

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

I compared two flat vectors with PyTorch's cosine_similarity, and it stopped with IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1). The function compares along dimension 1 unless told otherwise, and a flat vector has only dimension 0. Passing dim=0 fixed it.

Fixed: NotImplementedError: mean(): could not infer output dtype. Input dtype must be either a floating point or complex dtype. Got: Long

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

I asked PyTorch for the average of a tensor of whole numbers with mean(), and it stopped with NotImplementedError: mean(): could not infer output dtype. Input dtype must be either a floating point or complex dtype. Got: Long. mean() only averages decimal (or complex) numbers. Converting the tensor with .float(), or passing dtype=torch.float32, fixed it.

Fixed: "PipelineException: No mask_token ([MASK]) found on the input"

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A Hugging Face fill-mask pipeline stopped with PipelineException: No mask_token ([MASK]) found on the input. The text marked the missing word with <mask>, but this model's mask token is [MASK], so the pipeline found nothing to fill. Writing the text with the tokenizer's own mask_token makes it work with any fill-mask model.

Fixed: "TypeError: list indices must be integers or slices, not str" with a Hugging Face Pipeline's top_k

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A loop over a Hugging Face text-classification pipeline's results failed with TypeError: list indices must be integers or slices, not str. The pipeline was created with top_k=None, and given one text, it returned a list inside a list, so the loop got a list where it expected a result. Passing top_k=None when calling the pipeline, instead of when creating it, returns the flat list the loop expects.

Fixed: return_all_scores=True Returns Only One Label in Transformers 5

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A model card's example passes return_all_scores=True to a Hugging Face text-classification pipeline and shows a score for every label. In Transformers 5 the same code printed only the top label, with no error and no warning, because the argument no longer exists. top_k=None is its replacement, and it returned all six labels.

Fixed: Hugging Face NER Pipeline Splits a Name into Pieces Like "##ka"

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A Hugging Face named entity recognition (NER) pipeline returned the name "Anoushka" as three separate people: An, ##oush and ##ka. The model had split the name into word pieces and tagged two of the later pieces as the start of a new name, and aggregation_strategy="simple" followed those tags. aggregation_strategy="first" gives each word one tag, so the name came back whole.

Fixed: "NOTE: Redirects are currently not supported in MacOs."

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

On a Mac, every script that used Hugging Face Transformers 5.24.1 started with NOTE: Redirects are currently not supported in MacOs., from a PyTorch file named redirects.py. The note is harmless: Transformers loaded a part of PyTorch it didn't need, and that part prints it on macOS. Transformers 5.25.0 and later no longer load it, so upgrading Transformers removes the note.

Fixed: "BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER"

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A named entity recognition (NER) pipeline with dslim/bert-base-NER printed BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER, with two weights marked UNEXPECTED, before finding the right names. The two weights belong to a part the model doesn't have on purpose, so the report is harmless. logging.set_verbosity_error() hides it once you know that.

Fixed: "Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend"

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A fill-mask pipeline with ModernBERT worked, but printed Ignoring clean_up_tokenization_spaces=True for BPE tokenizer TokenizersBackend first. The model's tokenizer settings ask for a text cleanup that Transformers 5 deliberately skips for this kind of tokenizer, and the warning says so. Loading the tokenizer yourself with clean_up_tokenization_spaces=False gives the same results without the warning.

Fixed: "RuntimeError: The size of tensor a (802) must match the size of tensor b (512) at non-singleton dimension 1"

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A Hugging Face sentiment-analysis pipeline crashed on a long review with RuntimeError: The size of tensor a (802) must match the size of tensor b (512) at non-singleton dimension 1. The text was 802 tokens long, and the model reads at most 512. Passing truncation=True when calling the pipeline cuts the text to the model's limit, and the pipeline classifies it.