private void WriteWordVector(WordVector wv) { Writer.Write(wv.Word); Writer.Write(' '); Writer.Write(string.Join(" ", wv.Vector)); Writer.Write('\n'); }
private void WriteWordVector(WordVector wv) { WriteString(wv.Word); WriteString(" "); foreach (var f in wv.Vector) { Writer.Write(f); } }
public WordModel Open() { using (var reader = new StreamReader(stream, Encoding.UTF8, true, 4 * 1024)) { var header = ReadHeader(reader); var words = header[0]; var size = header[1]; var vectors = new List <WordVector>(); WordVector vector = null; while (null != (vector = ReadVector(reader))) { vectors.Add(vector); } return(new WordModel(ApplicationLogging.CreateLogger <WordModel>(), words == 0 ? vectors.Count : words, size == 0 ? (int)stream.Length : size, vectors)); } }
private WordVector ReadVector(BinaryReader binaryReader, int size) { string word = ReadString(binaryReader); if (string.IsNullOrEmpty(word)) { return null; } float[] vector = new float[size]; for (int j = 0; j < size; j++) { vector[j] = binaryReader.ReadSingle(); } WordVector result = new WordVector(word, vector); if (LineBreaks) { binaryReader.ReadByte(); // consume line break } return result; }
public static double Distance(this float[] word1, WordVector word2) { return(word1.Distance(word2.Vector)); }
public static float[] Subtract(this float[] word1, WordVector word2) { return(word1.Subtract(word2.Vector)); }
public static float[] Add(this float[] word1, WordVector word2) { return(word1.Add(word2.Vector)); }
protected void AddVector(WordVector vector) { vectorsTable.Add(vector.Word, vector); }