Answered step by step
Verified Expert Solution
Link Copied!

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 01
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.
tf.keras.models.Sequential: groups a linear stack of layers into a tf.keras.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: Sequential(Embeddings(...), AveragePooling1D(...), Dense(...), Softmax(...)) or
model = Sequential() model.add(Embeddings(...)) model.add(AveragePooling1D(...)) model.add(Dense(...)) model.add(Softmax(...))
tf.keras.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 d_featurein the model) is the number of elements in the word embedding.
Embedding(input_dim, output_dim).
input_dim is the number of unique words in the given vocabulary.
output_dim is the number of elements in the word embedding (some choices for a word embedding size range from 150 to 300, for example).
tf.keras.layers.LSTM : The LSTM layer. The number of units should be specified and should match the number of elements in the word embedding.
LSTM(units) Builds an LSTM layer of n_units.
tf.keras.layers.GlobalAveragePooling1D : Computes global average pooling, which essentially takes the mean across a desired axis. GlobalAveragePooling1D uses one tensor axis to form groups of values and replaces each group with the mean value of that group.
GlobalAveragePooling1D() takes the mean.
tf.keras.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.l2_normalize(x)
tf.keras.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.
Input(input_shape,dtype=None,...)
input_shape: Shape tuple (not including the batch axis)
dtype: (optional) data type of the input
tf.keras.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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions