From 6b29645cd895b958bb402d2a833ed0d9eca36e7a Mon Sep 17 00:00:00 2001 From: Haoran Li Date: Mon, 8 Jul 2019 17:13:07 -0700 Subject: [PATCH] adapt prediction workflow to new design (#746) Summary: Pull Request resolved: https://github.com/facebookresearch/pytext/pull/746 the prediction workflow only supports the old design, migrate it to support the new design. since I found some recurring jobs set using the old design, I didn't completely remove the old design support, but making it rather separate so it's easy to get rid of the old design in the future. Reviewed By: jingfeidu Differential Revision: D16096788 fbshipit-source-id: 7e51a2eebb86cda6452ecd0bd2405eceac989f4d --- pytext/task/tasks.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pytext/task/tasks.py b/pytext/task/tasks.py index 307be3249..f86f5da5a 100644 --- a/pytext/task/tasks.py +++ b/pytext/task/tasks.py @@ -199,6 +199,15 @@ class Config(NewTask.Config): # for multi-label classification task, # choose MultiLabelClassificationMetricReporter + @classmethod + def format_prediction(cls, predictions, scores, context, target_names): + for prediction, score in zip(predictions, scores): + score_with_name = {n: s for n, s in zip(target_names, score.tolist())} + yield { + "prediction": target_names[prediction.data], + "score": score_with_name, + } + class DocumentRegressionTask(NewTask): class Config(NewTask.Config):