public string Translate(string input) { string output = Seq2SeqInstance.Call(input); Logger.WriteLine($"'{input}' -> '{output}'"); return(output); }
private string CallBackend(string srcInputText, string tgtInputText, int tokenNumToGenerate, bool random, float repeatPenalty, int tgtContextSize) { srcInputText = srcInputText.Replace("<br />", "").Replace("「", "“").Replace("」", "”"); tgtInputText = tgtInputText.Replace("<br />", "").Replace("「", "“").Replace("」", "”"); string[] srcLines = srcInputText.Split("\n"); string[] tgtLines = tgtInputText.Split("\n"); srcInputText = String.Join(" ", srcLines).ToLower(); tgtInputText = String.Join(" ", tgtLines).ToLower(); string prefixTgtLine = ""; if (tgtInputText.Length > tgtContextSize) { prefixTgtLine = tgtInputText.Substring(0, tgtInputText.Length - tgtContextSize); tgtInputText = tgtInputText.Substring(tgtInputText.Length - tgtContextSize); } Stopwatch stopwatch = Stopwatch.StartNew(); if (srcInputText.EndsWith("。") == false && srcInputText.EndsWith("?") == false && srcInputText.EndsWith("!") == false) { srcInputText = srcInputText + "。"; } string logStr = $"Input Text = '{srcInputText}', Repeat Penalty = '{repeatPenalty}', Target Context Size = '{tgtContextSize}'"; if (setInputSents.Contains(logStr) == false) { Logger.WriteLine(logStr); setInputSents.Add(logStr); } string outputText = Seq2SeqInstance.Call(srcInputText, tgtInputText, tokenNumToGenerate, random, repeatPenalty); stopwatch.Stop(); outputText = prefixTgtLine + outputText; outputText = outputText.Replace("「", "“").Replace("」", "”"); var outputSents = SplitSents(outputText); return(String.Join("<br />", outputSents)); }