BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Machine Translation with Keras

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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)
Kodu Düzenle ve Çalıştır