private static void SuDeserializer(ModelSaver data, NeVeModel model) { model.MainVectors = data.MainVectorString.Select(x => Vector <double> .Build.Dense(Array.ConvertAll(x.Split(','), double.Parse))).ToList(); model.ContextVectors = data.ContextVectorString.Select(x => Vector <double> .Build.Dense(Array.ConvertAll(x.Split(','), double.Parse))).ToList(); var index = 0; model.Word2Index = data.Indexer.Split(',').ToDictionary(x => x, x => index++); }
public static ModelSaver PreSerializer(NeVeModel model) { var mainVectorString = model.MainVectors.Select(x => string.Join(",", x.Select(y => y.ToString("R")))).ToList(); var contextVectorString = model.ContextVectors.Select(x => string.Join(",", x.Select(y => y.ToString("R")))).ToList(); var words = string.Join(",", model.Word2Index.OrderBy(x => x.Value).Select(x => x.Key)); return(new ModelSaver { Indexer = words, MainVectorString = mainVectorString, ContextVectorString = contextVectorString }); }