'Initializes the vectors from a text vocabulary and binary data.'

def __init__(self, vocab_filename, rows_filename, cols_filename=None):

    with open(vocab_filename, 'r') as lines:
        self.vocab = [line.split()[0] for line in lines]
        self.word_to_idx = {word: idx for (idx, word) in enumerate(self.vocab)}
    n = len(self.vocab)
    with open(rows_filename, 'r') as rows_fh:
        rows_fh.seek(0, os.SEEK_END)
        size = rows_fh.tell()
        if ((size % (4 * n)) != 0):
            raise IOError(('unexpected    file    size    for    binary    vector    file    %s' % rows_filename))
        dim = (size / (4 * n))
        rows_mm = mmap.mmap(rows_fh.fileno(), 0, prot=mmap.PROT_READ)
        rows = np.matrix(np.frombuffer(rows_mm, dtype=np.float32).reshape(n, dim))
        if cols_filename:
            with open(cols_filename, 'r') as cols_fh:
                cols_mm = mmap.mmap(cols_fh.fileno(), 0, prot=mmap.PROT_READ)
                cols_fh.seek(0, os.SEEK_END)
                if (cols_fh.tell() != size):
                    raise IOError('row    and    column    vector    files    have    different    sizes')
                cols = np.matrix(np.frombuffer(cols_mm, dtype=np.float32).reshape(n, dim))
                rows += cols
                cols_mm.close()
        self.vecs = (rows / np.linalg.norm(rows, axis=1).reshape(n, 1))
        rows_mm.close()
