Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[ 1 0 + 1 5 + 1 0 = 3 5 points, implementation ] Consider the following RNN models to perform text classification over
points, implementation Consider the following RNN models to perform text classification over the dataset
provided in hw q text data train.csv see hw q helper.py for sample implementations of these six models
GRU: Single GRU layer and units in the layer.
GRU stacked: Two GRU layers, first one with units, and second one with units in the layers.
GRU stacked bidirectional: Same as # except that layers are bidirectional.
LSTM: Single LSTM layer and units in the layer.
LSTM stacked: Two LSTM layers, first one with units, and second one with units in the layers.
LSTM stacked bidirectional: Same as # except that layers are bidirectional.
For all the models, the preceding Embedding layer should have vocabulary size input dim of with dimensional
embeddings. Set your optimizer to adam, loss to categorical crossentropy and metrics to accuracy, and train with
batch size Set the validation split to wherever needed.
a Train any given model from the above list of models and identify the best number of epochs that minimizes the
validation loss.
Sample function call with required arguments and the output is provided below.
n u m e p o c h l i m i t
b e s t e p o c h m o d e l g e t b e s t n u m e p o c h s h w q t e x t d a t a t r a i n c s v GRU stacked
n u m e p o c h l i m i t g m a x w o r d s g m a x t e x t l e n
# g m a x w o r d s and g m a x t e x t l e n must s p e c i f y t h e d i m e n s i o n s o f t h e Embedding l a y e r
# b e s t e p o c h m o d e l would be b e t w e e n and n u m e p o c h l i m i t
b Compare the performances of the given list of models by evaluating them over the test set
hw q text data test.csv Sample function call with required arguments and the output is provided below.
Figure shows the format of the output dataframe ie df ress The same set of performance metrics in this figure
should be in the generated data frame df ress.
g t r a i n d a t a f i l e h w q t e x t d a t a t r a i n c s v
g t e s t d a t a f i l e h w q t e x t d a t a t e s t c s v
g n u m e p o c h s
l i s t m o d e l s GRU GRU stacked G R U s t a c k e d b i d i r e c t i o n a l LSTM LSTM stacked
L S T M s t a c k e d b i d i r e c t i o n a l
d f r e s s r u n g i v e n D N N s g t r a i n d a t a f i l e g t e s t d a t a f i l e g l i s t m o d e l s g n u m e p o c h s
g m a x w o r d s g m a x t e x t l e n
Figure : Sample data frame generated by run given DNNs function
c Investigate the effectiveness of the regularization methods, namely, weight regularization and dropout over the model #
LSTM stacked bidirectional You are required to implement a function named run regularization comparison
which generates a plot saved as a file with name text clf regularization.pdf which should look similar to Figure
Sample function call with required arguments and the output is provided below.
# w e i g h t r e g u l a r i z a t i o n c o d e s a m p l e
GRU k e r n e l r e g u l a r i z e r r e g u l a r i z e r s l
# d r o p o u t c o d e s a m p l e
l a y e r s D r o p o u t
max num epochs
t r a i n d a t a f i l e h w q t e x t d a t a t r a i n c s v
a v g l o s s o r i g a v g l o s s w r e g a v g l o s s d r o p o u t r u n r e g u l a r i z a t i o n c o m p a r i s o n t r a i n d a t a f i l e
max num epochs
# s a m p l e o u t p u t a v g l o s s o r i g : wreg : d r o p o u t :
# c o d e s h o u l d a u t o m a t i c a l l y g e n e r a t e t e x t c l f r e g u l a r i z a t i o n p d f
Epochs
Loss
validation losses
Validation loss original
Validation loss regularized
Validation loss dropout
Figure : Sample regularization plots
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