public void TestRandomExcluding() { _target = new WordVectors(10); var wv1 = new WordVector {Name = "wv1" }; var wv2 = new WordVector { Name = "wv2" }; ; var wv3 = new WordVector { Name = "wv3" }; ; var wv4 = new WordVector { Name = "wv4" }; ; _target.TryAdd("wv1", wv1); _target.TryAdd("wv2", wv2); _target.TryAdd("wv3", wv3); _target.TryAdd("wv4", wv4); var result = _target.RandomExcluding(new HashSet<WordVector> {wv1, wv2, wv3}); result.Should().Be(wv4); }
public void TestTrain() { var stream = new StringReader(@"Hey! Look here!"); var storyReader = new StoryReader(stream); var sentences = storyReader.ReadStory(); var wordVectors = new WordVectors(10); wordVectors.TryAdd("Hey", new WordVector { Name = "Hey" }); wordVectors.TryAdd("Look", new WordVector { Name = "Look" }); wordVectors.TryAdd("here", new WordVector { Name = "here" }); wordVectors.TryAdd("Test", new WordVector { Name = "Test" }); wordVectors.TryAdd("!", new WordVector { Name = "!" }); var contextMaps = new ContextMaps(); var target = new SentenceLearner(wordVectors, sentences, contextMaps); var trainingPlan = target.PreparePlan(4); //should train Hey,ctx0,1; Look,ctx0,0; here,ctx0,-1, here,ctx1,1 trainingPlan.ContainsPlanStep(new WrittenWord("Hey"), TrainingOutput.Complete).Should().BeTrue(); trainingPlan.ContainsPlanStep(new WrittenWord("Look"), TrainingOutput.Incomplete).Should().BeTrue(); trainingPlan.ContainsPlanStep(new WrittenWord("Test"), TrainingOutput.Incomplete).Should().BeFalse(); }
public void TestTrain2() { var stream = new StringReader(@"Hey! Look here!"); var storyReader = new StoryReader(stream); var sentences = storyReader.ReadStory(); var wordVectors = new WordVectors(10); var contextMaps = new ContextMaps(); wordVectors.TryAdd("Hey", new WordVector { Name = "Hey" }); wordVectors.TryAdd("Look", new WordVector { Name = "Look" }); wordVectors.TryAdd("here", new WordVector { Name = "here" }); wordVectors.TryAdd("Test", new WordVector { Name = "Test" }); wordVectors.TryAdd("!", new WordVector { Name = "!" }); var target = new SentenceLearner(wordVectors, sentences, contextMaps); var plan = target.PreparePlan(4); target.ExecutePlan(plan, MorphoSyntacticContext.InitialState()); var weights = target.GetWeightsForWord(new WrittenWord("Hey")); }