ValueError: could not broadcast input array from shape

Home / Uncategorized / ValueError: could not broadcast input array from shape

Question:
I am using seq2seq model for Hindi to English text translation. I am not much familiar with keras or deep learning. While exploring seq2seq model I came across this example.

https://github.com/karimkhanp/Seq2Seq/blob/master/seq2seq/seq2seq.py

While running this program I get error
ValueError: could not broadcast input array from shape (6) into shape (1,10)

at line
temp[0:len(seq)] = seq

Error log –
[[4000, 4000, 4000, 4000, 4000, 4000]]

Traceback (most recent call last):File "seq2seq.py", line 92, in
Seq2seq.encode()
File "seq2seq.py", line 58, in encode
temp[0:len(seq)] = seq
ValueError: could not broadcast input array from shape (6) into shape (1,10)

Code:def encode(self):#Encodes input sentence into fixed length vector
#print("Enter sentence in hindi")
inp = raw_input().decode("utf-8")
tokens = inp.split()
seq = []
for token in tokens:if token in self.proproces.vocab_tar:seq.append(self.proproces.vocab_tar[token])
else:token = "UNK"
seq.append(self.proproces.vocab_tar[token])
#seq = map(lambda x:self.proproces.vocab_hind[x], tokens)
# Normalize seq to maxlen
X = []
X.append(seq)
print(X)
temp = pad_sequences(X, maxlen=self.maxlen)
temp[0:len(seq)] = seq
print(len(temp))
temp = np.asarray(temp).reshape(128,)
print(temp.shape)
prob = model.predict_on_batch(temp)#, batch_size=1, verbose=0)
translated = self.decode(prob)
print("Tranlated is", translated)

Where is the dimention mismatch.

Original code had temp = sequence.pad_sequences(X, maxlen=self.maxlen) which I converted to temp = pad_sequences(X, maxlen=self.maxlen)


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *