'Determining the maximum length of the sequence and determining the attention mask in the Elmo model
I built this code to represent text using the Elmo model:
import tensorflow_hub as hub
import tensorflow as tf
class ELMoModelFeatures():
def __init__(self):
self.model = hub.load("https://tfhub.dev/google/elmo/3")
def elmo_vectors(self,sentence):
embeddings = self.model.signatures["default"](tf.constant(sentence))["elmo"]
token_embeddings = tf.reshape(embeddings,embeddings[0].shape)
return token_embeddings
I want to develop it so that I pass it a batch of texts with a specified length (padding of shorter texts), but I don't know how to specify the maximum length nor how to define an attention mask in this case?
Any help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
