Python 索引器:索引22超出大小为22的轴1的界限?
在使用英语到印地语的过程中,我遇到了一个错误索引器:索引22超出了大小为22.LSTM网络的axis 1的范围Python 索引器:索引22超出大小为22的轴1的界限?,python,keras,encoding,nlp,decoding,Python,Keras,Encoding,Nlp,Decoding,在使用英语到印地语的过程中,我遇到了一个错误索引器:索引22超出了大小为22.LSTM网络的axis 1的范围 def generate_batch(X = X_train, y = y_train, batch_size = 128): ''' Generate a batch of data ''' while True: for j in range(1, len(X), batch_size): encoder_input_data
def generate_batch(X = X_train, y = y_train, batch_size = 128):
''' Generate a batch of data '''
while True:
for j in range(1, len(X), batch_size):
encoder_input_data = np.zeros((batch_size, max_length_src),dtype='float32')
decoder_input_data = np.zeros((batch_size, max_length_tar),dtype='float32')
decoder_target_data = np.zeros((batch_size, max_length_tar, num_decoder_tokens),dtype='float32')
for i, (input_text, target_text) in enumerate(zip(X[j:j+batch_size], y[j:j+batch_size])):
for t, word in enumerate(input_text.split()):
encoder_input_data[i, t] = input_token_index[word] # encoder input seq
for t, word in enumerate(target_text.split()):
if t<len(target_text.split())-1:
decoder_input_data[i, t] = target_token_index[word] # decoder input seq #erro point
if t>0:
# decoder target sequence (one hot encoded)
# does not include the START_ token
# Offset by one timestep
decoder_target_data[i, t - 1, target_token_index[word]] = 1.
yield([encoder_input_data, decoder_input_data], decoder_target_data)
如果我错了,请原谅,但这看起来像是一个经典的错误 如果列表大小为22,则最后一个可索引位置为21。这是因为列表的索引从0开始
根据给定的代码,很难准确地说出这个问题是从代码中的什么地方产生的。最后一个可寻址索引是21。