public void Load(string modelFilePath) { EncodedModelFilePath = modelFilePath; ModelAttentionData tosave = new ModelAttentionData(); BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(EncodedModelFilePath, FileMode.Open, FileAccess.Read); tosave = bf.Deserialize(fs) as ModelAttentionData; fs.Close(); fs.Dispose(); this.bd = tosave.bd; this.clipval = tosave.clipval; this.decoder = tosave.decoder; this.Depth = tosave.Depth; this.encoder = tosave.encoder; this.HiddenSize = tosave.hidden_sizes; this.learning_rate = tosave.learning_rate; this.WordVectorSize = tosave.letter_size; this.max_word = 100; this.regc = tosave.regc; this.reversEncoder = tosave.ReversEncoder; this.UseDropout = tosave.UseDropout; this.Whd = tosave.Whd; this.s_Embedding = tosave.s_Wil; this.s_wordToIndex = tosave.s_wordToIndex; this.s_indexToWord = tosave.s_indexToWord; this.t_Embedding = tosave.t_Wil; this.t_wordToIndex = tosave.t_wordToIndex; this.t_indexToWord = tosave.t_indexToWord; }
public void Save() { ModelAttentionData tosave = new ModelAttentionData(); tosave.clipval = this.m_clipvalue; tosave.Depth = this.Depth; tosave.hidden_sizes = this.HiddenSize; tosave.learning_rate = m_startLearningRate; tosave.letter_size = this.WordVectorSize; tosave.max_chars_gen = this.m_maxWord; tosave.regc = this.m_regc; tosave.DropoutRatio = m_dropoutRatio; tosave.s_wordToIndex = m_srcWordToIndex; tosave.s_indexToWord = m_srcIndexToWord; tosave.t_wordToIndex = m_tgtWordToIndex; tosave.t_indexToWord = m_tgtIndexToWord; try { if (File.Exists(m_modelFilePath)) { File.Copy(m_modelFilePath, $"{m_modelFilePath}.bak", true); } BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(m_modelFilePath, FileMode.Create, FileAccess.Write); bf.Serialize(fs, tosave); m_bd[m_bdDefaultDeviceId].Save(fs); m_decoder[m_decoderDefaultDeviceId].Save(fs); m_encoder[m_encoderDefaultDeviceId].Save(fs); m_reversEncoder[m_reversEncoderDefaultDeviceId].Save(fs); m_Whd[m_WhdDefaultDeviceId].Save(fs); m_srcEmbedding[m_srcEmbeddingDefaultDeviceId].Save(fs); m_tgtEmbedding[m_tgtEmbeddingDefaultDeviceId].Save(fs); fs.Close(); fs.Dispose(); } catch (Exception err) { Logger.WriteLine($"Failed to save model to file. Exception = '{err.Message}'"); } }
public void Save() { ModelAttentionData tosave = new ModelAttentionData(); tosave.bd = this.bd; tosave.clipval = this.clipval; tosave.decoder = this.decoder; tosave.Depth = this.Depth; tosave.encoder = this.encoder; tosave.hidden_sizes = this.HiddenSize; tosave.learning_rate = this.learning_rate; tosave.letter_size = this.WordVectorSize; tosave.max_chars_gen = this.max_word; tosave.regc = this.regc; tosave.ReversEncoder = this.reversEncoder; tosave.UseDropout = this.UseDropout; tosave.Whd = this.Whd; tosave.s_Wil = this.s_Embedding; tosave.s_wordToIndex = s_wordToIndex; tosave.s_indexToWord = s_indexToWord; tosave.t_Wil = this.t_Embedding; tosave.t_wordToIndex = t_wordToIndex; tosave.t_indexToWord = t_indexToWord; try { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(EncodedModelFilePath, FileMode.Create, FileAccess.Write); bf.Serialize(fs, tosave); fs.Close(); fs.Dispose(); } catch (Exception err) { Logger.WriteLine($"Failed to save model to file. Exception = '{err.Message}'"); } }
public void Load(string modelFilePath) { Logger.WriteLine($"Loading model from '{modelFilePath}'..."); m_modelFilePath = modelFilePath; ModelAttentionData tosave = new ModelAttentionData(); BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(m_modelFilePath, FileMode.Open, FileAccess.Read); tosave = bf.Deserialize(fs) as ModelAttentionData; m_clipvalue = tosave.clipval; Depth = tosave.Depth; HiddenSize = tosave.hidden_sizes; m_startLearningRate = tosave.learning_rate; WordVectorSize = tosave.letter_size; m_maxWord = 100; m_regc = tosave.regc; m_dropoutRatio = tosave.DropoutRatio; m_srcWordToIndex = tosave.s_wordToIndex; m_srcIndexToWord = tosave.s_indexToWord; m_tgtWordToIndex = tosave.t_wordToIndex; m_tgtIndexToWord = tosave.t_indexToWord; InitWeights(); m_bd[m_bdDefaultDeviceId].Load(fs); m_decoder[m_decoderDefaultDeviceId].Load(fs); m_encoder[m_encoderDefaultDeviceId].Load(fs); m_reversEncoder[m_reversEncoderDefaultDeviceId].Load(fs); m_Whd[m_WhdDefaultDeviceId].Load(fs); m_srcEmbedding[m_srcEmbeddingDefaultDeviceId].Load(fs); m_tgtEmbedding[m_tgtEmbeddingDefaultDeviceId].Load(fs); fs.Close(); fs.Dispose(); }