Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main/java/com/medallia/word2vec/Word2VecModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,24 @@ public static Word2VecModel fromBinFile(File file, ByteOrder byteOrder, Profilin

long lastLogMessage = System.currentTimeMillis();
final float[] floats = new float[layerSize];

ByteBuffer bb = ByteBuffer.allocate(1000);
byte b;
for (int lineno = 0; lineno < vocabSize; lineno++) {
// read vocab
sb.setLength(0);
c = (char) buffer.get();
bb.rewind();
b = buffer.get();
c = (char)b;
while (c != ' ') {
// ignore newlines in front of words (some binary files have newline,
// some don't)
if (c != '\n') {
sb.append(c);
bb.put(b);
}
c = (char) buffer.get();
b = buffer.get();
c = (char)b;
}
vocabs.add(sb.toString());
vocabs.add(new String(bb.array(), 0, bb.position(), Charset.forName("utf-8")));

// read vector
final FloatBuffer floatBuffer = buffer.asFloatBuffer();
Expand Down