Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Embedder:
- def __init__(self, embedding_type):
- if embedding_type == 'USE':
- self._embed = USEEncoder()
- #elif embedding_type == 'bert base uncased'
- #elif embedding_type == 'bert base uncased -1 -12'
- else:
- raise NotImplementedError
- def run(self, sentences, batch=None):
- if not batch:
- return self._embedd.run(sentences)
- encoded_list = list()
- for text_batch in self._batch(sentences, batch):
- encoded_list.append(self._embed.run(text_batch))
- return np.array(list(itertools.chain(*encoded_list)))
- def _batch(self, iterable, n):
- l = len(iterable)
- for ndx in range(0, l, n):
- yield iterable[ndx:min(ndx + n, l)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement