Skip to content

Instantly share code, notes, and snippets.

@oborchers
Created June 8, 2019 11:06
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/5ae2e931e7ab69b0657e635ba38f3017 to your computer and use it in GitHub Desktop.
Save oborchers/5ae2e931e7ab69b0657e635ba38f3017 to your computer and use it in GitHub Desktop.
# Adapted
for i in xrange(len(sentences)):
if len(sentences[i]) > 0:
# Define a memory view of the sentence indices
sentence_view = sentences[i]
sentence_len = len(sentences[i])
# Pass all arguments to the C-Loop
sif_embeddings_cloop(size, sentence_view, sentence_len, i, vectors, sv)
return output
cdef void sif_embeddings_cloop(int size, int[:] sentence_view, int sentence_len,
int sentence_idx, float[:,:] vectors,
float[:,:] summary_vectors) nogil:
cdef int i,d, word_index, count = 0
cdef float inv = 1.
# Iterate the sentence
for i in xrange(sentence_len):
word_index = sentence_view[i]
count += 1
for d in xrange(size):
summary_vectors[sentence_idx, d] += vectors[word_index, d]
inv = (1./ <float>count)
for d in xrange(size):
summary_vectors[sentence_idx, d] *= inv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment