From 2fd2e544019a6fbc4de4b9ad3180d1b5312fc882 Mon Sep 17 00:00:00 2001 From: Anna Date: Tue, 2 Mar 2021 12:38:30 -0500 Subject: [PATCH] feat: add automated model creation --- .build.yml | 17 +++++++++++++++++ NoSoliciting.Trainer/Program.cs | 30 +++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 .build.yml diff --git a/.build.yml b/.build.yml new file mode 100644 index 0000000..d3a13aa --- /dev/null +++ b/.build.yml @@ -0,0 +1,17 @@ +image: fedora +packages: + - dotnet +sources: + - git@git.sr.ht:~jkcclemens/NoSoliciting +tasks: + - build: | + cd NoSoliciting/NoSoliciting.Trainer + dotnet build -c Release + - test: | + cd NoSoliciting/NoSoliciting.Trainer + ./bin/Release/net5/NoSoliciting.Trainer test data.csv + - create-model: | + cd NoSoliciting/NoSoliciting.Trainer + ./bin/Release/net5/NoSoliciting.Trainer create-model data.csv +artifacts: + - NoSoliciting/NoSoliciting.Trainer/model.zip diff --git a/NoSoliciting.Trainer/Program.cs b/NoSoliciting.Trainer/Program.cs index 0f84011..f3777ee 100644 --- a/NoSoliciting.Trainer/Program.cs +++ b/NoSoliciting.Trainer/Program.cs @@ -26,8 +26,21 @@ namespace NoSoliciting.Trainer { "blu", }; + private enum Mode { + Test, + CreateModel, + Interactive, + InteractiveFull, + } + private static void Main(string[] args) { - var full = args[0] == "create"; + var mode = args[0] switch { + "test" => Mode.Test, + "create-model" => Mode.CreateModel, + "interactive" => Mode.Interactive, + "interactive-full" => Mode.InteractiveFull, + _ => throw new ArgumentException("invalid argument"), + }; var path = "../../../data.csv"; if (args.Length > 1) { @@ -121,11 +134,16 @@ namespace NoSoliciting.Trainer { .Append(ctx.MulticlassClassification.Trainers.SdcaMaximumEntropy(exampleWeightColumnName: "Weight")) .Append(ctx.Transforms.Conversion.MapKeyToValue("PredictedLabel")); - var train = full ? df : ttd.TrainSet; + var train = mode switch { + Mode.Test => ttd.TrainSet, + Mode.CreateModel => df, + Mode.Interactive => ttd.TrainSet, + Mode.InteractiveFull => df, + }; var model = pipeline.Fit(train); - if (full) { + if (mode == Mode.CreateModel) { var savePath = Path.Join(parentDir.FullName, "model.zip"); ctx.Model.Save(model, train.Schema, savePath); } @@ -168,8 +186,10 @@ namespace NoSoliciting.Trainer { Console.WriteLine($"Macro acc: {eval.MacroAccuracy * 100}"); Console.WriteLine($"Micro acc: {eval.MicroAccuracy * 100}"); - if (full) { - return; + switch (mode) { + case Mode.Test: + case Mode.CreateModel: + return; } while (true) {