Introduction: How to Make an A.I. Part 4 - the Homophone Problem

About: I am a Maker, Builder and Developer. My A.I. / Chat Bot code is used in my Robot, which can be seen at WWW.ZoeTheRobot.Net. My Robot has her own YOU TUBE CHANNEL - "Zoe the Robot"

The other day I was talking with my A.I., and I said to

it, “I am going upstairs to dinner, we are having STEAK”.

However, the Speech Recognition (SR) software interpreted this as “… we are having STAKE”

I ran into a similar (but different) problem earlier when I was talking about a photograph, and I said the word “PICTURE”. The SR software interpreted this as “PITCHER”

The fix for this was a simple retraining of SR software. (Or maybe my pronunciation)

But when I say the words STEAK or STAKE, I pronounce them exactly the same way, and retraining the SR software will not help in cases like this.

Step 1:

One idea to solve the “Homonym Problem”.

I have to look at the word “in context” to determine which spelling to use. The human brain does this quite easily, and you don’t even know that you are doing it.

This means that other words in a sentence are examined, and your brain decides which spelling looks best. Now, how do I do this in code?

My A.I. program parses a sentence into an array of individual words using the Visual Basic (VB) “Split” function. [ MyArray = Split(InputSentence, “ “) ]

Each word in the array can be checked to see if it is a possible homonym by looking in a database table containing a list of homonyms.

Of course, creating another table means that we will need to fill it with data, and also we will need to be able to maintain the data in the table as well.

A self learning subroutine can be built later to scan a bunch of text, looking for words in my Homonym table, and capture other “context” words. Hmmmmm, maybe several tables are needed…

Writing these “Instructables” helps me “reason out” a solution to a programming challenge.

Step 2:

Structure of HomonymContext table.

My first idea was a table containing words, alternate spellings, and “Context” words. The idea was to search a sentence containing a homonym, for other words that gives the “context”, so that the program can determine which spelling to use. The table also contains a column named “WordDef” to hold the definition of the word, which is more for the human maintaining the table than the A.I. code.

To search each word, I can use VB code and SQL code like…

For each Word in MyArray

Query = "Select Word from tblHomonynContext where word = '" & word & "'"

if this query returns a result, then the word is a homonym

Next

This is just pseudo code at this point – I have not yet written the exact code, or figured out all of the details. But feel free to take my idea, and implement it using your own favorite programming language.

Step 3:

If your input sentence contains a homonym, you can now

execute VB code that will check the other words in your sentence, with the context words in the query results.

You could also do this all in a SQL stored procedure, which may execute faster.

The VB “InStr()” function will return a number greater than zero, if one string is contained within another string, or it will return zero, it the string is NOT contained in the other.

Instr() actually returns the position of the contained string. If you just want to know if String1 contains String2, you can use code like “If InStr(String1 , String2) > 0 …”

You will have to build this code in your favorite programming language.

The HomonymContext table is not a very good design. It has a lot of repeated data, and this is considered to be "Non-Normalized" by database designers. A better way to implement this functionality would be to use two tables, in a parent-child relationship. One table (The Parent) would hold a list of homonyms , their definitions, and also a Row ID. This Row ID is used as a key to the "Child table" which would contain the words and their context words.

This would be easier to query ( and to maintain) than my original design.