AI-powered Spell-check and Grammar-check in Business Applications
By: Pranay Dave
Tags: Business Apps, Business Value, Artificial Intelligence, Machine Learning

Wud yu read this artcle if it was ful of speling mistaks ? Ofcourse not. Incorrect spelling are not only limited to personal life, but unfortunately also exists in business applications.

Now-a-days most of our writing is via a word processor like word or using mobile phones. And they already have features built in to highlight spelling mistakes and even correct them using autocorrect feature

However in the business world, there are many applications such as master data management, call-center applications, resource planning, customer relation applications etc.., which do not have any autocorrection features. This allows spelling mistakes to creep into the system and it creates many problems while using these applications

Let us look at some of the common problems scenarios in businesses

Incorrect text in master data

Master data , such as product master data, customer master data and others are a key piece of information necessary for smooth working of business applications. Generally master data has a key, attributes and description. For example a product master data will have the product identifier, attributes (such as color, weight, size etc..) and product description. Out of all these fields, the product description is one of the most important as it is the only field which gives information about what the product really is. Also it is highlighted on e-commerce websites and is one of the first thing seen by prospective buyers

As the origin of the product description data is from humans, it is prone to mistakes. These mistakes occur simply because of human nature, attempt to find abbreviation for long product names , or trying to combine two different words into one

Some of real-life examples of such mistakes in product names are PINK NEW BAROQUECANDLESTICK CANDLE, PINK OVAL JEWELLED MIRROR, LUNC BAG RED RETROSPOT, PAPER CHAN KIT 50’S CHRISTMAS, LIGHT GARLAND BUTTERFILES PINK

When such mistakes are highlighted on company websites, it can put off clients from buying the products

Wrong spelling, words and grammar in business communications

Business communication mainly involves B2C (business to client), B2B (Business to business) and internal communications. With rise in different communication channels such as classic email, web-chat, support service , social media etc.., the amount of text being communicated has gone up in recent years. This means that the chances of errors in spelling, words as well as grammar has also gone up

Many of the business applications , such as web support services or B2B portals , might not have the basic orthograph or grammar check. Also there are many cases where automated spell checkers would not be able to catch the errors. Here are some real-life examples of business communications where spell check was either not active or did not work

Let’s us meet tomorrow morning an then we can present you our offering

We will send you male with detail description on how to solve the issue

We will dedicate tile to understand your pan point

With the ever increasing workload and stress, not all humans proof check or re-read all communications.

Such mistakes does not create a good impression with clients, customers as well as internal employees and sometime can lead to losing business, trust or cultural non-acceptance. Just by having an end-note “Please excuse for any typos” would not help as it conveys the message that the person is not very meticulous and is more of a sloppy person.

Unchecked AI generated text

There is a rising number of AI based applications which generate text such as automated personalized emails or chatbots. Generally one would expect that spelling or grammar mistakes would not occur in such automated text generation, but there are chances of such errors.

The main reason for an AI generated text to go wrong is insufficient training data or incorrectly parameterised AI architecture

So generally it is good idea to put an AI based spell and grammar check on top of AI generated text. You can think this as an AI program controlling another AI program

Making machine learn to predict correct spellings and words

Can a machine learn how to spell a word correctly within a given context ? For Example can it recognize the error in the word male in the sentence : “We will send you male with detail description on how to solve the issue” . The answer is yes.

AI can be used to go beyond what existing spell-checkers can provide. They can not only identify spelling mistakes, but also identify correctly spelled words but used in a wrong context.

At the center of advanced spell-checking or autocorrection lies algorithm to recognize sequential pattern of characters or words. For example the word “sequential” is orthographically correct but the word “sequentialy” is mis-spelled even though the first ten characters (“sequential”) are correct.

AI programs are very good at sequential pattern detection and can help differentiating between the right pattern (“sequentially”) from a wrong pattern (“sequentialy”).

The type of AI architecture which works on sequential pattern data are called Recurrent Neural network (RNN) or Long Short Term Memory (LSTM). Let’s look at these techniques with help of an example to identify a right character which follows a sequence of characters. As an example given the pattern “sequentiall”, it can identify that the next letter would be “y” and not anything else.

A simplified representation of RNN or LSTM would be an input sequence and an output sequence. For example, we can train the RNN to have input as “sequentiall” and output as “y”. The input is fed into neurons, which are represented by circles.

Simplified representation of RNN or LSTM

We need to train our network on various sentences and words, for which we need data. One possibility is to take already available correct text such as from Wikipedia or any other sources. For each line in the source, break it up into various lines in order to use it for RNN or LSTM training purposes.

Once the RNN or LSTM is trained on sufficient data, it will create a weight matrix for each letter. This weight matrix is kind of latent representation for each letter. It represents what the artificial intelligence has learned about each letter.

The size of weight matrix is number of characters * number of features. The number of characters is unique number of characters occurring in text corpus used for training. The number of features is up to us to select. If for example number of features is chosen to be 128, then each character will be represented by a bunch of 128 weights.

This weight matrix can be seen as “understanding” which AI developed looking at the text corpus. Here is the weight matrix created after training a RNN or LSTM based on randomly selected Wikipedia data (around 100 GB). The rows represent different characters and the columns represent the 128 weights for each character. Lower the weight, more black is the color. Higher the weight, more blue is the color

AI brain internal representation is a weight matrix

The weight matrix is an internal representation of what AI has learned about each character. This matrix is a bit difficult to understand by humans. However we can apply some data science techniques to this matrix in order to understand what AI has learned

One such technique we can apply is called clustering, which will group together characters which have similar weights. After applying clustering algorithm (called K-Means) to weight matrix , we see the following clusters

AI learns to differentiate between alphabets, numbers and punctuations

These cluster results are very interesting. Just by looking at the corpus text, AI has learned to differentiate between alphabets, numbers and punctuations. This shows the self-leaning power of AI and how it can think like human by just looking at the text

This “knowledge” of characters represented by weights is used in the RNN or LSTM architecture to predict the character. This process is shown here

RNN or LSTM process

For each character , the weight matrix is read and hidden state corresponding to the neuron is updated. The hidden state for one neuron serves as input to the next neuron. The process continues with the output of last neuron is used to predict the last letter.

The architecture can be used in a similar fashion to predict the next word. Example the input can be “we will dedicate” and the architecture can predict the word “time” has more probability to occur next rather than the word “tile”

Integrating business applications with AI model

So once we have our AI trained to predict correct spellings or next word, there are different ways by which we can leverage it. One of the common ways is to develop an API which wraps the AI logic (also called as model) and exposes it via an API service.

Any business application which would like to use spell-check or word check can make a call to the API and see if the predicted word is equal to word in the business application. For example the business application can send the word “sequentialy” and the API can send back response that the word would be probably misspelled as well send back the possible right word “sequentially”.

Based on the business application there could be different possible scenarios on how to leverage the AI model

Concluding thoughts

Spell-checks, grammar-checks, autocorrection should not only be restricted to mobile or productivity applications. It is very important that all these basic sanity checks are also integrated into business applications. Various state of the art AI algorithms and techniques can be used to achieve this and ensure that you have a smooth business functioning as well as to have a good external image

Hope you have enjoyed reading this article.