IniziaInizia gratis

Understanding the RepeatVector layer

You will now explore how the RepeatVector layer works. The RepeatVector layer adds an extra dimension to your dataset. For example if you have an input of shape (batch size, input size) and you want to feed that to a GRU layer, you can use a RepeatVector layer to convert the input to a tensor with shape (batch size, sequence length, input size).

In this exercise, you will define a model that repeats a given input a fixed number of times. You will then feed a numpy array to the model and investigate how the model changes the output.

Questo esercizio fa parte del corso

Machine Translation with Keras

Visualizza il corso

Istruzioni dell'esercizio

  • Define a RepeatVector layer that repeats the input 6 times.
  • Define a Model that takes the input layer in and produces the repeat vector output.
  • Define a numpy array object that has data [[0,1], [2,3]].
  • Predict the output of the model by feeding x as an input.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

from tensorflow.keras.layers import Input, RepeatVector
from tensorflow.keras.models import Model
import numpy as np

inp = Input(shape=(2,))
# Define a RepeatVector that repeats the input 6 times
rep = ____(____)(inp)
# Define a model
model = ____(____=____, ____=____)
# Define input x
x = ____.____([____,____])
# Get model prediction y
y = ____.____(____)
print('x.shape = ',x.shape,'\ny.shape = ',y.shape)
Modifica ed esegui il codice