Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Exercise 0 1 Instructions: Implement the Siamese function below. You should be using all the functions explained below. To implement this model, you will be
Exercise
Instructions: Implement the Siamese function below. You should be using all the functions explained below.
To implement this model, you will be using TensorFlow. Concretely, you will be using the following functions.
tfkeras.models.Sequential: groups a linear stack of layers into a tfkeras.Model.
You can pass in the layers as arguments to Serial, separated by commas, or simply instantiate the Sequentialmodel and use the add method to add layers.
For example: SequentialEmbeddings AveragePoolingD Dense Softmax or
model Sequential model.addEmbeddings model.addAveragePoolingD model.addDense model.addSoftmax
tfkeras.layers.Embedding : Maps positive integers into vectors of fixed size. It will have shape vocabulary length X dimension of output vectors The dimension of output vectors called dfeaturein the model is the number of elements in the word embedding.
Embeddinginputdim, outputdim
inputdim is the number of unique words in the given vocabulary.
outputdim is the number of elements in the word embedding some choices for a word embedding size range from to for example
tfkeras.layers.LSTM : The LSTM layer. The number of units should be specified and should match the number of elements in the word embedding.
LSTMunits Builds an LSTM layer of nunits.
tfkeras.layers.GlobalAveragePoolingD : Computes global average pooling, which essentially takes the mean across a desired axis. GlobalAveragePoolingD uses one tensor axis to form groups of values and replaces each group with the mean value of that group.
GlobalAveragePoolingD takes the mean.
tfkeras.layers.Lambda: Layer with no weights that applies the function f which should be specified using a lambda syntax. You will use this layer to apply normalization with the function
tfmath.lnormalizex
tfkeras.layers.Input: it is used to instantiate a Keras tensor. Remember to set correctly the dimension and type of the input, which are batches of questions. For this, keep in mind that each question is a single string.
Inputinputshape,dtypeNone,...
inputshape: Shape tuple not including the batch axis
dtype: optional data type of the input
tfkeras.layers.Concatenate: Layer that concatenates a list of inputs. This layer will concatenate the normalized outputs of each LSTM into a single output for the model.
Concatenate
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started