blob: 09bb42609e69795e1e90f280fea76a578a663070 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "lm/neural/wordvecs.hh"
#include "util/file_piece.hh"
namespace lm { namespace neural {
WordVecs::WordVecs(util::FilePiece &f) {
const unsigned long lines = f.ReadULong();
const std::size_t vocab_mem = ngram::ProbingVocabulary::Size(lines, 1.5);
vocab_backing_.reset(util::CallocOrThrow(vocab_mem));
vocab_.SetupMemory(vocab_backing_.get(), vocab_mem);
const unsigned long width = f.ReadULong();
vecs_.resize(width, lines);
for (unsigned long i = 0; i < lines; ++i) {
WordIndex column = vocab_.Insert(f.ReadDelimited());
for (unsigned int row = 0; row < width; ++row) {
vecs_(row,column) = f.ReadFloat();
}
}
vocab_.FinishedLoading();
}
}} // namespaces
|