def extract_embeddings(embedding_path, word_dict):

    with open(embedding_path) as fid:
        for i, line in enumerate(fid.readlines()):
            # Initialize
            if i == 0:
                 N    = len(line.split()[1:])     
                 E    = np.random.uniform(size=(N, len(word_dict)))
                 n    = 0
            word = line.split()[0].lower() 
            if word[0].upper() + word[1:] in word_dict:
                idx        = word_dict[word[0].upper() + word[1:]]
                E[:, idx]  = np.array(line.strip().split()[1:]).astype(float)
                n         += 1
            elif word in word_dict:
                idx        = word_dict[word]
                E[:, idx]  = np.array(line.strip().split()[1:]).astype(float)
                n         += 1
            print "\rGetting embeddings for the vocabulary %d/%d" % (n, len(word_dict)),    
    OOV_perc =  (1-n*1./len(word_dict))*100        
    print "\n%2.1f%% OOV, missing embeddings set to random" % OOV_perc
    return E
Given embeddings in text form and a word dictionary construct embedding
dataset/ETHPy150Open LxMLS/lxmls-toolkit/lxmls/deep_learning/rnn.py/extract_embeddings