0

I am using keras bi-lstm to predict 14 classes. Here is my label index:

label_index=`{'1':0,'2':1,'D':2,'7':3,'8':4,'9':5,'10':6,'11':7,'12':8,'13':9,'14':10,'15':11,'16':12,'17':13}`

Here is part of my model setting:

model.add(Bidirectional(LSTM(64)))
model.add(Dropout(0.5))
model.add(Dense(14, activation='softmax'))

model.compile('adam', 'sparse_categorical_crossentropy', metrics=['accuracy'])

The "14" in the Dense function is the number of classes. When I looked at the label distribution of pred = model.predict(x_test, verbose=0), I found this:

Counter({'1': 54,
         '10': 88,
         '11': 5,
         '12': 2,
         '13': 6,
         '14': 5,
         '3': 65,
         '4': 5,
         '5': 3,
         '6': 28,
         '7': 10,
         '8': 3,
         '9': 3})

Where did this "14" come from???? It's not in my index. And there was no "0"! I guess in the multi-class situation, kera.predict cannot output zero. Should I deduct 1 for every element in my "pred"?

Milo Lu
  • 3,176
  • 3
  • 35
  • 46
Robin
  • 1
  • 2
  • "D" is a pretty frequent class in the training, but it didn't appear in pred. Is pred producing labels or their indices? – Robin Oct 08 '18 at 04:42
  • I think your label index map is swapped. The keys are values and vice cersa – Anand C U Oct 08 '18 at 04:44
  • My following code is like this: labels=[[label_index[item[0]]] for item in f] and then labels = to_categorical(np.asarray(labels)) . I swapped the map and it reported a key error on 'D'. – Robin Oct 08 '18 at 04:54

0 Answers0