Question: Exercise 0 3 Instructions: Implement the train _ model below to train the neural network above. Here is a list of things you should do:

Exercise 03
Instructions: Implement the train_model below to train the neural network above. Here is a list of things you should do:
Compile the model. Here you will need to pass in:
loss=TripletLoss
optimizer=Adam() with learning rate lr
Call the fit method. You should pass:
train_dataset
epochs
validation_data
You will be using your triplet loss function with Adam optimizer. Also, note that you are not explicitly defining the batch size, because it will be already determined by the Dataset.
This function will return the trained model
# GRADED FUNCTION: train_model
def train_model(Siamese, TripletLoss, text_vectorizer, train_dataset, val_dataset, d_feature=128, lr=0.01, train_steps=5):
"""Training the Siamese Model
Args:
Siamese (function): Function that returns the Siamese model.
TripletLoss (function): Function that defines the TripletLoss loss function.
text_vectorizer: trained instance of `TextVecotrization`
train_dataset (tf.data.Dataset): Training dataset
val_dataset (tf.data.Dataset): Validation dataset
d_feature (int, optional)= size of the encoding. Defaults to 128.
lr (float, optional): learning rate for optimizer. Defaults to 0.01
train_steps (int): number of epochs
Returns:
tf.keras.Model
"""
## START CODE HERE ###
# Instantiate your Siamese model
model = Siamese(None,
vocab_size = None, #set vocab_size accordingly to the size of your vocabulary
d_feature = None)
# Compile the model
model.compile(loss=None,
optimizer = None
)
# Train the model
model.fit(None,
epochs = None,
validation_data = None,
)
### END CODE HERE ###
return model

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!