keras-exercises/exercise-3/solution/keras_embeddings_w2v_glove.py
def load_glove(GLOVE_DIR, dim="100d"):
    """ returns dict mapping word -> coeffs in 100d"""
    print('Indexing word vectors.')

    embeddings_index = {}
    with open(os.path.join(GLOVE_DIR, f'glove.6B.{dim}.txt')) as f:
        for line in f:
            values = line.split()
            word = values[0]
            coefs = np.asarray(values[1:], dtype='float32')
            embeddings_index[word] = coefs

    print('Found %s word vectors.' % len(embeddings_index))
    return embeddings_index
 returns dict mapping word -> coeffs in 100d
returns dict mapping word -> coeffs in 100d
returns dict mapping word - > coeffs in 100d
def load_glove(GLOVE_DIR, dim="100d"):
    print('Indexing word vectors.')
    embeddings_index = {}
    with open(os.path.join(GLOVE_DIR, f'glove.6B.{dim}.txt')) as f:
        for line in f:
            values = line.split()
            word = values[0]
            coefs = np.asarray(values[1:], dtype='float32')
            embeddings_index[word] = coefs
    print('Found %s word vectors.' % len(embeddings_index))
    return embeddings_index
def load_glove ( GLOVE_DIR , dim = "100d" ) : print ( 'Indexing word vectors.' ) embeddings_index = { } with open ( os . path . join ( GLOVE_DIR , f'glove.6B.{dim}.txt' ) ) as f : for line in f : values = line . split ( ) word = values [ 0 ] coefs = np . asarray ( values [ 1 : ] , dtype = 'float32' ) embeddings_index [ word ] = coefs print ( 'Found %s word vectors.' % len ( embeddings_index ) ) return embeddings_index
returns dict mapping word -> coeffs in 100d
returns dict mapping word - > coeffs in 100d
""" returns dict mapping word -> coeffs in 100d"""
GLOVE_DIR
dim