(path)
return embeddings, word2idx
Loads pre-trained embeddings from the specified path.

    @return (embeddings as an numpy array, word to index dictionary)
Loads pre-trained embeddings from the specified path.
Loads pre - trained embeddings from the specified path .
def load_word_embeddings(path):
    """
    Loads pre-trained embeddings from the specified path.

    @return (embeddings as an numpy array, word to index dictionary)
    """
    word2idx = defaultdict(lambda: 1)  # Maps a word to the index in the embeddings matrix
    word2idx[all_zeroes] = 0
    word2idx[unknown_el] = 1
    embeddings = []

    with codecs.open(path, 'r', encoding='utf-8') as fIn:
        idx = 2
        for line in fIn:
            split = line.strip().split(' ')
            embeddings.append([float(num) for num in split[1:]])
            word2idx[split[0]] = idx
            idx += 1

    embedding_size = len(embeddings[0])
    embeddings = np.asarray(embeddings, dtype='float32')

    unknown_emb = np.average(embeddings[:10000], axis=0)
    embeddings = np.concatenate((np.zeros((1, embedding_size)),
                                 np.expand_dims(unknown_emb, 0),
                                 embeddings), axis=0)
    logger.debug("Loaded: {}".format(embeddings.shape))

    return embeddings, word2idx
def load_word_embeddings ( path ) : word2idx = defaultdict ( lambda : 1 ) # Maps a word to the index in the embeddings matrix word2idx [ all_zeroes ] = 0 word2idx [ unknown_el ] = 1 embeddings = [ ] with codecs . open ( path , 'r' , encoding = 'utf-8' ) as fIn : idx = 2 for line in fIn : split = line . strip ( ) . split ( ' ' ) embeddings . append ( [ float ( num ) for num in split [ 1 : ] ] ) word2idx [ split [ 0 ] ] = idx idx += 1 embedding_size = len ( embeddings [ 0 ] ) embeddings = np . asarray ( embeddings , dtype = 'float32' ) unknown_emb = np . average ( embeddings [ : 10000 ] , axis = 0 ) embeddings = np . concatenate ( ( np . zeros ( ( 1 , embedding_size ) ) , np . expand_dims ( unknown_emb , 0 ) , embeddings ) , axis = 0 ) logger . debug ( "Loaded: {}" . format ( embeddings . shape ) ) return embeddings , word2idx