Skip to content

Instantly share code, notes, and snippets.

@oborchers
Created June 8, 2019 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oborchers/7d6dfd91f995e44fd37cdb0e8a6446b7 to your computer and use it in GitHub Desktop.
Save oborchers/7d6dfd91f995e44fd37cdb0e8a6446b7 to your computer and use it in GitHub Desktop.
def sif_embeddings(sentences, model):
""" Uses a pre-computed list of indices and skips the use of strings alltogether
"""
vectors = model.wv.sif_vectors
output = np.zeros(shape=(len(sentences), model.vector_size), dtype=REAL)
for i,s in enumerate(sentences):
output[i] = np.sum(vectors[s], axis=0) * ( (1/len(s)) if len(s)>0 else 1)
return output.astype(REAL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment