1using System; 2using System.IO; 3using System.Collections.Generic; 4using WindowCapture.Helpers; 5 6class TrainSeq2Spell 7{ 8 static void Main() 9 { 10 Console.OutputEncoding = System.Text.Encoding.UTF8; 11 string dataDir = Path.Combine(Path.GetDirectoryName( 12 System.Reflection.Assembly.GetExecutingAssembly().Location), "..", "Data"); 13 if (!Directory.Exists(dataDir)) 14 dataDir = Path.Combine(Environment.CurrentDirectory, "Data"); 15 16 Console.WriteLine("Loading dictionary..."); 17 var words = new List<string>(); 18 foreach (var l in File.ReadAllLines(Path.Combine(dataDir, "dict_ru.txt"))) 19 { string w = l.Trim().ToLower(); if (w.Length >= 2 && w.Length <= 20) words.Add(w); } 20 Console.WriteLine("Loaded " + words.Count + " words"); 21 22 string savePath = Path.Combine(dataDir, "seq2spell.bin"); 23 Console.WriteLine("Training Seq2Spell (40 epochs)..."); 24 Seq2Spell.Train(words.ToArray(), savePath, 40); 25 26 // Test 27 var model = new Seq2Spell(); 28 model.Load(savePath); 29 30 string[] tests = { "привет", "прввет", "компуктер", "здраствуте", "пшоел", "кароче", "тихналогия" }; 31 Console.WriteLine("\n=== Test ==="); 32 foreach (string t in tests) 33 Console.WriteLine(" " + t + " → " + model.Correct(t)); 34 35 Console.WriteLine("\nDone!"); 36 } 37}