Ejemplo n.º 1
0
 public void SetupNetwork()
 {
     _vectors = Substitute.For<WordVectors>();
     _sentences = Substitute.For<Sentences>();
     SentenceLearner.NeuralNetworkFactory = _neuralNetworkFactory = new NeuralNetworkFactory();
     _contextMaps = new ContextMaps();
     _target = new SentenceLearner(_vectors, _sentences,_contextMaps);
 }
Ejemplo n.º 2
0
 public void TestConstructor()
 {
     var factory = Substitute.For<NeuralNetworkFactory>();
     SentenceLearner.NeuralNetworkFactory = factory;
     WordVector.VectorLength = 10;
     MorphoSyntacticContext.VectorLength = 15;
     var target = new SentenceLearner(_vectors, _sentences, _contextMaps);
     factory.Received(1).CreateNeuralNetwork(25, 15,10);
 }
Ejemplo n.º 3
0
 public void LoadAndLearn()
 {
     var wvl =new WordVectorLoader("wikipedia_vectors.txt");
     var sw = Stopwatch.StartNew();
     _wordVectors = wvl.LoadVectors();
     sw.Stop();
     Debug.WriteLine("Loaded word vectors in {0} ms", sw.ElapsedMilliseconds);
     var s = new StoryReader("WikiJunior_Biology.txt");
     var sentences = s.ReadStory();
     _contextMaps = new ContextMaps();
     _sentenceLearner = new SentenceLearner(_wordVectors, sentences, _contextMaps);
     var plan = _sentenceLearner.PreparePlan(12);
     _sentenceLearner.ExecutePlan(plan, MorphoSyntacticContext.InitialState());
 }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        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"));
        }