diff --git a/doc/References.bib b/doc/References.bib index 3e94233..6f77a47 100644 --- a/doc/References.bib +++ b/doc/References.bib @@ -325,4 +325,32 @@ doi = {10.1038/s41586-020-2649-2}, publisher = {Springer Science and Business Media {LLC}}, url = {https://doi.org/10.1038/s41586-020-2649-2} -} \ No newline at end of file +} + + +% This file was created with Citavi 6.15.2.0 + +@misc{Gupta.20062016, + abstract = {Product classification is the task of automatically predicting a taxonomy path for a product in a predefined taxonomy hierarchy given a textual product description or title. For efficient product classification we require a suitable representation for a document (the textual description of a product) feature vector and efficient and fast algorithms for prediction. To address the above challenges, we propose a new distributional semantics representation for document vector formation. We also develop a new two-level ensemble approach utilizing (with respect to the taxonomy tree) a path-wise, node-wise and depth-wise classifiers for error reduction in the final product classification. Our experiments show the effectiveness of the distributional representation and the ensemble approach on data sets from a leading e-commerce platform and achieve better results on various evaluation metrics compared to earlier approaches.}, + author = {Gupta, Vivek and Karnick, Harish and Bansal, Ashendra and Jhala, Pradhuman}, + date = {20/06/2016}, +year = {2016}, + title = {Product Classification in E-Commerce using Distributional Semantics}, + url = {https://arxiv.org/pdf/1606.06083.pdf}, + urldate = {09/03/2023}, + file = {1606.06083:Attachments/1606.06083.pdf:application/pdf} +} + +% This file was created with Citavi 6.15.2.0 + +@article{AliCevahir., + author = {{Ali Cevahir} and {Koji Murakami}}, + title = {Large-scale Multi-class and Hierarchical Product Categorization for an E-commerce Giant}, + url = {https://aclanthology.org/C16-1051.pdf}, + year ={2016}, + urldate = {31/05/2023}, + file = {Ali Cevahir, Koji Murakami - Large-scale Multi-class and Hierarchical Product:Attachments/Ali Cevahir, Koji Murakami - Large-scale Multi-class and Hierarchical Product.pdf:application/pdf} +} + + + diff --git a/doc/chapters/chapter7.tex b/doc/chapters/chapter7.tex index 31f6065..1d32c1b 100644 --- a/doc/chapters/chapter7.tex +++ b/doc/chapters/chapter7.tex @@ -457,11 +457,17 @@ Listing \ref{code:triangularLR} is the code to train the model using triangular \subsection{Experimentation and analysis} -In this experiment, the model is trained with and without triangular learning rate method. The total number of iterations is $10000 \times 10$. The graph of Loss Vs Learning rate and time taken to complete the iterations illustrates the performance of the model. The graph plotted for each $2500$ iterations provide insight on how the model is performing. The lesser the time taken +In this experiment, the model is trained with and without triangular learning rate method. The total number of iterations is $10000 \times 10$. The graph of Loss Vs Learning rate and time taken to complete the iterations illustrates the performance of the model. The graph plotted for each $2500$ iterations provide insight on how the model is performing. \begin{enumerate} \item Triangular learning rate; where $base\_lr =0.0075$ and $max\_lr=0.02$: \\ - + \begin{figure}[H] + \centering + \includegraphics[scale=0.5]{lossinfo_tlr.png} + \caption{Loss with TLR, where $base\_lr =0.0075$ and $max\_lr=0.02$ + } + \label{fig:trl_loss} + \end{figure} diff --git a/doc/chapters/introduction.tex b/doc/chapters/introduction.tex index 2109ad5..57e0198 100644 --- a/doc/chapters/introduction.tex +++ b/doc/chapters/introduction.tex @@ -2,3 +2,38 @@ \section{Topic overview} +While working at an E-commerce company selling automobile parts, author realized that various manufacture and suppliers of similar kind of automobile parts may have different product taxonomy. Defining the product taxonomy is a prior task of product deployment. Manually defining the product taxonomy requires a significant amount of time and are prone to error. \\ + +E-commerce industry is growing, and many products are sold online. Use of machine learning model for suggesting the products to the customer, auto completing the search text, auto filtering of products based on the text provided by the user describing the product are few of the tasks which is managed by artificial intelligence. All the tasks can only be performed appropriately only if the product taxonomy is well-defined. \\ + + + +\section{Problem statement and Research question} + +\begin{itemize} + \item RQ1: How to define product features as an input for machine learning model? + \item RQ2 : Which type of neural network is the best suitable for text classification in terms of product classification? + \item RQ3 : How should the model parameters be defined to optimize the neural network? +\end{itemize} + +\section{Methodology} + +Machine learning model to text classification for predicting the product taxonomy is a methodology in which a lot of research have been conducted \parencite{AliCevahir.} \parencite{Gupta.20062016}. In this thesis, author classifies the product by representing the features of the product into vector of entire vocabulary of dataset. This approach is inspired by \parencite{sean}, in which the language of the name is predicted based on the pattern of characters in name input. + +\section{Thesis structure} + +In the first chapter, gives the introduction of the thesis along with research questions and methodology. + +In the second chapter, defining or selecting the features from a document is described. It introduces various analytic engine tools and methods for feature selection. + +The third chapter describes various methods to standardize the text data and preprocess it before making it as an input to the classification model. + +The fourth chapter focuses on retaining the missing textual data from the dataset from which the classification model will be predicting the product category. + +The fifth chapter is a guideline on vectoring or transforming the text into machine usable numerical form called feature extraction. + +In the sixth chapter, how author classifies the product by representing the features of the product into vector of entire vocabulary of dataset is depicted. The architecture of neural network used for the prediction is described in this chapter. Mathematical equations on probability distribution, Softmax and why to apply log to softmax is formulated. + +In the seventh chapter, the model is trained to classification. The experimentation and analysis of model with different approaches and varying model parameters is conducted. + +The eight chapter, is research on creating a knowledge graph with natural language processing. \ No newline at end of file diff --git a/doc/images/lossinfo_tlr.png b/doc/images/lossinfo_tlr.png new file mode 100644 index 0000000..f15ee09 Binary files /dev/null and b/doc/images/lossinfo_tlr.png differ diff --git a/doc/index.tex b/doc/index.tex index 809b747..6d6eb01 100644 --- a/doc/index.tex +++ b/doc/index.tex @@ -66,13 +66,13 @@ preliminary/affidavit, % preliminary/abstract, % preliminary/acronyms, % chapters/introduction, % -chapters/chapter1,% chapters/chapter2,% chapters/chapter3,% chapters/chapter4,% chapters/chapter5,% chapters/chapter6,% -chapters/chapter7 +chapters/chapter7,% +chapters/chapter1% } \begin{document} @@ -99,14 +99,14 @@ chapters/chapter7 %--------------------------------------- \include{chapters/introduction.tex} -\include{chapters/chapter1} + \include{chapters/chapter2} \include{chapters/chapter3} \include{chapters/chapter4} \include{chapters/chapter5} \include{chapters/chapter6} \include{chapters/chapter7} - +\include{chapters/chapter1} \pagenumbering{roman} diff --git a/loss_tlr.png b/loss_tlr.png deleted file mode 100644 index 651e5bc..0000000 Binary files a/loss_tlr.png and /dev/null differ diff --git a/loss_tlr2.png b/loss_tlr2.png deleted file mode 100644 index dcf2c4b..0000000 Binary files a/loss_tlr2.png and /dev/null differ diff --git a/loss_tlr_5000.png b/loss_tlr_5000.png deleted file mode 100644 index c12e09e..0000000 Binary files a/loss_tlr_5000.png and /dev/null differ diff --git a/lossinfo.png b/lossinfo.png index 719ef2a..a14bf70 100644 Binary files a/lossinfo.png and b/lossinfo.png differ diff --git a/rm_clasificationmodel/TrainClass.py b/rm_clasificationmodel/TrainClass.py index 5d001b0..5813223 100644 --- a/rm_clasificationmodel/TrainClass.py +++ b/rm_clasificationmodel/TrainClass.py @@ -16,7 +16,7 @@ class Train(): self.rnn= RNN(self.inputSize, self.n_hidden, self.n_category) self.lr_low=0.0075 - self.lr_max=0.02 + self.lr_max=0.0125 self.learning_rate= 0.00000000000001 self.criterion = nn.NLLLoss() @@ -160,7 +160,7 @@ class Train(): output, loss = self.train(category_tensor, name_tensor) self.current_loss += loss # Print ``iter`` number, loss, name and guess - if epoch % 2500 == 0: + if epoch % 1000 == 0: guess, guess_i = self.data.categoryFromOutput(output) correct = '✓' if guess == category else '✗ (%s)' % category @@ -173,28 +173,48 @@ class Train(): correct, self.learning_rate)) - if epoch % 2500 == 0: + if epoch % 5000 == 0: if (math.isnan(self.current_loss)!=True): - self.all_losses.append(self.current_loss / 2500) + self.all_losses.append(self.current_loss / 1000) learning_rates.append(self.learning_rate) - times.append(self.helper.timeSince(start)) + times.append(self.helper.secondsSince(start)) self.current_loss = 0 else: break # Plot loss curve # Initialise the subplot function using number of rows and columns - figure, axs = plt.subplots(2,sharex=True) - figure.suptitle("Loss") - # plt.figure() - axs[0].plot(self.all_losses,learning_rates,'tab:orange') - axs[1].plot(self.all_losses,times,'tab:green') + # figure, axs = plt.subplots(2,sharex=True) + # figure.suptitle("Loss vs Learning rate and time with TLR") + # # plt.figure() + # axs[0].plot(self.all_losses,learning_rates,'tab:orange') + # axs[1].plot(self.all_losses,times,'tab:green') - for ax in axs.flat: - ax.set(xlabel='Loss') + # for ax in axs.flat: + # ax.set(xlabel='Loss') # plt.ylabel("Loss") # plt.xlabel('Learning rate') # # # Title and display the plot # ax1.set_title('Losses Vs Learning rate') + plt.figure(figsize=(10, 5)) + plt.subplot(1, 2, 1) + + plt.plot(learning_rates, self.all_losses, marker='o', linestyle='-') + plt.title('Learning Rate vs. Loss') + plt.xlabel('Learning Rate') + plt.ylabel('Loss') + # plt.xscale('log') # Log scale for learning rate for better visualization + plt.grid(True) + + # Create a plot for time vs. loss + plt.subplot(1, 2, 2) + plt.plot(times, self.all_losses, marker='o', linestyle='-') + plt.title('Training Time vs. Loss') + plt.xlabel('Training Time (seconds)') + plt.ylabel('Loss') + plt.grid(True) + + plt.tight_layout() + plt.savefig("lossinfo") \ No newline at end of file diff --git a/rm_clasificationmodel/helper.py b/rm_clasificationmodel/helper.py index ebaa2b2..94cf4e4 100644 --- a/rm_clasificationmodel/helper.py +++ b/rm_clasificationmodel/helper.py @@ -40,6 +40,11 @@ class Helper(): s -= m * 60 return '%dm %ds' % (m, s) + def secondsSince(self,since): + now = time.time() + s = now - since + return s + def plot(self,data,name): plt.figure() plt.plot(data)