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()); } }
private static void Test(FastTextWrapper fastText) { 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?"); }
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?"); } }
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) { 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(); }