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(); }
static void ss_IterationDone(object sender, EventArgs e) { CostEventArg ep = e as CostEventArg; if (float.IsInfinity(ep.Cost) == false) { TimeSpan ts = DateTime.Now - ep.StartDateTime; double sentPerMin = 0; if (ts.TotalMinutes > 0) { sentPerMin = ep.ProcessedInTotal / ts.TotalMinutes; } Logger.WriteLine($"Epoch = '{ep.Epoch}' Learning Rate = '{ep.LearningRate}', Avg Cost = '{(ep.CostInTotal / ep.ProcessedInTotal).ToString("F6")}', SentInTotal = '{ep.ProcessedInTotal}', SentPerMin = '{sentPerMin.ToString("F")}'"); } }
public static void Ss_StatusUpdateWatcher(object sender, EventArgs e) { CostEventArg ep = e as CostEventArg; TimeSpan ts = DateTime.Now - ep.StartDateTime; double sentPerMin = 0; double wordPerSec = 0; if (ts.TotalMinutes > 0) { sentPerMin = ep.ProcessedSentencesInTotal / ts.TotalMinutes; } if (ts.TotalSeconds > 0) { wordPerSec = ep.ProcessedWordsInTotal / ts.TotalSeconds; } Logger.WriteLine($"Update = {ep.Update}, Epoch = {ep.Epoch}, LR = {ep.LearningRate:F6}, AvgCost = {ep.AvgCostInTotal:F4}, Sent = {ep.ProcessedSentencesInTotal}, SentPerMin = {sentPerMin:F}, WordPerSec = {wordPerSec:F}"); }
static void ss_IterationDone(object sender, EventArgs e) { CostEventArg ep = e as CostEventArg; if (float.IsInfinity(ep.CostPerWord) == false) { TimeSpan ts = DateTime.Now - ep.StartDateTime; double sentPerMin = 0; double wordPerSec = 0; if (ts.TotalMinutes > 0) { sentPerMin = ep.ProcessedSentencesInTotal / ts.TotalMinutes; } if (ts.TotalSeconds > 0) { wordPerSec = ep.ProcessedWordsInTotal / ts.TotalSeconds; } Logger.WriteLine($"Epoch = '{ep.Epoch}' LR = '{ep.AvgLearningRate}', Current Cost = '{ep.CostPerWord.ToString("F6")}', Avg Cost = '{ep.avgCostInTotal.ToString("F6")}', SentInTotal = '{ep.ProcessedSentencesInTotal}', SentPerMin = '{sentPerMin.ToString("F")}', WordPerSec = '{wordPerSec.ToString("F")}'"); } }
private static void ss_IterationDone(object sender, EventArgs e) { CostEventArg ep = e as CostEventArg; if (float.IsInfinity(ep.CostPerWord) == false) { TimeSpan ts = DateTime.Now - ep.StartDateTime; double sentPerMin = 0; double wordPerSec = 0; if (ts.TotalMinutes > 0) { sentPerMin = ep.ProcessedSentencesInTotal / ts.TotalMinutes; } if (ts.TotalSeconds > 0) { wordPerSec = ep.ProcessedWordsInTotal / ts.TotalSeconds; } Logger.WriteLine($"Update = {ep.Update}, Epoch = {ep.Epoch}, LR = {ep.LearningRate.ToString("F6")}, Cost = {ep.CostPerWord.ToString("F4")}, AvgCost = {ep.AvgCostInTotal.ToString("F4")}, Sent = {ep.ProcessedSentencesInTotal}, SentPerMin = {sentPerMin.ToString("F")}, WordPerSec = {wordPerSec.ToString("F")}"); } }
static void Main(string[] args) { if (args.Length > 0) { int.TryParse(args[0], out times); } if (args.Length > 1) { int.TryParse(args[1], out dim); } if (args.Length > 2) { int.TryParse(args[2], out hdim); } //Random r = new Random(5); try { S2S = Seq2Seq.Load(); } catch (Exception ex) { var msg = LogService.Exception(ex); Console.WriteLine(msg); S2S = null; } if (S2S == null) { Preprocess(); S2S = new Seq2Seq(dim, hdim, dep, input, output, true); } //添加事件 int c = 0; var lastdone = DateTime.Now; S2S.IterationDone += (a1, a2) => { CostEventArg ep = a2 as CostEventArg; var dtnow = DateTime.Now; if ((dtnow - lastdone).TotalSeconds >= 10)//c % 300 == 0 || { lastdone = dtnow; Console.WriteLine($"训练次数 {ep.Iteration + 1}/{times} 完成行数 {c}"); S2S.Save(); } c++; }; S2S.EpochDone += (o, e) => { CostEventArg ep = e as CostEventArg; Console.WriteLine($"训练批次 {ep.Iteration + 1}/{times} 完成"); }; S2S.TrainDone += (o, e) => { CostEventArg ep = e as CostEventArg; Console.WriteLine($"训练任务 {times}次 完成"); S2S.Save(false); }; S2S.TrainStart += (o, e) => { CostEventArg ep = e as CostEventArg; Console.WriteLine($"训练开始 将训{times}次"); }; //创建模式 不是加载模式 if (S2S.newType == "new") { MainThread = new Thread(new ThreadStart(Train)); MainThread.Start(); } ReadThread = new Thread(new ThreadStart(ReadingConsole)); ReadThread.Start(); //System.Threading.AutoResetEvent resetEvent = new AutoResetEvent(false); //resetEvent.WaitOne(); //Console.ReadKey(); }
public void Progress(CostEventArg cost) { label5.Text = cost.Iteration.ToString(); label3.Text = cost.Cost.ToString(); label2.Text = DateTime.Now.ToLongTimeString(); }
void ss_IterationDone(object sender, EventArgs e) { CostEventArg ep = e as CostEventArg; this.Invoke(new ProgressDeleget(Progress), ep); }