我想从这个输出中得到三个目标(类的名称)



我对我的模型进行了训练,然后我预测了一个句子的结果,我从它得到了下面的结果,所以我想从这个结果得到三个类。代码:

model = None
with self.strategy.scope():
# NUMBER OF CLASSES
model = self.build_model(18)
model.summary()
model.load_weights("./saved_weights.h5")
tokenizer = RobertaTokenizer.from_pretrained(self.MODEL_NAME)
sentence = "entrepreneurs do you know these 4 golden rules for choosing your partner"
feat_sent = self.roberta_encode(sentence, tokenizer)
print(model.predict(feat_sent))

输出:

[[5.9324593e-05 1.3429151e-06 1.8986340e-03 ... 1.3939711e-05
7.6713404e-03 3.3101414e-06]
[6.2252270e-06 5.5910685e-05 5.3245033e-04 ... 7.4192496e-05
6.0618650e-02 1.8048033e-06]
[1.5471487e-06 6.4954706e-06 8.8266870e-03 ... 1.1088764e-03
3.0796309e-03 1.4289287e-04]
...
[6.2252229e-06 5.5910707e-05 5.3244922e-04 ... 7.4192525e-05
6.0618687e-02 1.8048074e-06]
[5.9324593e-05 1.3429151e-06 1.8986340e-03 ... 1.3939683e-05
7.6713329e-03 3.3101351e-06]
[1.4472993e-05 1.6191008e-06 1.4653641e-03 ... 3.5171520e-06
2.7216172e-03 1.5248560e-08]]

你可以这么简单但是类名是你自己决定的

results = model.predict(inputs)
# Get max results
preds = results.argmax(axis=1)
label_map = {0: "class_a", 1: "class_b", 2: "class_c"}
# Map array of results via for loop
labels = [label_map[pred] for pred in preds]

相关内容

  • 没有找到相关文章

最新更新