IndexError:索引5407超出了尺寸为8的轴1的范围

时间:2019-06-11 05:29:42

标签: tensorflow keras python-3.6 indexoutofboundsexception

我是python和神经网络的新手

这是我的代码的一部分:

y = [[tag2idx[w[1]] for w in s] for s in sentences]

y = pad_sequences(maxlen=max_len, sequences=y, padding="post", value=tag2idx["O"])


y = [to_categorical(i, num_classes=n_tags) for i in y]

这是错误:

Using TensorFlow backend.
Traceback (most recent call last):
  File "C:/Users/lam/.PyCharm2019.1/config/scratches/scratch.py", line 79, in <module>
    y = [to_categorical(i, num_classes=n_tags) for i in y]
  File "C:/Users/lam/.PyCharm2019.1/config/scratches/scratch.py", line 79, in <listcomp>
    y = [to_categorical(i, num_classes=n_tags) for i in y]
  File "C:\Users\lam\PycharmProjects\untitled\venv\lib\site-packages\keras\utils\np_utils.py", line 34, in to_categorical
    categorical[np.arange(n), y] = 1
IndexError: index 5407 is out of bounds for axis 1 with size 8

0 个答案:

没有答案