static void Dump(string[] args) { if (args.Length < 3) { PrintDumpUsage(); Environment.Exit(-1); } var modelPath = args[1]; var option = args[2]; var fasttext = new FastText(); fasttext.LoadModel(modelPath); if (option == "args") { fasttext.GetArgs().Dump(Console.Out); } else if (option == "dict") { fasttext.GetDictionary().Dump(Console.Out); } else if (option == "input") { if (fasttext.IsQuant()) { Console.Error.WriteLine("Not supported for quantized models."); } else { fasttext.GetInputMatrix().Dump(Console.Out); } } else if (option == "output") { if (fasttext.IsQuant()) { Console.Error.WriteLine("Not supported for quantized models."); } else { fasttext.GetOutputMatrix().Dump(Console.Out); } } else { PrintDumpUsage(); Environment.Exit(-1); } }
static void Test(string [] args) { var perLabel = args[0] == "test-label"; if (args.Length < 3 || args.Length > 5) { if (perLabel) { PrintTestLabelUsage(); } else { PrintTestUsage(); } Environment.Exit(-1); } var model = args[1]; var input = args[2]; int k = args.Length > 3 ? int.Parse(args[3]) : 1; var threshold = args.Length > 4 ? float.Parse(args[4]) : 0f; var fasttext = new FastText(); fasttext.LoadModel(model); var meter = new Meter(); if (input == "-") { fasttext.Test(Console.OpenStandardInput(), k, threshold, meter); } else { var ifs = new FileStream(input, FileMode.Open, FileAccess.Read); if (!ifs.CanRead) { Console.Error.WriteLine("Test file cannot be opened!"); Environment.Exit(-1); } fasttext.Test(ifs, k, threshold, meter); } if (perLabel) { void writeMetric(string name, double value) { Console.Write($"{name} : "); if (double.IsFinite(value)) { Console.Write($"{value:0.######}"); } else { Console.Write("--------"); } Console.Write(" "); }; var dict = fasttext.GetDictionary(); for (int labelId = 0; labelId < dict.nlabels; labelId++) { writeMetric("F1-Score", meter.F1Score(labelId)); writeMetric("Precision", meter.Precision(labelId)); writeMetric("Recall", meter.Recall(labelId)); Console.WriteLine($" {dict.GetLabel(labelId)}"); } } meter.WriteGeneralMetrics(Console.Out, k); }