我收到此错误:
IndexError:索引13超出了尺寸为13的轴0的边界
但是我似乎无法修复它。你能帮我吗?
def sample_labels( y, num_of_sents = 5, num_of_samples = 10,
num_of_classes = 1, start_index = 5, get_prob = True):
#Get a sense of how labels in y look like
classes = classes_()
ret = []
x=list(y)
for sent in x[:num_of_sents]:
cur = []
for word in sent[start_index: start_index + num_of_samples]:
sorted_prob = am(word)
print('sorted_prob',sorted_prob)
print ('sorted_prob len', len(sorted_prob))
print('word',word)
#print('cur',cur)
print('number of classes',num_of_classes)
cur.append([(classes[ind], word[ind]) if get_prob
else classes[ind]
for ind in sorted_prob[:num_of_classes]]) #------ERROR here----------
print('cur and end of inner 4 loop',cur)
print('classesind',classes)
ret.append(cur)
print('cur',cur)
return ret
以下是印刷报表的示例
sorted_prob [12,13,4,2,3,0,6,1,14,14,5,7,8,9,11,10]
sorted_prob len 15
word [3.9363772e-06 6.2428586e-07 1.2910984e-05 4.0524797e-06 4.3209013e-05 2.4976660e-07 1.3571737e-06 1.0090356e-09 1.5341955e-11 4.4677283e-12 1.8482331e-15 1.6146554e-14 9.9985778e-01 7.5455580e-05 4.0608529e-07]
班数1
cur和内部4循环[['P-I']]
的结尾classesind ['A0-B''A0-I''A1-B''A1-I''A2-B''A2-I''A3-B''A3-I' 'A4-B''A4-I''O''P-B''P-I']
sorted_prob [13、12、14、1、3、0、5、4、9、2、6、7、8、11、10]
sorted_prob len 15
word [1.40233034e-10 1.62562830e-09 1.44035496e-14 7.12817139e-10 2.15579486e-12 1.05151512e-11 2.58049413e-15 1.43085274e-15 1.61804985e-16 1.13536066e-13 4.95883708e-23 6.91257209e-19 1.88131162e-06 9.99998093e-01 7.41057393e-09]
班数1
然后将引发错误。