public static GRNNLayer readGRNN(string path) { FileStream fs = new FileStream(path, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); GRNNLayer ps = bf.Deserialize(fs) as GRNNLayer; fs.Close(); return(ps); }
public static void Run() { System.DateTime currentTime = System.DateTime.Now; readword(); Global.inputDim = 100; Global.hiddenDim = 100; readfourword(); Global.randn = new Normal(); DataSet X = new DataSet(); if (Global.isRead == 1) { string path = "model//deepNetwork"; Global.upLSTMLayer = LSTMLayer.readLSTM(path + "//lstmmodel.txt"); Global.upLSTMLayerr = LSTMLayer.readLSTM(path + "//lstmmodelr.txt"); Global.GRNNLayer1 = GRNNLayer.readGRNN(path + "//grnnmodel1.txt"); Global.GRNNLayer2 = GRNNLayer.readGRNN(path + "//grnnmodel2.txt"); Global.GRNNLayer3 = GRNNLayer.readGRNN(path + "//grnnmodel3.txt"); Global.GRNNLayer4 = GRNNLayer.readGRNN(path + "//grnnmodel4.txt"); Global.feedForwardLayer = FeedForwardLayer.readFF(path + "//feedforwardmodel.txt"); Global.wordEmbedding = LSTMLayer.getSerializeWordembedding(path + "//embedding.txt", Global.wordEmbedding); } else { Global.GRNNLayer1 = new GRNNLayer(); Global.GRNNLayer2 = new GRNNLayer(); Global.GRNNLayer3 = new GRNNLayer(); Global.GRNNLayer4 = new GRNNLayer(); Global.upLSTMLayer = new LSTMLayer(); Global.upLSTMLayerr = new LSTMLayer(); Global.feedForwardLayer = new FeedForwardLayer(); } Trainer.train(X); Global.swLog.Close(); System.DateTime currentTime_1 = System.DateTime.Now; Console.WriteLine(currentTime_1 - currentTime); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("Choose running mode: 1. training, 2. testing"); string mode = Console.ReadLine(); if (mode == "1") { Global.mode = "train"; } else if (mode == "2") { Global.mode = "test"; } //Console.WriteLine("Choose reading mode: 1. read saved model, 2. read model trained on MSR dataset."); //string read = Console.ReadLine(); //string modes = Console.ReadLine(); //if (modes == "1") //{ // Global.isRead = true; //} //else if (modes == "2") //{ // Global.isRead = false; //} Console.WriteLine("Choose the bigram feature mode: 1. read bigram features, 2. create bigram features"); string bigramfeature = Console.ReadLine(); if (bigramfeature == "1") { Global.isReadBigramfeature = true; } else if (bigramfeature == "2") { Global.isReadBigramfeature = false; } readword(); readbigramword(); readidoimword(); Global.randn = new Normal(); Global._UpLSTMLayer = LSTMLayer.readLSTM("model\\lstmmodel.txt"); Global._UpLSTMLayerr = LSTMLayer.readLSTM("model\\lstmmodelr.txt"); // Global._LSTMLayerr = LSTMLayer.readLSTM("model\\lstmmodelr.txt"); Global._GRNNLayer1 = GRNNLayer.readGRNN("model\\grnnmodel1.txt"); Global._GRNNLayer2 = GRNNLayer.readGRNN("model\\grnnmodel2.txt"); Global._GRNNLayer3 = GRNNLayer.readGRNN("model\\grnnmodel3.txt"); Global._GRNNLayer4 = GRNNLayer.readGRNN("model\\grnnmodel4.txt"); Global._feedForwardLayer = FeedForwardLayer.readFF("model\\feedforwardmodel.txt"); LSTMLayer.getSerializeWordembedding(); LSTMLayer.getSerializeBigramWordembedding(); DataSet X = new DataSet(); Trainer.train(X); Global.swLog.Close(); }