public void ReadModel(string filename) { string contents = File.ReadAllText(filename); var data = (ModelSaver)DataStructures.Deserialization(contents, typeof(ModelSaver)); Ip2VecModel.SuDeserializer(data, this); //this.WordCount = this.Word2Index.Count(); //this.Ip2VecSettings.NeuronCount = data.Y; }
private static void SuDeserializer(ModelSaver data, Ip2VecModel ipNumerizerByIp2Vec) { var w1array = Array.ConvertAll(data.W1String.Split(','), double.Parse); var w2array = Array.ConvertAll(data.W2String.Split(','), double.Parse); ipNumerizerByIp2Vec.W1 = Matrix <double> .Build.Dense(data.X, data.Y, w1array); ipNumerizerByIp2Vec.W2 = Matrix <double> .Build.Dense(data.X, data.Y, w2array); var words = data.Indexer.Split(','); for (int i = 0; i < words.Count(); i++) { ipNumerizerByIp2Vec.Index2Word[i] = words[i]; ipNumerizerByIp2Vec.Word2Index[words[i]] = i; } ipNumerizerByIp2Vec.Frequency = data.Frequencies.Split(',').Select(x => int.Parse(x)).ToList(); }
private static ModelSaver PreSerializer(Ip2VecModel ipNumerizerByIp2Vec) { var w1string = string.Join(",", ipNumerizerByIp2Vec.W1.ToColumnMajorArray().Select(x => x.ToString("R"))); var w2string = string.Join(",", ipNumerizerByIp2Vec.W2.ToColumnMajorArray().Select(x => x.ToString("R"))); var words = new string[ipNumerizerByIp2Vec.Index2Word.Count]; for (int i = 0; i < ipNumerizerByIp2Vec.Index2Word.Count; i++) { words[i] = ipNumerizerByIp2Vec.Index2Word[i]; } var wordsarray = string.Join(",", words); var frequencies = string.Join(",", ipNumerizerByIp2Vec.Frequency); return(new ModelSaver { W1String = w1string, W2String = w2string, Indexer = wordsarray, X = ipNumerizerByIp2Vec.W1.RowCount, Y = ipNumerizerByIp2Vec.W1.ColumnCount, Frequencies = frequencies, }); }