我有这样的代码:
def new_predict(y):
_text_data = pad_sequences(y, 350, padding="post", truncating="post")
return np.array([[float(1-m), float(m)] for m in model.predict(_text_data)])
if __name__ == '__main__':
model = tf.keras.models.load_model(path)
doc = 'sample Text'
x, len_vocab = preprocess_data(path)
test_padded = pad_sequences(x, 350, padding="post", truncating="post")
model.predict(test_padded[-1].reshape(1, -1))
explainer = LimeTextExplainer()
exp = explainer.explain_instance(doc, new_predict(x), 350, top_labels=1)
print(exp)
print(exp.show_in_notebook(text=False))
我有一个错误,例如:
return np.array([[float(1-m), float(m)] for m in model.predict(_text_data)]) TypeError: only size-1 arrays can be convert to Python scalars
我知道问题出在哪里,但我不知道如何解决。问题是,在我的模型中,所有键都是二维数组 [1,0](好)或 [0,1](坏),但解释器需要一个 int。