[Python] ELMo embedding not working - causing 0 params in the model summary

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am attempting to create a text classification CNN model with ELMo embedding however the model summary is showing 0 params. It seems the ELMo embedding is not applying properly but not sure on the issue.

    #setting up parameters
    max_length = 200
    no_of_filters = 250
    kernel_size = 3
    hidden_dims = 250
    batch_size = 32
    epochs = 2
    early_stopping = EarlyStopping(monitor ='val_loss', patience = 10)

    #obtaining elmo emmbedding
    elmo = hub.KerasLayer("https://tfhub.dev/google/elmo/2",
    trainable=True,
    name = 'elmo_embedding',
    #input_shape=[],
    dtype=(tf.string))
    model = Sequential()

    model.add(Lambda(lambda x: elmo(x), input_shape = [], dtype = tf.string))

    model.add(Conv1D(no_of_filters, kernel_size, activation ='relu', input_shape =
    (max_length, 1024)))

    model.add(GlobalMaxPooling1D())

    model.add(Dense(hidden_dims, activation = 'relu'))

    model.add(Dense(1, activation = 'sigmoid'))

    model.summary()


    The model is then outputting a model summary that shows the model isn't working. I've tried a few different iterations of the code but seems to be the same outcome. Would the embedding need to be applied to the data before being fed through the model or is it possible to do so within the model itself?

    Continue reading...

Compartilhe esta Página