示例#1
0
 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?");
     }
 }
示例#2
0
 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());
     }
 }
示例#3
0
        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());
        }
示例#4
0
 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?");
     }
 }
示例#5
0
        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);
                }
            }
        }
示例#6
0
        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();
        }
示例#7
0
        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();
        }