Kainos and AI: One Simple Tool to Improve the Efficiency of your Machine Learning Systems

Date posted
18 April 2019
Reading time
12 Minutes
Conor McCormick

Kainos and AI: One Simple Tool to Improve the Efficiency of your Machine Learning Systems

Have you ever been a position where you didn't have enough data? Would that chatbot, recommendation system or fraud detector become possible if more data were available? If so, keep reading??? ??this blog is for you!

Background

The Text Augmenter (henceforth referred to as TA) is a program which can be used to augment text records (generate new records from existing records) in order to supply Machine Learning projects with additional training data. I used research done by Jake Young as a jumping off point for TA. I wanted to use the methods that he had come up with but in a slightly more user-friendly way to be used in the team.

Now you know why I made this, so what does this actually look like?

 /><figcaption>This is the original data value I provided.<br><br></figcaption></figure>



<figure ><img src=Jake's article??? ??augmenting the data based on using synonyms, and translations.

Synonym Augmentation

This works by breaking down each of the rows of text into individual words, then finding the keywords and replacing them with synonyms to create a new data record. This process is explained using the following flow chart:

 /></figure>



<p>Due to the nature of Synonym Augmentation, the number of results can vary wildly depending on the length of the original values. If longer sentences are used, then there will be more words to augment, and thus a larger return of data.</p>



<p><strong>Validation:</strong> To ensure that the results of the Synonym Augmentation are usable for any given project, the user can specify a 'blacklist' which is a list of words that the user defines which will be ignored by the Augmentation function.</p>



<p><em>For example, the word 'one' gives 5 different data records. Using the blacklist means that none of these would show up in the augmented dataset. This is useful as it means that certain things that shouldn't be augmented, for example words in the name of a law will not be augmented.</em></p>



<h3>Translation Augmentation</h3>



<p>This takes the data records and translates them into a different language then back into English using <a rel=Microsoft Azure's translation API. It does this for five languages chosen to mangle the syntax of the sentence. This process is explained using the following flow chart:
 /></figure>



<p>As each data value will be translated into five different languages, this function will always give a 500% return.</p>



<p><strong>Validation: </strong><a rel=Universal Sentence Encoder is used to ensure that the augmented data records are close enough to the original values. This works by finding the 'cosine similarity' of the augmented value to the original value. The user is able to set a threshold for this similarity and any augmented values that fall outside of the threshold.

Benchmarking

TA has a built-in feature for benchmarking the original dataset against the augmented datasets using a variety of common Machine Learning algorithms. It uses the following:

Stochastic Gradient Descent [SGD]
Gaussian Na??ve-Bayes [GNB] *
Complement Na??ve-Bayes [CNB]
Linear Regression
Decision Tree Classifier [DTC] *
Multi-Layer Perceptron [MLP] *
* this classifier is used in the Flask application

The augmentation function splits each of the datasets up into training and test values, then trains the classifier and makes predictions. It then gives the user feedback about the classification: accuracy value, classification report and confusion matrix. It does this for all of the datasets??? ??the original and the datasets created by the two methods of augmentation??? ??and displays comparisons between them.

 /><figcaption>The output from the Flask application when benchmarking is performed.<br></figcaption></figure>



<h2><strong>How Can TA Be Used?</strong></h2>



<p>There are three different ways to use it, to allow for flexibility for users with differing levels of technical knowledge:</p>



<p><a rel=Python script
Currently, the main way we use TA is via the main Python script running on the Terminal. This method allows for the use of all of the selected benchmarking classifiers, and is the fastest way of using TA.
 /><figcaption>A screenshot from the python script.<br></figcaption></figure>



<p><a href=Flask application
This project gave me my first ever opportunity to use Flask, a web framework written in Python. Using this, I built a webpage to house the functions for TA. Doing this allowed me to gain a better understanding of endpoints and requests having never really experienced much related to the web. I'm currently unsure about whether or not this will be hosted as a usable web page, or whether the primary method for use will be one of the other methods. The downside of this, is that the number of machine learning classifiers used for benchmarking bulk up the tool, and thus I have restricted the benchmarking to only three classifiers.
 /><figcaption>A screenshot from the Flask application.<br></figcaption></figure>



<p><a href=Jupyter Notebook
An implementation of the Python script has been created as a Jupyter Notebook. This is separated into cells containing each of the functions, and an explanation of what they do and how to use them.
 /><figcaption>A screenshot from the Jupyter Notebook.<br></figcaption></figure>



<h2>Conclusion: Using TA For A Project</h2>



<p>After having completed TA recently, we have began using it in the team's projects as a means to create more testing data in order to prove the effectiveness of it.</p>



<p><strong>The Effectiveness of TA<br></strong>TA took in a dataset of 11000 values, and returned an augmented dataset of 500000 values (4545% return). This means that the training for the algorithm was able to be more efficient and return better results.</p>



<p>We are planning to use TA in the future to assist in the development of any of our projects that this would be beneficial to.<br></p>

About the author

Conor McCormick