Пример #1
0
        static void Main(string[] args)
        {
            System.Random r = new Random(5);
            Preprocess();
            S2S = new AttentionSeq2Seq(32, 16, 1, input, output, true);
            try { S2S.Load(); } catch (Exception) { }

            int c = 0;

            S2S.IterationDone += (a1, a2) =>
            {
                CostEventArg ep = a2 as CostEventArg;

                if (c % 100 == 0)
                {
                    Console.WriteLine($"Cost {ep.Cost} Iteration {ep.Iteration} k {c}");
                    S2S.Save();
                }
                c++;
            };

            MainThread = new Thread(new ThreadStart(Train));
            MainThread.Start();

            ReadThread = new Thread(new ThreadStart(ReadingConsole));
            ReadThread.Start();
        }
Пример #2
0
        static void ReadingConsole()
        {
            while (true)
            {
                var Line = RemoveAccentMark(Console.ReadLine().ToLower());
                if (!MainThread.IsAlive)
                {
                    if (Line == "!resume")
                    {
                        MainThread = new Thread(new ThreadStart(Train));
                        MainThread.Start();
                    }
                    else
                    {
                        try
                        {
                            var pred = S2S.Predict(Line.Trim().Split(' ').ToList());
                            Console.WriteLine($"<< {Line}");

                            Console.Write(">>");
                            for (int i = 0; i < pred.Count; i++)
                            {
                                Console.Write(pred[i] + " ");
                            }
                            Console.WriteLine();
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Deja de usar palabras raras crj");
                        }
                    }
                }
                else
                {
                    if (Line == "!stop")
                    {
                        MainThread.Abort();
                        Console.WriteLine("Process stoped");
                        S2S.Save();
                    }
                }
            }
        }
Пример #3
0
        private void Train()
        {
            ss.Train(300);

            ss.Save();
        }