doc
This commit is contained in:
parent
277332f8f1
commit
c1d07398c8
7 changed files with 77 additions and 62 deletions
|
|
@ -56,9 +56,9 @@ Initial approach of finding a solution to product categorization is to analyze a
|
||||||
|
|
||||||
Machine learning model to text classification for predicting the product taxonomy is a methodology in which a lot of research have been conducted. \cite{AliCevahir.} implements classification model at every level using the \acl*{KNN} classifier. Like wise \parencite{Gupta.20062016} proposes a distributional semantics representation for predicting the product taxonomies. Some classifying methods are supervised classification, decision trees, naive Bayes classifier and max entropy classifiers \parencite{BirdKleinLoper09}
|
Machine learning model to text classification for predicting the product taxonomy is a methodology in which a lot of research have been conducted. \cite{AliCevahir.} implements classification model at every level using the \acl*{KNN} classifier. Like wise \parencite{Gupta.20062016} proposes a distributional semantics representation for predicting the product taxonomies. Some classifying methods are supervised classification, decision trees, naive Bayes classifier and max entropy classifiers \parencite{BirdKleinLoper09}
|
||||||
|
|
||||||
\subsection{Do the math.}
|
\subsection{Understanding Mathematics of Neural Networks.}
|
||||||
|
|
||||||
In this paper, author researches on the relevance of the mathematical concept with respect to the machine learning process. Understanding the math behind reducing the loss for prediction enables to completely understand the algorithms. Especially the training algorithm applies the activation functions. Author describes the theoretical knowledge with reasoning to apply these activation functions.
|
In this paper, author researches on the relevance of the mathematical concept with respect to the machine learning process. Understanding the math behind reducing the loss for prediction enables to completely understand the algorithms. Especially the training algorithm applies the activation functions. Author describes the theoretical knowledge with reasoning to apply these activation functions. Understanding the mathematical foundations on which the neural networks and classification model works enables to reverse engineer the algorithm of machine learning model.
|
||||||
|
|
||||||
\clearpage
|
\clearpage
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,16 @@ In figure \ref{fig:sample-product-taxonomy}, is a sample of product taxonomy rep
|
||||||
\item The node ``Break system'' could also be a part of node ``Sparepart'' and yet the taxonomy will remain well-defined as it is a general term.
|
\item The node ``Break system'' could also be a part of node ``Sparepart'' and yet the taxonomy will remain well-defined as it is a general term.
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
|
\clearpage
|
||||||
|
|
||||||
\item How important is a well-defined product taxonomy in e-commerce \parencite{JessicaHoward.}?
|
\item How important is a well-defined product taxonomy in e-commerce \parencite{JessicaHoward.}?
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item \textbf{Simplify product searches}:\\ Customer filters the categories to narrow down the search result, enabling them to find the required product in the fewest possible clicks. This improves customer experience.
|
\item \textbf{Simplify product searches}:\\ Customer filters the categories to narrow down the search result, enabling them to find the required product in the fewest possible clicks. This improves customer experience.
|
||||||
\item \textbf{Better product recommendation}:\\ Product recommendation system analyze the customer behavior and returns the related products. Customer behavior such as to know which category the customer clicked on but did not purchase the product yet, enabling recommendation of most relevant products.
|
\item \textbf{Better product recommendation}:\\ Product recommendation system analyze the customer behavior and returns the related products. Customer behavior such as to know which category the customer clicked on but did not purchase the product yet, enabling recommendation of most relevant products.
|
||||||
\item \textbf{Improves search engine optimization (SEO)}:\\ Organizing the products into structured taxonomy, businesses can ensure that their products are found easily. It also helps business drive more organic traffic.
|
\item \textbf{Improves search engine optimization (SEO)}:\\ Organizing the products into structured taxonomy, businesses can ensure that their products are found easily. It also helps business drive more organic traffic.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\item What are the challenges in defining the product taxonomy? \parencite{JessicaHoward.}
|
\item What are the challenges in defining the product taxonomy?
|
||||||
|
|
||||||
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item \textbf{Scalability}:\\ The taxonomy requires to be able to update as the number of products in a business grows.
|
\item \textbf{Scalability}:\\ The taxonomy requires to be able to update as the number of products in a business grows.
|
||||||
|
|
@ -68,9 +70,6 @@ In figure \ref{fig:sample-product-taxonomy}, is a sample of product taxonomy rep
|
||||||
|
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\section{Product Taxonomy Prediction Approaches}
|
\section{Product Taxonomy Prediction Approaches}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -95,12 +94,13 @@ A lot of research have been conducted on methodology for predicting taxonomy. Pr
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
\item Max Entropy
|
\item Max Entropy
|
||||||
|
|
||||||
Like the naive Bayes model, the Maximum Entropy classifier calculates the likelihood of each label for a given input.
|
Like the naive Bayes model, the Maximum Entropy classifier calculates the likelihood of each label for a given input.
|
||||||
However, Maximum Entropy classifier model leaves it up to the user to decide what combinations of labels and features should receive their own parameters.
|
However, Maximum Entropy classifier model leaves it up to the user to decide what combinations of labels and features should receive their own parameters.
|
||||||
|
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
|
\clearpage
|
||||||
|
|
||||||
\section{Supervised Learning}
|
\section{Supervised Learning}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ If the machine always returns the value 0, what is the loss?
|
||||||
Lower loss indicate the network is trained well. The goal of training is minimizing the loss.
|
Lower loss indicate the network is trained well. The goal of training is minimizing the loss.
|
||||||
|
|
||||||
|
|
||||||
\subsection*{Minimizing the Loss}
|
\subsection*{Minimizing the Loss} \label{sec:minloss}
|
||||||
|
|
||||||
From equation \ref{eq:single_n} it is known that tweaking weights ($w$) and biases ($b$) changes the output value. How do we change the networks weights and biases such that the loss is decreased at each time step? Answer to this question is partial derivatives. Partial derivatives is a method of small change in one of the variable of a multivariable function leading to a small change in the output of the function. For example, making a small change in variable $w_1$ keeping all other variables constant leading to a small change in Loss $L$ can be represented by equation \ref{eq:loss_partial}.
|
From equation \ref{eq:single_n} it is known that tweaking weights ($w$) and biases ($b$) changes the output value. How do we change the networks weights and biases such that the loss is decreased at each time step? Answer to this question is partial derivatives. Partial derivatives is a method of small change in one of the variable of a multivariable function leading to a small change in the output of the function. For example, making a small change in variable $w_1$ keeping all other variables constant leading to a small change in Loss $L$ can be represented by equation \ref{eq:loss_partial}.
|
||||||
|
|
||||||
|
|
@ -281,9 +281,9 @@ Substituting \(a = \exp(x_i)\) and \(b = \sum_{j=1}^n \exp(x_j)\) in equation \e
|
||||||
\item Logarithms and Multiplication: Logarithms convert multiplication to addition. Probabilities of independent events, represented as \(P(A \cap B \cap C \cap \ldots)\). Logarithm of the product of these probabilities simplifies the computation to a sum.
|
\item Logarithms and Multiplication: Logarithms convert multiplication to addition. Probabilities of independent events, represented as \(P(A \cap B \cap C \cap \ldots)\). Logarithm of the product of these probabilities simplifies the computation to a sum.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
|
|
||||||
\section{ \acs*{RNN} - Forward and Backward Propagation}
|
\section{ \acs*{RNN} - Forward and Backward Propagation} \label{sec:math-rnn}
|
||||||
|
|
||||||
When a feedforward neural network are extended to include feedback connections, they are called \acfp{RNN} \parencite[Chapter 6, Page 164]{Goodfellow-et-al-2016}. \acfp{RNN} \parencite{Rumelhart.1986} is best suited for machine learning problems that involve sequential data and use patterns to predict the output. A recurrent neural network is specialized for processing sequence of values $ x^{(1)},\ldots,x^{(t)}$.
|
When a feedforward neural network are extended to include feedback connections, they are called \acfp{RNN} \parencite[Chapter 6, Page 164]{Goodfellow-et-al-2016}. \acfp{RNN} is best suited for machine learning problems that involve sequential data and use patterns to predict the output. A recurrent neural network is specialized for processing sequence of values $ x^{(1)},\ldots,x^{(t)}$.
|
||||||
|
|
||||||
\begin{figure}[H]
|
\begin{figure}[H]
|
||||||
\centering
|
\centering
|
||||||
|
|
@ -301,7 +301,7 @@ Equation \ref{eq:rnn} depicts the common representation of RNN to define the hid
|
||||||
h^{(t)} = f(h^{(t-1)}, x^{(t)}; \theta) \label{eq:rnn}
|
h^{(t)} = f(h^{(t-1)}, x^{(t)}; \theta) \label{eq:rnn}
|
||||||
\end{align}
|
\end{align}
|
||||||
|
|
||||||
Properties of a RNN are as follows \parencite[Chapter 10]{Goodfellow-et-al-2016}:-
|
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item Graph un-rolling and parameter sharing.
|
\item Graph un-rolling and parameter sharing.
|
||||||
|
|
||||||
|
|
@ -324,4 +324,6 @@ Properties of a RNN are as follows \parencite[Chapter 10]{Goodfellow-et-al-2016}
|
||||||
|
|
||||||
\section{Summary}
|
\section{Summary}
|
||||||
|
|
||||||
In this chapter, the mathematical theories and formulas related to multi level classification task is described. Author discusses the approach for numerical stability to avoid overflow and underflow of value resulting into a not-a-number values. In this chapter, an overview of the Probability Distribution and one of its type Multinoulli Distribution is given. Author illustrates the relationship between the task of product feature classification into category and the mathematical formulas.
|
In this chapter, the mathematical theories on neural network is described. Author illustrates mathematical equation for feedforward computational graphs and back propagation. Some mathematical concepts such as partial differentials to calculate the effect of small change in any one of the variable of a neural network is explained with step by step equation. Author describes the using sigmoid, softmax activation function in the output layer of neural network to bound the output values. In this chapter, author explains the \acl{MSE} loss function with a sample of training data. Author discusses the approach for numerical stability to avoid overflow and underflow of value resulting into a not-a-number values.
|
||||||
|
|
||||||
|
Further, the author describes multi level classification task. In this chapter, an overview of the Probability Distribution and one of its type Multinoulli Distribution is given. Author describes the basic architecture of a \acl{RNN} and explains the reason of using this network for categorizing the products based on product name.
|
||||||
|
|
@ -269,6 +269,6 @@ The graphical representation of code listed in \ref{code:rnn-arch} is illustrate
|
||||||
|
|
||||||
In this chapter, author describes how he ideated the concept of vocabulary based RNN. This method is a modified version of character level RNN \parencite{sean}. The method of converting the product name into a tensor format is described in this chapter.
|
In this chapter, author describes how he ideated the concept of vocabulary based RNN. This method is a modified version of character level RNN \parencite{sean}. The method of converting the product name into a tensor format is described in this chapter.
|
||||||
|
|
||||||
Architecture of the RNN and pictorial representation of flow of data within the neural network is depicted. It gives an overview of the activation functions and forward propagation method.
|
Architecture of the RNN and pictorial representation of flow of data within the neural network is depicted. The chapter gives an overview of the activation functions and forward propagation method. The code snippet of the defining architecture of \acl{RNN} class is given along with its explaination.
|
||||||
|
|
||||||
Research on mathematical representation of the RNN is conducted in this chapter. Step by step formulation and equations with regard to probability distribution is explained in this chapter.
|
In this chapter, Pytorch's loss functions such as SoftMax, LogSoftMax, Adaptive Softmax and its equivalent mathematical representations is described.
|
||||||
|
|
@ -23,6 +23,8 @@ Table \ref{table:AfterNormal} displays the difference in the number of records a
|
||||||
|
|
||||||
Pandas data frame \parencite{mckinney-proc-scipy-2010} provides the \textit{drop\_duplicates()} method to remove duplicate entries in the document. Code snippet in listing \ref{code:nt} has two methods ``normalize'' and ``clean''. In Pandas \parencite{mckinney-proc-scipy-2010}, ``apply'' method executes a function along a specified axis of data frame. Here for every text in the document of data frame variable ``df\_eng'', the method ``normalize'' is called to process the data. ``normalize'' function excepts a ``document'' as a parameter. These texts are processed to remove any html tags using Beautiful Soup a python library. Using regular expression library the digits in between the characters are removed, white spaces are removed. Any special character within the text has been transformed to its normal form.
|
Pandas data frame \parencite{mckinney-proc-scipy-2010} provides the \textit{drop\_duplicates()} method to remove duplicate entries in the document. Code snippet in listing \ref{code:nt} has two methods ``normalize'' and ``clean''. In Pandas \parencite{mckinney-proc-scipy-2010}, ``apply'' method executes a function along a specified axis of data frame. Here for every text in the document of data frame variable ``df\_eng'', the method ``normalize'' is called to process the data. ``normalize'' function excepts a ``document'' as a parameter. These texts are processed to remove any html tags using Beautiful Soup a python library. Using regular expression library the digits in between the characters are removed, white spaces are removed. Any special character within the text has been transformed to its normal form.
|
||||||
|
|
||||||
|
\clearpage
|
||||||
|
|
||||||
\begin{lstlisting}[language=Python,caption={Function to normalize text and remove duplicate},label={code:nt}]
|
\begin{lstlisting}[language=Python,caption={Function to normalize text and remove duplicate},label={code:nt}]
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
|
@ -73,11 +75,13 @@ As illustrated in code listing \ref{code:ootc}, the class Train is instantiated
|
||||||
train = Train(df_en)
|
train = Train(df_en)
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
The code snippet listing \ref{code:tcc} shows the initialization for attributes.
|
\clearpage
|
||||||
|
|
||||||
\begin{lstlisting}[language=Python,caption={Train class constructor},label={code:tcc}]
|
\begin{lstlisting}[language=Python,caption={Train class constructor},label={code:tcc}]
|
||||||
from sklearn.feature_extraction.text import CountVectorizer
|
from sklearn.feature_extraction.text import CountVectorizer
|
||||||
class Train():
|
class Train():
|
||||||
def __init__(self,df_en):
|
def __init__(self,df_en):
|
||||||
|
|
||||||
self.vectorizer = CountVectorizer(1,1)
|
self.vectorizer = CountVectorizer(1,1)
|
||||||
self.df_en = df_en
|
self.df_en = df_en
|
||||||
self.df_category = self.df_en.groupby("category")
|
self.df_category = self.df_en.groupby("category")
|
||||||
|
|
@ -93,6 +97,8 @@ class Train():
|
||||||
self.all_losses = []
|
self.all_losses = []
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
|
The code snippet listing \ref{code:tcc} shows the initialization of \textit{Train} class attributes. Code listing \ref{code:tcc} describes the initialization the required attributes qualifying the building blocks of a neural network, such as object of class \textit{RNN} defining the input size, number of hidden layers, and size of the output. The loss function $L$, learning rate $l$, training dataset containing the true labels $y_{true}$ are initialized.
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item self.vectorizer : Is an instance of \textbf{CountVectorizer} from scikit-learn \parencite{sklearn_api}. The details of Count vectorization is in section \ref {ch_countvector}. The argument (1,1) indicates that the vectorizer will consider individual words as the vocabulary.
|
\item self.vectorizer : Is an instance of \textbf{CountVectorizer} from scikit-learn \parencite{sklearn_api}. The details of Count vectorization is in section \ref {ch_countvector}. The argument (1,1) indicates that the vectorizer will consider individual words as the vocabulary.
|
||||||
\item self.df\_category: Stores the categorical classification of input data df\_en
|
\item self.df\_category: Stores the categorical classification of input data df\_en
|
||||||
|
|
@ -104,9 +110,11 @@ class Train():
|
||||||
\item self.all\_losses and self.current\_loss: These attributes are used to track the loss values during the training process.
|
\item self.all\_losses and self.current\_loss: These attributes are used to track the loss values during the training process.
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
\section{Generating random training examples}
|
\clearpage
|
||||||
|
|
||||||
The code listing \ref{code:rtcc} defines a method ``randomTrainingExample''. This method is responsible for generating training examples that will be used during the training process of the neural network.
|
\section{Fetch Training Dataset}
|
||||||
|
|
||||||
|
The code listing \ref{code:rtcc} defines a method ``randomTrainingExample''. This method is responsible for generating training examples that will be used during the training process of the neural network. This function fetches the pair of vectorized input $x^i$ that is the tensor representation of product name and true target label $y^i_{true}$ which is the tensor representation of category.
|
||||||
|
|
||||||
\begin{lstlisting}[language=Python,caption={Train class constructor},label={code:rtcc}]
|
\begin{lstlisting}[language=Python,caption={Train class constructor},label={code:rtcc}]
|
||||||
def randomTrainingExample(self):
|
def randomTrainingExample(self):
|
||||||
|
|
@ -126,7 +134,7 @@ def randomTrainingExample(self):
|
||||||
return randcategory, name, category_tensor, name_tensor
|
return randcategory, name, category_tensor, name_tensor
|
||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{itemize}
|
||||||
\item randcategory = random.choice(self.all\_category) : This fetches random category from the list of categories extracted during the initialization of ``Train'' class
|
\item randcategory = random.choice(self.all\_category) : This fetches random category from the list of categories extracted during the initialization of ``Train'' class
|
||||||
\item random\_feature\_indices = self.df\_category.indices[randcategory]: The indices of the randomly obtained category from step 1 is stored from the grouped dataframe ```df\_category'''
|
\item random\_feature\_indices = self.df\_category.indices[randcategory]: The indices of the randomly obtained category from step 1 is stored from the grouped dataframe ```df\_category'''
|
||||||
\item index = random\_feature\_indices[random.randint(0, len(random\_feature\_indices) - 1)] :\\ Random index is obtained from the list of indices of data sample belonging to the selected category.
|
\item index = random\_feature\_indices[random.randint(0, len(random\_feature\_indices) - 1)] :\\ Random index is obtained from the list of indices of data sample belonging to the selected category.
|
||||||
|
|
@ -135,67 +143,72 @@ def randomTrainingExample(self):
|
||||||
\item name\_tensor = self.helper.nameToTensor(name): The product name is converted into a tensor with a custom defined ``helper'' class. Code listing \ref{productnametotensor} is defined within the helper class.
|
\item name\_tensor = self.helper.nameToTensor(name): The product name is converted into a tensor with a custom defined ``helper'' class. Code listing \ref{productnametotensor} is defined within the helper class.
|
||||||
|
|
||||||
|
|
||||||
\end{enumerate}
|
\end{itemize}
|
||||||
|
|
||||||
|
|
||||||
\section{\acl{NLLLoss}}
|
|
||||||
|
|
||||||
The negative log likelihood loss is useful to train a classification problem with ``C'' classes or target labels \parencite{Paszke.03122019}. These labels are integers representing class indices. The \acl{NLLLoss} is often used with LogSfotmax activation function. In the final layer of the neural network, adding the
|
|
||||||
$LogSoftMax$ functions return the predicted log-probabilities. The loss is calculated by comparing the predicted log probabilities with the true target labels.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\clearpage
|
||||||
|
|
||||||
|
\section{Training Execution}
|
||||||
|
|
||||||
|
In code listing \ref{code:train_function} the \acl{NLLLoss} is calculated between the output of the \acf{RNN} $ y_{pred} $ which is the predicted-log-probabilities and the ground truth category tensor $y_true$.
|
||||||
|
|
||||||
\begin{lstlisting}[language=Python,caption={Train function},label={code:train_function}]
|
\begin{lstlisting}[language=Python,caption={Train function},label={code:train_function}]
|
||||||
|
|
||||||
def train(self,category_tensor, name_tensor):
|
def train(self,category_tensor, name_tensor):
|
||||||
|
|
||||||
|
hidden = self.rnn.initHidden()
|
||||||
|
|
||||||
hidden = self.rnn.initHidden()
|
self.rnn.zero_grad()
|
||||||
|
|
||||||
|
output, hidden = self.rnn(name_tensor, hidden)
|
||||||
|
loss = self.criterion(output, category_tensor)
|
||||||
|
loss.backward()
|
||||||
|
|
||||||
|
# Add parameters' gradients to their values, multiplied by learning rate
|
||||||
|
for p in self.rnn.parameters():
|
||||||
|
p.data.add_(p.grad.data, alpha=-self.learning_rate)
|
||||||
|
|
||||||
|
|
||||||
|
return output, loss.item()
|
||||||
|
\end{lstlisting}
|
||||||
|
|
||||||
self.rnn.zero_grad()
|
\subsection{\acl{NLLLoss}}
|
||||||
# for i in range(name_tensor.size()[0]):
|
The negative log likelihood loss is useful to train a classification problem with ``C'' classes or target labels \parencite{Paszke.03122019}. These labels are integers representing class indices. The \acl{NLLLoss} is often used with $LogSoftMax$ activation function. In the final layer of the neural network, adding the
|
||||||
|
$LogSoftMax$ functions return the predicted log-probabilities. The loss is calculated by comparing the predicted log probabilities with the true target labels $y_{true}$.
|
||||||
# output, hidden = self.rnn(name_tensor[i], hidden)
|
|
||||||
|
|
||||||
output, hidden = self.rnn(name_tensor, hidden)
|
|
||||||
loss = self.criterion(output, category_tensor)
|
|
||||||
loss.backward()
|
|
||||||
|
|
||||||
# Add parameters' gradients to their values, multiplied by learning rate
|
|
||||||
for p in self.rnn.parameters():
|
|
||||||
p.data.add_(p.grad.data, alpha=-self.learning_rate)
|
|
||||||
|
|
||||||
|
|
||||||
return output, loss.item()
|
|
||||||
\end{lstlisting}
|
|
||||||
|
|
||||||
In code listing \ref{code:train_function} the \acl{NLLLoss} is calculated between the output of the RNN which is the predicted-log-probabilities and the ground truth category tensor.
|
|
||||||
|
|
||||||
\section{\acf{BPTT}}
|
|
||||||
|
|
||||||
The back propagation learning procedure proposed in \parencite{Rumelhart.1986} minimizes the measure of difference in actual output vector and the desired output vector. This can be achieved with the backward() method of the loss function.
|
|
||||||
|
|
||||||
\subsection{How the backward() method works?} \label{sec:backward}
|
\subsection{\acf{BPTT}}
|
||||||
|
|
||||||
|
Detailed explanation of back propagation is given in section \ref{sec:minloss}. \\ In code listing \ref{code:train_function} the loss.backward() method of the loss function performs back propagation. RNN is a computational graph with parameters holding memory of previous time step. A computational graph is a record of all data (tensors) and all executed operations in a \acf{DAG}. The leaves of a \acsp{DAG} are the input tensor, roots are the output tensors. Unrolling the computational graph and then applying the back propagation algorithm is called \acl{BPTT} \parencite[section 15.2.5]{pml1Book}.
|
||||||
|
|
||||||
|
\subsection*{How the backward() method works?} \label{sec:backward}
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item During forward pass (refer code listing \ref{code:RNN-class}) of \acs{RNN} module, the log probabilities computation operations are recorded along with the computational graphs. A computational graph is a record of all data (tensors) and all executed operations in a \acf{DAG}. The leaves of a \acsp{DAG} are the input tensor, roots are the output tensors.
|
\item During forward propagation of \acs{RNN} module (refer section \ref{sec:math-rnn}) with output of $LogSoftMax$ activation function, the log probabilities computation operations are recorded along with the computational graphs.
|
||||||
\item The \textbf{backward()} on a scalar tensor start traversing the computational graph in reverse order (from \acs{DAG} root to leaves). For each step it applies chain rules of calculus flowing backward through the network in order to compute the gradients \parencite[section 6.5.2]{Goodfellow-et-al-2016}.
|
\item The \textbf{backward()} on a scalar tensor start traversing the computational graph in reverse order (from \acs{DAG} root to leaves). For each step it applies chain rules of calculus flowing backward through the network in order to compute the gradients \parencite[section 6.5.2]{Goodfellow-et-al-2016}.
|
||||||
\item The gradients are accumulated in the pytorchs \textbf{torch.Tensor.grad} attributes of the input tensors. \footnote{https://pytorch.org/tutorials/beginner/blitz/autograd\_tutorial.html}
|
|
||||||
\item These gradients can be accessed to update the model parameters through an optimization algorithm like \acf{SGD} . Iteratively trained neural network's gradient-based optimizers drive the cost function($LogSoftmax$) to a very low value.
|
|
||||||
\end{enumerate}
|
|
||||||
|
|
||||||
|
\end{enumerate}
|
||||||
|
\clearpage
|
||||||
|
\subsection{Model Parameter Optimization}
|
||||||
|
At line number 13 of code listing \ref{code:train_function}, the loop updates the model parameter.
|
||||||
|
\begin{itemize}
|
||||||
|
\item The gradients are accumulated in the Pytorchs \textbf{torch.Tensor.grad} attributes of the input tensors. \footnote{https://pytorch.org/tutorials/beginner/blitz/autograd\_tutorial.html}
|
||||||
|
\item These gradients can be accessed to update the model parameters through an optimization algorithm like \acf{SGD} (refer chapter \ref{ch:math-behid} for more details).
|
||||||
|
\item Iteratively trained neural network's gradient-based optimizers drive the cost function($LogSoftmax$) to a very low value.
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
\section{Experimentation: Variation in the training parameters.}
|
\section{Experimentation: Variation in the training parameters.}
|
||||||
|
|
||||||
\subsection{Training without \acs{BPTT}}
|
\subsection*{Training without \acs{BPTT}}
|
||||||
|
|
||||||
These are the observations when \textbf{loss.backward()} function in code listing \ref{code:train_function} is not used.
|
These are the observations when \textbf{loss.backward()} function in code listing \ref{code:train_function} is not used.
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item Pytorch's tensor.grad value is None. Hence, the manual optimization step does not update the model parameters.
|
\item Pytorch's tensor.grad value is None. Hence, the manual optimization step does not update the model parameters.
|
||||||
\item Commenting the line number 16 and 17 from code listing \ref{code:train_function}, completes the training process. However, the model does not learn anything.
|
\item Commenting the line number 9 and 10 from code listing \ref{code:train_function}, completes the training process. However, the model does not learn anything.
|
||||||
\item The figure \ref{fig:nograd} shows the loss across the training process. As the loss are not nearing to zero this shows that the model has failed in supervised learning of classification task.
|
\item The figure \ref{fig:nograd} shows the loss across the training process. As the loss are not nearing to zero this shows that the model has failed in supervised learning of classification task.
|
||||||
\begin{figure}[H]
|
\begin{figure}[H]
|
||||||
\centering
|
\centering
|
||||||
|
|
@ -207,7 +220,7 @@ These are the observations when \textbf{loss.backward()} function in code listin
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Training without updating the model parameters}
|
\subsection*{Training without updating the model parameters}
|
||||||
In this experiment, the \textbf{loss.backward()} method calculated the gradients. However, the model parameters were not updated by commenting the line number 16 and 17 from code listing \ref{code:train_function}. Notice in the figure \ref{fig:nograd} and figure \ref{fig:womp}, the loss is not reaching zero towards the end of the training. Indicating that in both the cases the model has not learned the product name patterns for the classification task.
|
In this experiment, the \textbf{loss.backward()} method calculated the gradients. However, the model parameters were not updated by commenting the line number 16 and 17 from code listing \ref{code:train_function}. Notice in the figure \ref{fig:nograd} and figure \ref{fig:womp}, the loss is not reaching zero towards the end of the training. Indicating that in both the cases the model has not learned the product name patterns for the classification task.
|
||||||
|
|
||||||
\begin{figure}[H]
|
\begin{figure}[H]
|
||||||
|
|
@ -237,11 +250,11 @@ In code \ref{code:mump}, the parameter ``p.data'' is a tensor. The method ``add
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Updating the hidden number of units}
|
\subsection*{Updating the hidden number of units}
|
||||||
|
|
||||||
The model is described as a \acl{DAG} describing how functions are composed together. Consider having three functions $f(x) = f_3(f_2(f_1(x)))$ connected in a chain. $f_1$ is the first layer of the network, $f_2$ the second and so on. In the example of a classifier, $y=f_*(x)$ maps an input $ x $ to a category $ y $. The final layer of the network is called the output layer. The training data specifies what the output layer must do at each point $x$, that is to produce a value close to $y$. As the training data does not show the desired output for other layers, they are called \textbf{hidden layers} \parencite[Chapter 3]{Goodfellow-et-al-2016}. \parencite{zhang2021dive} describes the concept of \textbf{hidden state} which are inputs at step $t$ can only be computed with previous input at step $ t-1 $. \acf{RNN} are neural network with hidden states.
|
The model is described as a \acl{DAG} describing how functions are composed together. Consider having three functions $f(x) = f_3(f_2(f_1(x)))$ connected in a chain. $f_1$ is the first layer of the network, $f_2$ the second and so on. In the example of a classifier, $y=f_*(x)$ maps an input $ x $ to a category $ y $. The final layer of the network is called the output layer. The training data specifies what the output layer must do at each point $x$, that is to produce a value close to $y$. As the training data does not show the desired output for other layers, they are called \textbf{hidden layers} \parencite[Chapter 3]{Goodfellow-et-al-2016}. \parencite{zhang2021dive} describes the concept of \textbf{hidden state} which are inputs at step $t$ can only be computed with previous input at step $ t-1 $. \acf{RNN} are neural network with hidden states.
|
||||||
|
|
||||||
\subsubsection{Model with only one hidden state}
|
\subsubsection*{Model with only one hidden state}
|
||||||
In this experiment, only one hidden state has been assigned to the \acs{RNN} network. As illustrated in figure \ref{fig:unihidden}, the loss reduces gradually. However, the model is yet under fit for the classification task. The loss not reaching zero towards the end of the training indicates that the model has not learned anything significant.
|
In this experiment, only one hidden state has been assigned to the \acs{RNN} network. As illustrated in figure \ref{fig:unihidden}, the loss reduces gradually. However, the model is yet under fit for the classification task. The loss not reaching zero towards the end of the training indicates that the model has not learned anything significant.
|
||||||
|
|
||||||
\begin{figure}[H]
|
\begin{figure}[H]
|
||||||
|
|
@ -251,7 +264,7 @@ In this experiment, only one hidden state has been assigned to the \acs{RNN} net
|
||||||
\label{fig:unihidden}
|
\label{fig:unihidden}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
\subsubsection{Model with only 10 hidden state}
|
\subsubsection*{Model with only 10 hidden state}
|
||||||
Increasing the number of hidden state to 10 units gave the desired result. As seen in figure \ref{fig:10hidden}, the loss has reached near zero by end of the training. This model is able to predict the category based on the pattern of name.
|
Increasing the number of hidden state to 10 units gave the desired result. As seen in figure \ref{fig:10hidden}, the loss has reached near zero by end of the training. This model is able to predict the category based on the pattern of name.
|
||||||
\begin{figure}[H]
|
\begin{figure}[H]
|
||||||
\centering
|
\centering
|
||||||
|
|
@ -260,7 +273,7 @@ Increasing the number of hidden state to 10 units gave the desired result. As s
|
||||||
\label{fig:10hidden}
|
\label{fig:10hidden}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
\subsection{Gradient decent step adjustment}
|
\section{Gradient decent step adjustment}
|
||||||
|
|
||||||
As stated in section \ref{sec:backward}, the method \textbf{loss.backward()} computes the gradients by applying chain rule of calculus for each function $f(x)$. The derivative of this function is denoted as $f'(x)$ \\ or as $\frac{dy}{dx}$. $f(x)$ can be reduced by moving $x$ in small with steps opposite sign of derivative is called gradient decent \parencite{cauchy}. \parencite[section 4.3]{Goodfellow-et-al-2016} presents an equation \ref{eq:update_rule}.
|
As stated in section \ref{sec:backward}, the method \textbf{loss.backward()} computes the gradients by applying chain rule of calculus for each function $f(x)$. The derivative of this function is denoted as $f'(x)$ \\ or as $\frac{dy}{dx}$. $f(x)$ can be reduced by moving $x$ in small with steps opposite sign of derivative is called gradient decent \parencite{cauchy}. \parencite[section 4.3]{Goodfellow-et-al-2016} presents an equation \ref{eq:update_rule}.
|
||||||
|
|
||||||
|
|
@ -297,7 +310,7 @@ The steps involved in training a model with \acs{CLR} are as follows :
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
|
|
||||||
\subsection{Experimentation and analysis to determine learning rate range}
|
\subsection*{Experimentation and analysis to determine learning rate range}
|
||||||
|
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item Experiment by setting $base\_lr$ and $max\_lr$ manually : \\
|
\item Experiment by setting $base\_lr$ and $max\_lr$ manually : \\
|
||||||
|
|
|
||||||
BIN
doc/images/srh.png
Normal file
BIN
doc/images/srh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
|
|
@ -3,7 +3,7 @@
|
||||||
\vspace*{3\baselineskip}
|
\vspace*{3\baselineskip}
|
||||||
\begin{flushright}
|
\begin{flushright}
|
||||||
|
|
||||||
\includegraphics[scale=0.3]{SRH_Hochschule_Heidelberg_logo.svg.png}
|
\includegraphics[scale=1]{srh.png}
|
||||||
|
|
||||||
\end{flushright}
|
\end{flushright}
|
||||||
\vspace*{3\baselineskip}
|
\vspace*{3\baselineskip}
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{\Large \bfseries Application of Natural language processing in E-Commerce \\ Predicting product taxonomy}
|
{\Large \bfseries Application of Natural Language Processing in E-Commerce \\ Predicting Product Taxonomy}
|
||||||
\vspace*{3\baselineskip}
|
\vspace*{3\baselineskip}
|
||||||
|
|
||||||
{\Large Master Thesis}
|
{\Large Master Thesis}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue