# Error: operands could not be broadcast together

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-operands-could-not-be-broadcast-together%2F51696%3E%5C
**Category:** Beginners\
**Created:** [August 22, 2023, 3:15pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-operands-could-not-be-broadcast-together%2F51696 "2023-08-22T15:15:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luan77777](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@Luan77777](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FLuan77777)%5C
**Post date:** [August 22, 2023, 3:15pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-operands-could-not-be-broadcast-together%2F51696%2F1 "2023-08-22T15:15:37Z")

</div>

Hi! I’m currently trying to train a SpeechT5 model on an ASR task. I have everything set up but it still get an error when i try to map my data: ValueError: operands could not be broadcast together with remapped shapes [original-\>remapped]: (2,2) and requested shape (1,2). Im using the SpeechT5 Processor to prepare and pad my data for the model but i dont know why this error still occurs, i tried many thnigs to fix it… This is my code, any help would be really appreceated!

feature\_extractor = SpeechT5FeatureExtractor(sampling\_rate=16000,  
num\_mel\_bins=128,  
feature\_size=128,  
win\_length=32,  
padding\_value=3,  
return\_attention\_mask=True,  
do\_normalize=False,  
hop\_length=16,  
win\_function=“hann\_window”,  
fmin=50,  
fmax=7600,  
mel\_floor=1e-10,  
)

processor = SpeechT5Processor(feature\_extractor=feature\_extractor, tokenizer=tokenizer)

valid\_dataset = valid\_dataset.map(lambda example: {‘array’: [example[‘audio’][‘array’]], \*\*example})  
print(valid\_dataset)

train\_dataset = train\_dataset.map(lambda example: {‘array’: [example[‘audio’][‘array’]], \*\*example})  
print(train\_dataset)

def preprocess\_function(examples):  
audio\_arrays = examples[‘array’]

```
text_list = examples['transcription']

input_data = processor(
    audio=audio_arrays,
    text_target=text_list,
    sampling_rate=16000,
    # return_tensors='pt'
)
return input_data

```

valid\_dataset = valid\_dataset.map(preprocess\_function, batched=False)  
valid\_dataset = valid\_dataset.remove\_columns([‘audio’, ‘transcription’, ‘array’, ‘attention\_mask’, ‘decoder\_attention\_mask’])

train\_dataset = train\_dataset.map(preprocess\_function, batched=False)  
train\_dataset = train\_dataset.remove\_columns([‘audio’, ‘transcription’, ‘array’, ‘attention\_mask’, ‘decoder\_attention\_mask’])

print(train\_dataset)

config = SpeechT5Config(  
return\_dict=False,  
sampling\_rate=16000,  
vocab\_size=tokenizer.vocab\_size,  
use\_cache=True,  
activation\_function=‘relu’,  
max\_target\_positions=2048,  
max\_source\_positions=160000,  
input\_feat\_per\_channel=80,  
pad\_token\_id=3,  
eos\_token\_id=2,  
bos\_token\_id=1,

)

@dataclass  
class DataCollatorForSeq2Seq:  
processor: processor

```
padding: Union[bool, str] = "longest"

def __call__ (self, features: List[Dict[str, Union[List[int], torch.Tensor]]]) -> Dict[str, torch.Tensor]:

    # split inputs and labels since they have to be of different lengths and need

    # different padding methods

    input_features = [{"input_values": feature["input_values"][0]} for feature in features]

    label_features = [{"input_ids": feature["labels"]} for feature in features]

    batch = self.processor.pad(input_values=input_features, padding=True, return_tensors="pt", return_attention_mask=True)

    labels_batch = self.processor.pad(labels=label_features, padding=True, return_tensors="pt", return_attention_mask=True)

    # replace padding with -100 to ignore loss correctly

    labels = labels_batch["input_ids"].masked_fill(labels_batch.attention_mask.ne(1), -100)

    batch["labels"] = labels

    return batch

```

data\_collator = DataCollatorForSeq2Seq(processor=processor, padding=‘longest’)

The error occurs in the feature\_extractor.pad() function
