From 1b67219f0a5a8474c80c562c36265a8661f76d4e Mon Sep 17 00:00:00 2001 From: zewditu Hailemariam Date: Mon, 31 Jul 2023 22:50:50 -0700 Subject: [PATCH 1/2] Add QA sweepable --- .../CodeGen/QuestionAnswering.cs | 27 ++++++++++ .../CodeGen/estimator-schema.json | 3 +- .../CodeGen/question-answering.json | 51 +++++++++++++++++++ .../CodeGen/search-space-schema.json | 3 +- .../CodeGen/trainer-estimators.json | 7 +++ 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs create mode 100644 src/Microsoft.ML.AutoML/CodeGen/question-answering.json diff --git a/src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs b/src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs new file mode 100644 index 0000000000..c1e454016d --- /dev/null +++ b/src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +using Microsoft.ML.TorchSharp; +using Microsoft.ML.TorchSharp.NasBert; +using Microsoft.ML.TorchSharp.Roberta; + +namespace Microsoft.ML.AutoML.CodeGen +{ + internal class QuestionAnsweringMulti + { + public IEstimator BuildFromOption(MLContext context, QATrainer.Options param) + { + return context.MulticlassClassification.Trainers.QuestionAnswer( + contextColumnName: param.ContextColumnName, + questionColumnName: param.QuestionColumnName, + trainingAnswerColumnName: param.TrainingAnswerColumnName, + answerIndexColumnName: param.AnswerIndexStartColumnName, + predictedAnswerColumnName: param.PredictedAnswerColumnName, + scoreColumnName: param.ScoreColumnName, + batchSize: param.BatchSize, + maxEpochs: param.MaxEpoch, + topK: param.TopKAnswers, + architecture: BertArchitecture.Roberta); + } + } +} diff --git a/src/Microsoft.ML.AutoML/CodeGen/estimator-schema.json b/src/Microsoft.ML.AutoML/CodeGen/estimator-schema.json index b62d4c217f..8c12390426 100644 --- a/src/Microsoft.ML.AutoML/CodeGen/estimator-schema.json +++ b/src/Microsoft.ML.AutoML/CodeGen/estimator-schema.json @@ -73,7 +73,8 @@ "ForecastBySsa", "TextClassifcation", "SentenceSimilarity", - "ObjectDetection" + "ObjectDetection", + "QuestionAnswering" ] }, "nugetDependencies": { diff --git a/src/Microsoft.ML.AutoML/CodeGen/question-answering.json b/src/Microsoft.ML.AutoML/CodeGen/question-answering.json new file mode 100644 index 0000000000..6f9b6bba74 --- /dev/null +++ b/src/Microsoft.ML.AutoML/CodeGen/question-answering.json @@ -0,0 +1,51 @@ +{ + "$schema": "./search-space-schema.json#", + "name": "question_answering _option", + "search_space": [ + { + "name": "ContextColumnName", + "type": "string", + "default": "Context" + }, + { + "name": " QuestionColumnName", + "type": "string", + "default": "Question" + }, + { + "name": "TrainingAnswerColumnName", + "type": "string", + "default": "TrainingAnswer" + }, + { + "name": "AnswerIndexStartColumnName", + "type": "string", + "default": "AnswerStart" + }, + { + "name": "ScoreColumnName", + "type": "string", + "default": "Score" + }, + { + "name": "predictedAnswerColumnName", + "type": "string", + "default": "Answer" + }, + { + "name": "BatchSize", + "type": "integer", + "default": 4 + }, + { + "name": "MaxEpochs", + "type": "integer", + "default": 10 + }, + { + "name": "Architecture", + "type": "bertArchitecture", + "default": "BertArchitecture.Roberta" + } + ] +} diff --git a/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json b/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json index e9e680e86e..4d9b55cd62 100644 --- a/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json +++ b/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json @@ -146,7 +146,8 @@ "dnn_featurizer_image_option", "text_classification_option", "sentence_similarity_option", - "object_detection_option" + "object_detection_option", + "question_answering _option" ] }, "option_name": { diff --git a/src/Microsoft.ML.AutoML/CodeGen/trainer-estimators.json b/src/Microsoft.ML.AutoML/CodeGen/trainer-estimators.json index 9eab12f286..0ce5a45e37 100644 --- a/src/Microsoft.ML.AutoML/CodeGen/trainer-estimators.json +++ b/src/Microsoft.ML.AutoML/CodeGen/trainer-estimators.json @@ -532,6 +532,13 @@ "usingStatements": [ "Microsoft.ML", "Microsoft.ML.Trainers", "Microsoft.ML.TorchSharp" ], "searchOption": "object_detection_option" }, + { + "functionName": "QuestionAnswering", + "estimatorTypes": [ "MultiClassification" ], + "nugetDependencies": [ "Microsoft.ML", "Microsoft.ML.TorchSharp" ], + "usingStatements": [ "Microsoft.ML", "Microsoft.ML.Trainers", "Microsoft.ML.TorchSharp" ], + "searchOption": "question_answering_option" + }, { "functionName": "ForecastBySsa", "estimatorTypes": [ "Forecasting" ], From 48a813403a792b3990d9cf78814f895d8c4bae5b Mon Sep 17 00:00:00 2001 From: zewditu Hailemariam Date: Tue, 1 Aug 2023 14:41:23 -0700 Subject: [PATCH 2/2] clean --- ...ering.json => question_answering_search_space.json} | 9 +++++++-- .../CodeGen/search-space-schema.json | 10 ++++++++-- src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj | 2 +- .../Estimators}/QuestionAnswering.cs | 7 ++++--- 4 files changed, 20 insertions(+), 8 deletions(-) rename src/Microsoft.ML.AutoML/CodeGen/{question-answering.json => question_answering_search_space.json} (85%) rename src/Microsoft.ML.AutoML/{CodeGen => SweepableEstimator/Estimators}/QuestionAnswering.cs (82%) diff --git a/src/Microsoft.ML.AutoML/CodeGen/question-answering.json b/src/Microsoft.ML.AutoML/CodeGen/question_answering_search_space.json similarity index 85% rename from src/Microsoft.ML.AutoML/CodeGen/question-answering.json rename to src/Microsoft.ML.AutoML/CodeGen/question_answering_search_space.json index 6f9b6bba74..83d7b0b538 100644 --- a/src/Microsoft.ML.AutoML/CodeGen/question-answering.json +++ b/src/Microsoft.ML.AutoML/CodeGen/question_answering_search_space.json @@ -1,6 +1,6 @@ { "$schema": "./search-space-schema.json#", - "name": "question_answering _option", + "name": "question_answering_option", "search_space": [ { "name": "ContextColumnName", @@ -8,7 +8,7 @@ "default": "Context" }, { - "name": " QuestionColumnName", + "name": "QuestionColumnName", "type": "string", "default": "Question" }, @@ -42,6 +42,11 @@ "type": "integer", "default": 10 }, + { + "name": "TopKAnswers", + "type": "integer", + "default": 3 + }, { "name": "Architecture", "type": "bertArchitecture", diff --git a/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json b/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json index 4d9b55cd62..5d28914734 100644 --- a/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json +++ b/src/Microsoft.ML.AutoML/CodeGen/search-space-schema.json @@ -147,7 +147,7 @@ "text_classification_option", "sentence_similarity_option", "object_detection_option", - "question_answering _option" + "question_answering_option" ] }, "option_name": { @@ -211,7 +211,13 @@ "Steps", "MaxEpoch", "InitLearningRate", - "WeightDecay" + "WeightDecay", + "ContextColumnName", + "QuestionColumnName", + "TrainingAnswerColumnName", + "AnswerIndexStartColumnName", + "predictedAnswerColumnName", + "TopKAnswers" ] }, "option_type": { diff --git a/src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj b/src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj index 4f5c192cd6..6ecc501c11 100644 --- a/src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj +++ b/src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj @@ -69,7 +69,7 @@ - + PreserveNewest diff --git a/src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs b/src/Microsoft.ML.AutoML/SweepableEstimator/Estimators/QuestionAnswering.cs similarity index 82% rename from src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs rename to src/Microsoft.ML.AutoML/SweepableEstimator/Estimators/QuestionAnswering.cs index c1e454016d..64f99961ec 100644 --- a/src/Microsoft.ML.AutoML/CodeGen/QuestionAnswering.cs +++ b/src/Microsoft.ML.AutoML/SweepableEstimator/Estimators/QuestionAnswering.cs @@ -7,9 +7,9 @@ namespace Microsoft.ML.AutoML.CodeGen { - internal class QuestionAnsweringMulti + internal partial class QuestionAnsweringMulti { - public IEstimator BuildFromOption(MLContext context, QATrainer.Options param) + public override IEstimator BuildFromOption(MLContext context, QuestionAnsweringOption param) { return context.MulticlassClassification.Trainers.QuestionAnswer( contextColumnName: param.ContextColumnName, @@ -19,9 +19,10 @@ public IEstimator BuildFromOption(MLContext context, QATrainer.Opt predictedAnswerColumnName: param.PredictedAnswerColumnName, scoreColumnName: param.ScoreColumnName, batchSize: param.BatchSize, - maxEpochs: param.MaxEpoch, + maxEpochs: param.MaxEpochs, topK: param.TopKAnswers, architecture: BertArchitecture.Roberta); } + } }