in src/utils.py [0:0]
def bow(sentences, word_vec, normalize=False):
"""
Get sentence representations using average bag-of-words.
"""
embeddings = []
for sent in sentences:
sentvec = [word_vec[w] for w in sent if w in word_vec]
if normalize:
sentvec = [v / np.linalg.norm(v) for v in sentvec]
if len(sentvec) == 0:
sentvec = [word_vec[list(word_vec.keys())[0]]]
embeddings.append(np.mean(sentvec, axis=0))
return np.vstack(embeddings)