Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. class Embedder:
  2.  
  3. def __init__(self, embedding_type):
  4.  
  5. if embedding_type == 'USE':
  6. self._embed = USEEncoder()
  7. #elif embedding_type == 'bert base uncased'
  8. #elif embedding_type == 'bert base uncased -1 -12'
  9. else:
  10. raise NotImplementedError
  11.  
  12. def run(self, sentences, batch=None):
  13. if not batch:
  14. return self._embedd.run(sentences)
  15.  
  16. encoded_list = list()
  17. for text_batch in self._batch(sentences, batch):
  18. encoded_list.append(self._embed.run(text_batch))
  19.  
  20. return np.array(list(itertools.chain(*encoded_list)))
  21.  
  22. def _batch(self, iterable, n):
  23. l = len(iterable)
  24. for ndx in range(0, l, n):
  25. yield iterable[ndx:min(ndx + n, l)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement