public void Word2Vec() { using (var fastText = new FastTextWrapper()) { fastText.LoadModel(Path.Combine(dataDir, "dbpedia.ftz")); var vector = fastText.GetSentenceVector("Can I use a larger crockpot than the recipe calls for?"); } }
public static double[] Cosine(string src, string[] dst, string model) { using (var fastText = new FastTextWrapper()) { fastText.LoadModel(model); var vector = fastText.GetSentenceVector(src.ToLower()); return(dst.Select(x => CalCosine(vector, fastText.GetSentenceVector(x.ToLower()))).ToArray()); } }
public void CanLoadSupervisedModel() { using var fastText = new FastTextWrapper(loggerFactory: _loggerFactory); fastText.LoadModel(_fixture.FastText.ModelPath); fastText.IsModelReady().Should().BeTrue(); fastText.GetModelDimension().Should().Be(100); AssertLabels(fastText.GetLabels()); }
private static void LoadModel() { using (var fastText = new FastTextWrapper()) { fastText.LoadModel(@"D:\__Models\cooking.bin"); var labels = fastText.GetLabels(); var prediction = fastText.PredictSingle("Can I use a larger crockpot than the recipe calls for?"); var predictions = fastText.PredictMultiple("Can I use a larger crockpot than the recipe calls for?", 4); var vector = fastText.GetSentenceVector("Can I use a larger crockpot than the recipe calls for?"); } }
static void Main(string[] args) { if ((args.FirstOrDefault() == "nn" && args.Length < 2) || (args.FirstOrDefault() != "nn" && args.Length < 3)) { Console.WriteLine(Usage); return; } using (var fastText = new FastTextWrapper()) { switch (args[0]) { case "train": TrainSupervised(fastText, args[1], args[2]); break; case "trainlowlevel": TrainLowLevel(fastText, args[1], args[2]); break; case "load": fastText.LoadModel(args[2]); break; } if (args[0] != "nn") { Test(fastText); } else { fastText.LoadModel(File.ReadAllBytes(args[1])); TestNN(fastText); } } }
public void CanQuantizeLoadedSupervisedModel() { using var fastText = new FastTextWrapper(loggerFactory: _loggerFactory); fastText.LoadModel(_fixture.FastText.ModelPath); fastText.IsModelReady().Should().BeTrue(); fastText.GetModelDimension().Should().Be(100); AssertLabels(fastText.GetLabels()); string newPath = Path.Combine(Path.GetDirectoryName(_fixture.FastText.ModelPath), Path.GetFileNameWithoutExtension(_fixture.FastText.ModelPath)); fastText.Quantize(); fastText.IsModelReady().Should().BeTrue(); fastText.GetModelDimension().Should().Be(100); fastText.ModelPath.Should().Be(newPath + ".ftz"); File.Exists(newPath + ".ftz").Should().BeTrue(); File.Exists(newPath + ".vec").Should().BeTrue(); }
static void Main(string[] args) { var model = Path.Combine(@"D:\SciSharp\CherubNLP\data", "dbpedia.bin"); using (var fastText = new FastTextWrapper()) { fastText.LoadModel(model); var vector1 = fastText.GetSentenceVector("Hello"); } var similarities = Similarity.Cosine("Power Outage -Fifth & Park - JPMC150713", new[] { "Cosine Similarity algorithm function sample.", "Power Restored -Fifth & Park - JPMC150713", "Compute the similarity of two hardcoded lists.", "We can compute the similarity of two hardcoded lists.", "Coronavirus app could trace your contacts without sacrificing your privacy" }, model); // var test = new KaggleTest(); // test.SpookyAuthorIdentification(); }