summaryrefslogtreecommitdiff
path: root/klm/lm/neural/wordvecs.cc
diff options
context:
space:
mode:
authorarmatthews <armatthe@cmu.edu>2014-10-13 14:59:23 -0400
committerarmatthews <armatthe@cmu.edu>2014-10-13 14:59:23 -0400
commitb26cda84e05d4523eee069234a975a0153bf8608 (patch)
tree61c9da4f8dd6070f27c8e81812a76fc0a8cf2d8d /klm/lm/neural/wordvecs.cc
parentcd7bc67f475fdfd07fba003ac4cca40e83944740 (diff)
parentb1ed81ef3216b212295afa76c5d20a56fb647204 (diff)
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'klm/lm/neural/wordvecs.cc')
-rw-r--r--klm/lm/neural/wordvecs.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/klm/lm/neural/wordvecs.cc b/klm/lm/neural/wordvecs.cc
new file mode 100644
index 00000000..09bb4260
--- /dev/null
+++ b/klm/lm/neural/wordvecs.cc
@@ -0,0 +1,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