diff --git a/doc/References.bib b/doc/References.bib index b22da4c..189293b 100644 --- a/doc/References.bib +++ b/doc/References.bib @@ -537,3 +537,45 @@ urldate = {2023-08-09}, } +% This file was created with Citavi 6.15.2.0 + +@misc{Kutyniok.16032022, + abstract = {We currently witness the spectacular success of artificial intelligence in both science and public life. However, the development of a rigorous mathematical foundation is still at an early stage. In this survey article, which is based on an invited lecture at the International Congress of Mathematicians 2022, we will in particular focus on the current {\textquotedbl}workhorse{\textquotedbl} of artificial intelligence, namely deep neural networks. We will present the main theoretical directions along with several exemplary results and discuss key open problems.}, + author = {Kutyniok, Gitta}, + date = {16/03/2022}, + title = {The Mathematics of Artificial Intelligence}, + url = {https://arxiv.org/pdf/2203.08890.pdf}, + urldate = {2023-08-03}, + file = {2203.08890:Attachments/2203.08890.pdf:application/pdf} +} + + +% This file was created with Citavi 6.15.2.0 + +@book{Gevin.1997, + abstract = {Though mathematical ideas underpin the study of neural networks, the author presents the fundamentals without the full mathematical apparatus. All aspects of the field are tackled, including artificial neurons as models of their real counterparts; the geometry of network action in pattern space; gradient descent methods, including back-propagation; associative memory and Hopfield nets; and self-organization and feature maps. The traditionally difficult topic of adaptive resonance theory is clarified within a hierarchical description of its operation. The book also includes several real-world e}, + author = {Gevin, Gurney}, + year = {1997}, + title = {An introduction to neural networks}, + url = {http://www.macs.hw.ac.uk/~yjc32/project/ref-NN/Gurney_et_al.pdf}, + address = {London}, + urldate = {2023-08-10}, + publisher = {{UCL Press}}, + isbn = {9781857286731}, + file = {An Introduction to Neural Networks:Attachments/An Introduction to Neural Networks.pdf:application/pdf} +} + +% This file was created with Citavi 6.15.2.0 + +@misc{Lederer.25012021, + abstract = {Activation functions shape the outputs of artificial neurons and, therefore, are integral parts of neural networks in general and deep learning in particular. Some activation functions, such as logistic and relu, have been used for many decades. But with deep learning becoming a mainstream research topic, new activation functions have mushroomed, leading to confusion in both theory and practice. This paper provides an analytic yet up-to-date overview of popular activation functions and their properties, which makes it a timely resource for anyone who studies or applies neural networks.}, + author = {Lederer, Johannes}, + date = {25/01/2021}, + title = {Activation Functions in Artificial Neural Networks: A Systematic Overview}, + url = {https://arxiv.org/pdf/2101.09957.pdf}, + urldate = {2023-06-05}, + file = {2101.09957:Attachments/2101.09957.pdf:application/pdf} +} + + + diff --git a/doc/chapters/introduction.tex b/doc/chapters/introduction.tex index 44ef911..4643dc3 100644 --- a/doc/chapters/introduction.tex +++ b/doc/chapters/introduction.tex @@ -2,19 +2,17 @@ \section{Background and context} -While working at an e-commerce industry, specializing in sales of automobile parts, author realized that manufactures and suppliers of similar automobile parts often utilize different product taxonomies. Product taxonomy is hierarchical multi level categorization of the product. Suppliers rely on online platforms to reach out to the customers. In the business context, the term ``supplier'' encompasses entity contributing to production and distribution of goods and services. Therefore, in this thesis, the term ``supplier'' include both manufactures or any source which provides information on the product for sale. Suppliers are business partners who provide the stocks of products along with associated product details. +While working at an e-commerce industry, specializing in sales of automobile parts, author realized that manufactures and suppliers of similar automobile parts often utilize different product taxonomies. Product taxonomy is hierarchical multi level categorization of the product. Suppliers rely on online platforms to reach out to the customers. However, due to inconsistencies in the product taxonomies among various suppliers, directly importing these product taxonomies into the online platform is not feasible. The inconsistency could be due to use of different vocabulary for the similar product. For example, manufacturers of car oil may use the term ``Motor oil'' as well as ``Engine oil'' for the same product. -However, due to inconsistencies in the product taxonomies among various suppliers, directly importing these product taxonomies into the online platform is not feasible. The inconsistency could be due to use of different vocabulary for the similar product. For example, supplier A may use the term ``Motor oil'' and supplier B may use the term ``Engine oil'' for the same product. The process of product deployment is as following: suppliers furnish the product details, online retailers update the product taxonomies with their specific vocabulary. Once the taxonomies are updated these products details are accessible for the customers. - -Defining the product taxonomy is a prior and crucial task of product deployment. A well-defined product taxonomy enables customers to search the product with the fewest possible clicks. Manually defining the product taxonomies requires a significant amount of time and are prone to human error. +Defining the product taxonomy is a prior and crucial task of product information deployment. A well-defined product taxonomy enables customers to search the product with the fewest possible clicks. Manually defining the product taxonomies requires a significant amount of time and are prone to human error. The e-commerce industry is growing substantially, and wide range of products being offered online. Utilization of machine learning model for recommending the products to the customer, auto completing the search text, automatically filtering of products based on the product description provided by the customer are few examples of function facilitated by artificial intelligence. It is important to note that successful execution of all these functionalities primary requirement is to have a well-defined product taxonomy. Customer review monitoring system uses natural language processing to understand the semantic meaning of the comment. Determining whether a customer is satisfied or dissatisfied based on their review can be a complex task. By understanding the semantic meaning helps to identify the negatively commented review regarding a product or service. The reviews are classified as either positive or negative, similar to the classification problem of predicting the product category. - In this paper, author equates on mathematical functionality of probability distribution and learning mechanism of \acl*{RNN}. These insights are applicable to wide range of classification problem. +Understanding the mathematical foundations of neural network is important to develop a robust supervised text classification model for predicting the product taxonomy. Analyzing the research path intersecting between mathematics and \acl{AI} leverages the ongoing development of building better machine learning model. - Apart from the classification problem, this paper presents the concept of knowledge base. Online retailers strive to engage with their customers effectively through tools like chatbot, capable of answering frequently asked question. The queries asked by the customers and their relevant answers are in the form of an unstructured textual data. In this thesis, author presents a prototype for converting the unstructured textual data into a directed acyclic graph. These graphs, in conjunction with the question generator machine learning model, can function as a knowledge base. Knowledge base serve as a foundation for chatbot applications to traverse through the graph structure, locate relevant leafs nodes, and formulate human-readable response. + This paper also presents the concept of knowledge base. In this thesis, author presents a prototype for converting the unstructured textual data into a directed acyclic graph. \section{Research questions} diff --git a/doc/chapters/math-behind.tex b/doc/chapters/math-behind.tex index bd4fd00..ad85dd6 100644 --- a/doc/chapters/math-behind.tex +++ b/doc/chapters/math-behind.tex @@ -1,10 +1,22 @@ -\chapter{Mathematical Foundations of Classification Model} \label{ch:math-behid} +\chapter{Mathematical Foundations of Neural Networks} \label{ch:math-behid} + +Understanding the mathematical foundations of the deep neural network is important for searching suitable network architecture. The approach of implementing a model without understanding the mathematical foundation could lead to unexpected failure in getting the desired results from the model. Understanding fundamental mathematics of \acl{AI} is necessary as further development in this field is on going. \parencite{Kutyniok.16032022} states two different research direction intersects with mathematics and \acl{AI}. One which place the network architecture and training process on theory of mathematics and another with a goal to develop mathematical problem settings such as partial derivatives equations aiming to tap the potentials of neural network. + +Often it is said that an artificial neural network mimics the structure of a biological brain. As illustrated in figure \ref{fig:bio neuron}, a brain is a deep network of neurons which processes the input signals received from Dendrites and transited with Axon. Before transmitting these incoming signals are integrated or summed together in some way and if resulting signal exceeds some threshold then the neuron will transmit it to other neurons. +\begin{figure}[H] + \centering + \includegraphics[scale=0.4]{bio_neuron.png} + \caption{Component of biological neuron in stylized form \parencite[section 1.1]{Gevin.1997}} + \label{fig:bio neuron} +\end{figure} + +The artificial equivalent of a biological neuron is shown in figure \ref{fig:basic neuron}. The Synapses of figure \ref{fig:bio neuron} are modelled as number or weight being multiplied to each input signals. The weighted signals are summed together by simple arithmetic addition. The resulting value is passed though an activation function representing threshold logic units \parencite[section 1.1]{Gevin.1997}. \section{Neural Networks and Loss Minimization} \subsection*{Neurons} -A neural network is a connection of neurons. A Neuron takes input, do some computation and returns an output. Figure \ref{fig:basic neuron} illustrates a basic unit of neuron, which is multiplying each unit of inputs with weight $w$ and weighted input are added with bias $b$. Finally, the sum is passed though a sigmoid activation function $ f $. +A neural network is a connection of neurons. A Neuron takes input, do some computation and returns an output. Figure \ref{fig:basic neuron} illustrates a example of basic unit of neuron, which is multiplying each unit of inputs with weight $w$ and weighted input are added with bias $b$. Finally, the sum is passed though a activation function $ f $. \begin{figure}[H] \centering \includegraphics[scale=0.4]{neuron.png} @@ -17,7 +29,7 @@ A neural network is a connection of neurons. A Neuron takes input, do some compu y = f(x_1 * w_1 + x_2 * w_2 + b) \label{eq:single_n} \end{align} -The equation \ref{eq:single_n} is the mathematical representation of the sample neuron. +The equation \ref{eq:single_n} is the mathematical representation of the sample neuron. The artificial neurons can be added and concatenated into new functions eventually leading to a complex function. A neuron's characteristics is determined by its parameters and activation functions. Each of the activation functions have a mathematical particularity and their practical effects \parencite{Lederer.25012021}. \subsection*{Neural Network} @@ -71,7 +83,7 @@ The equation \ref{eq:single_n} is the mathematical representation of the sample \label{fig:nn_hl} \end{figure} -Figure \ref{fig:nn_hl}, illustrates addition of two neurons hidden layers $h_1$ and $h_2$ between input layer (first) and output layer (last). The data flow is represented with directed arrows, this process of passing input forward to get an output is called feed-forward. +Figure \ref{fig:nn_hl}, illustrates addition of two neurons hidden layers $h_1$ and $h_2$ between input layer (first) and output layer (last). The data flow is represented with directed arrows, this process of passing input forward to get an output is called feed-forward. A feedforward neural network comprises many functions associated with a \acl{DAG}. These chain of functions form a deep layers of the network and such is the term deep learning being tossed \parencite[chapter 6]{Goodfellow-et-al-2016}. \subsection*{Training a Network} @@ -225,8 +237,8 @@ Multinoulli distributions are often employed to model distributions over categor Moreover, when working with multinoulli-distributed random variables, it is typically unnecessary to compute expectations or variances since these distributions are used to describe categorical outcomes where numerical operations may not be meaningful \parencite[Page 60,61]{Goodfellow-et-al-2016}. - -\section{Softmax} +\section{Activation Functions and their Propertise} +\subsection{Softmax} The softmax function is often used to predict the probabilities associated with a multinoulli distribution \parencite[Page 79]{Goodfellow-et-al-2016}. @@ -281,6 +293,73 @@ 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. \end{itemize} +\subsection{Sigmoid or Logistic} + +Sigmoid function, also termed as squashing function as the values are bounded in an interval. Figure \ref{fig:SigmoidActivation} shows the graph of a sigmoid function showing a smooth ``S'' shaped curve. This function is denoted with greek letter $\sigma$ (sigma) and is defined as \parencite[section 2.1]{Lederer.25012021}: + +\begin{align} + \sigma(x) = \frac{1}{1+ e^{-x}} \label{eq:sigma} +\end{align} + +\begin{itemize} + \item If $x$ to the sigmoid function is a small negative number, the output is very close to 0. + \item If $x$ is a large positive number, then the output is very close to 1. + \item If $x$ is 0, the output is $0.5$. + \item Types of sigmoid functions are logistics, artan, tanh and softsign. +\end{itemize} + +\subsection{ReLU Rectified Linear Unit} +In electrical engineering, a rectifier is a device that converts alternating current to direct current. Similarly, this function lets positive inputs pass unaltered but cuts negative inputs as shown in figure \ref{fig:ReLUActivation}. Limitations of ReLU is dying-relu phenomina, which is similar to vanishing gradient decent. The solution to it is leaky-ReLu \parencite[section 2.2.2]{Lederer.25012021}. + +\begin{figure}[htbp] + \centering + \begin{subfigure}{0.45\textwidth} + \begin{tikzpicture} + \begin{axis}[ + xlabel=$x$, + ylabel=$\sigma(x)$, + xmin=-6, + xmax=6, + ymin=0, + ymax=1.2, + width=8cm, + height=6cm, + grid=both, + axis lines=middle + ] + \addplot[blue, domain=-6:6, samples=100] {1 / (1 + exp(-x))}; + \end{axis} + \end{tikzpicture} + \caption{Sigmoid activation function} + \label{fig:SigmoidActivation} + \end{subfigure} + \hspace{0.05\textwidth} + \begin{subfigure}{0.45\textwidth} + \begin{tikzpicture} + \begin{axis}[ + xlabel=$x$, + ylabel=$\text{ReLU}(x)$, + xmin=-2, + xmax=2, + ymin=0, + ymax=2, + width=8cm, + height=6cm, + grid=both, + axis lines=middle + ] + \addplot[blue, domain=-2:0, samples=100] {0}; + \addplot[blue, domain=0:2, samples=100] {x}; + \end{axis} + \end{tikzpicture} + \caption{ReLU activation function} + \label{fig:ReLUActivation} + \end{subfigure} + + \caption{Activation functions} + \label{fig:ActivationFunctions} +\end{figure} + \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} is best suited for machine learning problems that involve sequential data such as sequence translation, generation and classification. A recurrent neural network is specialized for processing sequence of values $ x^{(1)},\ldots,x^{(t)}$. The prediction of output $y^t$ also depends on the hidden state of the system $h^t$, which gets updated overtime as the sequence is processed \parencite[Chapter 15, Page 501]{pml1Book}. @@ -302,8 +381,8 @@ Equation \ref{eq:rnn} depicts the common representation of RNN to define the hid \end{align} -\begin{itemize} - \item Graph un-rolling and parameter sharing. + + \subsection*{Graph Un-rolling and Parameter Sharing} Here graph is referred to as the structure of a set of computations, such as the data flow from input layer to output layer for mapping the loss. Unfolding the equation \ref{eq:rnn} for $t=3$ times, we obtain: @@ -315,7 +394,35 @@ Equation \ref{eq:rnn} depicts the common representation of RNN to define the hid The equation \ref{eq:rnn} is recurrent without the external signal $x^{(t)}$. This expression can be represented by \acl{DAG}. Unfolding this graph results in the sharing of parameters across a network structure. -\end{itemize} + \subsection*{Sequence Generation} + + In this type, the output sequence is generated one token at a time. At every step a sample output $y^t$ from the hidden state $h^t$ is again feed back in to the model to get new state $h^{t+1}$ as illustrated in figure \ref{fig:RNN vectoseq}. This architecture could be applied in image captioning method \parencite[section 15.2.1]{pml1Book}. + + + \begin{figure}[H] + \centering + \includegraphics[scale=0.9]{seq_gen.png} + \caption{A \acl*{RNN} for generating a variable length output sequence given an + optional fixed length input vector. \parencite[section 15.2.1]{pml1Book}} + \label{fig:RNN vectoseq} + \end{figure} + + \subsection*{Sequence Classification} +This architecture take variable length sequence as input and predict an output vector. The output of the hidden state is depended on the previous hidden state and also on input sequence as shown in figure \ref{fig:RNN seqtovec}. + \begin{figure}[H] + \centering + \includegraphics[scale=0.9]{seq_class.png} + \caption{A \acs*{RNN} for classification \parencite[section 15.2.1]{pml1Book}} + \label{fig:RNN seqtovec} + \end{figure} + + + + \subsection*{Sequence Translation} +There are two types, one in which the input and output are of same length (aligned) and other in which input and output sequence are of variable length(unaligned). +Application of unaligned sequence translation is machine translation. + + diff --git a/doc/chapters/model-selection.tex b/doc/chapters/model-selection.tex index 0129b80..5a5f352 100644 --- a/doc/chapters/model-selection.tex +++ b/doc/chapters/model-selection.tex @@ -140,6 +140,7 @@ class RNN(nn.Module): return torch.zeros(1, self.hidden_size) \end{lstlisting} +\clearpage \subsection*{Summary of the RNN class:} \begin{itemize} @@ -155,8 +156,8 @@ class RNN(nn.Module): \clearpage -The graphical representation of code listed in \ref{code:rnn-arch} is illustrated in figure \ref{fig:archi}. -\begin{figure}[h] +The graphical representation of code listed in \ref{code:rnn_arch} is illustrated in figure \ref{fig:archi}. +\begin{figure} \centering \caption{\acs{RNN} Architecture \parencite{sean}} \label{fig:archi} @@ -225,7 +226,7 @@ The graphical representation of code listed in \ref{code:rnn-arch} is illustrate % \item $\hat{y}(t)$ is the normalized probability vector (predicted probabilities) over the output, obtained by applying the softmax operation to $o(t)$, which converts the unnormalized log probabilities into valid probabilities summing up to $1$. % \end{itemize} - +\clearpage \section{Pytorch's $SoftMax$ function and its variations} diff --git a/doc/chapters/training-hypertuning.tex b/doc/chapters/training-hypertuning.tex index 2b8e5c2..3975b91 100644 --- a/doc/chapters/training-hypertuning.tex +++ b/doc/chapters/training-hypertuning.tex @@ -329,54 +329,63 @@ The steps involved in training a model with \acs{CLR} are as follows : \item In the next experiment, we set the $max\_lr = 0.2$. \\ The classification model successfully completed the training and was able to predict the category. - \begin{figure} - \centering - \includegraphics[scale=0.8]{loss_lr_02.png} - \caption{Loss vs Learning rate; where $max\_lr = 0.2$} - \label{fig:Loss value at 0.2} - \end{figure} + As illustrated in figure \ref{fig:Loss value at 0.2}, in the graph plotted of Loss Vs Learning rate. The model started to learn at learning rate $\epsilon = 0.04$ onwards. We will further reduce the $max\_lr$. \item In the next experiment, we set the $max\_lr = 0.04$. \\ Notice in figure \ref{fig:Loss value at 0.04}, there is a plateau until $\epsilon = 0.010$. After which there is a descent until $\epsilon = 0.015$ - \begin{figure} - \centering - \includegraphics[scale=0.9]{loss_004.png} - \caption{Loss vs Learning rate; where $max\_lr = 0.04$} - \label{fig:Loss value at 0.04} - \end{figure} + \item In the next experiment, we set the $max\_lr = 0.015$. \\ Notice in figure \ref{fig:Loss value at 0.015}, the loss had not neared zero and the model fails to predict the classification. - \begin{figure} - \centering - \includegraphics[scale=0.9]{loss_0015.png} - \caption{Loss vs Learning rate; where $max\_lr = 0.015$} - \label{fig:Loss value at 0.015} - \end{figure} + \item From the earlier mentioned experimentation with $max\_lr$, the loss in classification model is nearing zero by the end the training when $max\_lr > 0.015$ Figure \ref{fig:Loss value at 0.02} illustrates the loss reaching near zero when $max\_lr = 0.02$. The figure \ref{fig:Loss value at 0.02}, there is a plateau until the $ \epsilon = 0.0075$. Indicating that the model did not learn until the learning rate $ \epsilon = 0.0075$. - \begin{figure} - \centering - \includegraphics[scale=0.9]{loss_002.png} - \caption{Loss vs Learning rate; where $max\_lr = 0.02$} - \label{fig:Loss value at 0.02} - \end{figure} + \item Updating the $base_lr=0.0075$ and $max_lr=0.02$, resulted a steady slop in the loss vs learning rate. Figure \ref{fig:Loss value at 0.0075} illustrates the loss reaching near zero when $max\_lr = 0.02$ and $base_lr=0.0075$. The steady decent indicates the learning rate range is optimal. - \begin{figure} - \centering - \includegraphics[scale=0.9]{loss_0075_002.png} - \caption{Loss vs Learning rate; where $base\_lr = 0.0075$ and $max\_lr = 0.02$ } - \label{fig:Loss value at 0.0075} - \end{figure} \end{enumerate} +\begin{figure}[htbp] + \centering + \begin{subfigure}{0.4\textwidth} + \includegraphics[width=\linewidth]{loss_004.png} + \caption{Loss vs Learning rate; where $max\_lr = 0.04$} + \label{fig:Loss value at 0.04} + \end{subfigure} + \hfill + \begin{subfigure}{0.4\textwidth} + + \includegraphics[width=\linewidth]{loss_lr_02.png} + \caption{Loss vs Learning rate; where $max\_lr = 0.2$} + \label{fig:Loss value at 0.2} + \end{subfigure} + + \begin{subfigure}{0.4\textwidth} + \includegraphics[width=\linewidth]{loss_0015.png} + \caption{Loss vs Learning rate; where $max\_lr = 0.015$} + \label{fig:Loss value at 0.015} + \end{subfigure} + \hfill + \begin{subfigure}{0.4\textwidth} + \includegraphics[width=\linewidth]{loss_002.png} + \caption{Loss vs Learning rate; where $max\_lr = 0.02$} + \label{fig:Loss value at 0.02} + \end{subfigure} + \vspace{1cm} % Add vertical space between rows of images + \begin{subfigure}{0.4\textwidth} + \includegraphics[width=\linewidth]{loss_0075_002.png} + \caption{Loss vs Learning rate; where $base\_lr = 0.0075$ and $max\_lr = 0.02$ } + \label{fig:Loss value at 0.0075} + \end{subfigure} + +\end{figure} + \section{Triangular learning rate} \parencite{Smith.03062015} introduced the concept of letting the learning rate vary within the range of minimum and maximum boundaries of learning rate known as learning rate range. In this method the learning rate linearly increases until step size $ t $ and then linearly decreases. diff --git a/doc/images/bio_neuron.png b/doc/images/bio_neuron.png new file mode 100644 index 0000000..32610d8 Binary files /dev/null and b/doc/images/bio_neuron.png differ diff --git a/doc/images/seq_class.png b/doc/images/seq_class.png new file mode 100644 index 0000000..3732373 Binary files /dev/null and b/doc/images/seq_class.png differ diff --git a/doc/images/seq_gen.png b/doc/images/seq_gen.png new file mode 100644 index 0000000..cd3eaf1 Binary files /dev/null and b/doc/images/seq_gen.png differ diff --git a/doc/index.tex b/doc/index.tex index b78ea22..27565f1 100644 --- a/doc/index.tex +++ b/doc/index.tex @@ -23,7 +23,8 @@ \usepackage{enumitem} \usepackage{appendix} \usepackage{mathrsfs} - +\usepackage{subcaption} % For subfigures +\usepackage{pgfplots} % \title{\Large \textbf{Application of Natural Language Processing \\ and Machine Learning in E-Commerce} \\ \Large Predicting Product Taxonomy} \usetikzlibrary{shapes,arrows,positioning,arrows.meta,calc} \captionsetup[table]{skip=5pt} @@ -33,6 +34,10 @@ \setlength{\cftfigindent}{0pt} \setlength{\cftfignumwidth}{6.5em} +% Add extra space between paragraphs +\setlength{\parskip}{10pt} % Adjust the value to your preferred paragraph spacing + + \definecolor{codegreen}{rgb}{0,0.6,0} \definecolor{codegray}{rgb}{0.5,0.5,0.5}