feat(trainer): add normalise mode and accept base64
Windows sucks.
This commit is contained in:
parent
23895f6b86
commit
b738f801c8
|
@ -1,14 +1,17 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Buffers.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using ConsoleTables;
|
using ConsoleTables;
|
||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using CsvHelper.Configuration;
|
using CsvHelper.Configuration;
|
||||||
using Microsoft.ML;
|
using Microsoft.ML;
|
||||||
using Microsoft.ML.Data;
|
using Microsoft.ML.Data;
|
||||||
using Microsoft.ML.Transforms.Text;
|
using Microsoft.ML.Transforms.Text;
|
||||||
|
using NoSoliciting.Interface;
|
||||||
using NoSoliciting.Internal.Interface;
|
using NoSoliciting.Internal.Interface;
|
||||||
|
|
||||||
namespace NoSoliciting.Trainer {
|
namespace NoSoliciting.Trainer {
|
||||||
|
@ -34,6 +37,7 @@ namespace NoSoliciting.Trainer {
|
||||||
CreateModel,
|
CreateModel,
|
||||||
Interactive,
|
Interactive,
|
||||||
InteractiveFull,
|
InteractiveFull,
|
||||||
|
Normalise,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Main(string[] args) {
|
private static void Main(string[] args) {
|
||||||
|
@ -42,8 +46,23 @@ namespace NoSoliciting.Trainer {
|
||||||
"create-model" => Mode.CreateModel,
|
"create-model" => Mode.CreateModel,
|
||||||
"interactive" => Mode.Interactive,
|
"interactive" => Mode.Interactive,
|
||||||
"interactive-full" => Mode.InteractiveFull,
|
"interactive-full" => Mode.InteractiveFull,
|
||||||
|
"normalise" => Mode.Normalise,
|
||||||
_ => throw new ArgumentException("invalid argument"),
|
_ => throw new ArgumentException("invalid argument"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (mode == Mode.Normalise) {
|
||||||
|
Console.WriteLine("Ready");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Console.Write("> ");
|
||||||
|
var input = Console.ReadLine();
|
||||||
|
var bytes = Convert.FromBase64String(input!);
|
||||||
|
var toNormalise = Encoding.UTF8.GetString(bytes);
|
||||||
|
var normalised = NoSolUtil.Normalise(toNormalise);
|
||||||
|
Console.WriteLine(normalised);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var path = "../../../data.csv";
|
var path = "../../../data.csv";
|
||||||
|
|
||||||
if (args.Length > 1) {
|
if (args.Length > 1) {
|
||||||
|
@ -217,6 +236,12 @@ namespace NoSoliciting.Trainer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var size = Base64.GetMaxDecodedFromUtf8Length(parts[1].Length);
|
||||||
|
var buf = new byte[size];
|
||||||
|
if (Convert.TryFromBase64String(parts[1], buf, out var written)) {
|
||||||
|
parts[1] = Encoding.UTF8.GetString(buf[..written]);
|
||||||
|
}
|
||||||
|
|
||||||
var input = new Data(channel, parts[1]);
|
var input = new Data(channel, parts[1]);
|
||||||
var pred = predEngine.Predict(input);
|
var pred = predEngine.Predict(input);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user