diff options
author | Patrick Simianer <p@simianer.de> | 2014-10-13 19:03:48 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-10-13 19:03:48 +0100 |
commit | cb9fb7088dde35881516c088db402abe747d49fa (patch) | |
tree | a91e4935a7941f1b261f76d88ab41fa3078a1891 /klm/lm/neural/wordvecs.hh | |
parent | 0a00e57e921c8eca8e02364db7d2e6607bfdcebc (diff) | |
parent | b1ed81ef3216b212295afa76c5d20a56fb647204 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'klm/lm/neural/wordvecs.hh')
-rw-r--r-- | klm/lm/neural/wordvecs.hh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/klm/lm/neural/wordvecs.hh b/klm/lm/neural/wordvecs.hh new file mode 100644 index 00000000..921a2b22 --- /dev/null +++ b/klm/lm/neural/wordvecs.hh @@ -0,0 +1,38 @@ +#ifndef LM_NEURAL_WORDVECS_H +#define LM_NEURAL_WORDVECS_H + +#include "util/scoped.hh" +#include "lm/vocab.hh" + +#include <Eigen/Dense> + +namespace util { class FilePiece; } + +namespace lm { +namespace neural { + +class WordVecs { + public: + // Columns of the matrix are word vectors. The column index is the word. + typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor> Storage; + + /* The file should begin with a line stating the number of word vectors and + * the length of the vectors. Then it's followed by lines containing a + * word followed by floating-point values. + */ + explicit WordVecs(util::FilePiece &in); + + const Storage &Vectors() const { return vecs_; } + + WordIndex Index(StringPiece str) const { return vocab_.Index(str); } + + private: + util::scoped_malloc vocab_backing_; + ngram::ProbingVocabulary vocab_; + + Storage vecs_; +}; + +}} // namespaces + +#endif // LM_NEURAL_WORDVECS_H |