def _get_embed_device(vocab_size):
gpus=_get_available_gpus()
if not gpus or vocab_size > VOCAB_SIZE_THRESHOLD_CPU:
return "/cpu:0"
return "/gpu:0"
def transform_sentence(sentence, ws, max_len=None, add_end=False):
encoded=ws.transform(
sentence,
max_len=max_len if max_len is not None else len(sentence))
encoded_len= len(sentence)+(1 if add_end else 0)
if encoded_len>len(encoded):
encoded_len=len(encoded)
return encoded, encoded_len
if __name__=='__main__':
size=30000
print(_get_embed_device(size))