public RootTrainingAction(IPlan plan, ContextMaps maps)
 {
     foreach (var contained in plan.ContainedPlans)
     {
         ChildActions.Add(new TrainingAction(contained, maps));
     }
 }
 public virtual void SaveContexts(ContextMaps contextMaps)
 {
     SaveContext(contextMaps);
     foreach (var trainingAction in ChildActions)
     {
         trainingAction.SaveContexts(contextMaps);
     }
 }
 public SentenceLearner(WordVectors vectors, Sentences sentences, ContextMaps contextMaps)
 {
     _vectors = vectors;
     _sentences = sentences;
     _network = NeuralNetworkFactory.CreateNeuralNetwork(
             WordVector.VectorLength + MorphoSyntacticContext.VectorLength, MorphoSyntacticContext.VectorLength, WordVector.VectorLength);
     _contextMaps = contextMaps;
     MinError = 0.01;
 }
Exemple #4
0
 public TrainingAction(IPlan plan, ContextMaps maps)
     : base(plan,maps)
 {
     _contextMap = maps.For(plan.Word);
     _weights = _contextMap.NeuronWeights;
     if (!plan.Output.HasValue) throw new ArgumentException("plan.Output must be set", "plan");
     _wordVector = _vectors[plan.Word];
     if (_outputArray == null)
     {
         _outputArray = OutputToArray(plan.Output.Value);
     }
 }
Exemple #5
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Use the unit tests");
            var loader = new WordVectorLoader(args[0]);
            var vectors = loader.LoadVectors();

            string fileName;
            if (args.Length == 1)
            {
                Console.WriteLine("Story file:");
                fileName = Console.ReadLine();
            }
            else
            {
                fileName = args[1];
            }

            var storyReader = new StoryReader(fileName);
            var sentences = storyReader.ReadStory();
            var firstWord = sentences.FirstWords().FirstOrDefault();
            Console.Write(firstWord != null ? firstWord.Word : "empty file");
            var contextMaps = new ContextMaps();
            var sentenceLearner = new SentenceLearner(vectors, sentences, contextMaps);
            var plan = sentenceLearner.PreparePlan(4);
            sentenceLearner.ExecutePlan(plan, MorphoSyntacticContext.InitialState());

            //sentenceLearner.Learn(1);
            while (true)
            {
                Console.Write("\n> ");
                var stdinReader = new StoryReader(Console.In);
                var sentence = stdinReader.ReadSentence();
                if (sentence.Words[0].IsEndOfSentence()) break;
                var result = sentenceLearner.Run(sentence);
                Console.WriteLine(result);

            }
            Console.WriteLine("Quitting");
        }
Exemple #6
0
 public override void SaveContext(ContextMaps contextMaps)
 {
     _contextMap.NeuronWeights = _weights;
 }
Exemple #7
0
 public static ITrainingAction ImplementPlan(IPlan plan, WordVectors vectors, ContextMaps maps)
 {
     _vectors = vectors;
     var action = new RootTrainingAction(plan, maps);
     return action;
 }
 public virtual void SaveContext(ContextMaps contextMaps)
 {
     //overridden in derived class
 }