In this part of the assignment I have developed a spell checker for Hindi which identifies and offer upto 3 suggestions for both real word and non-word errors. I have used Dr. Peter Norvig's code which is available at www.norvig.com/ngrams. I have made several other modifications considering that the words belong to Hindi.
I combined all the three Hindi corpus available to us. Then using the python program getSentence.py and getSentence2.py written by me, I extracted the sentences from the corpus. Then words were simply obtained from the corpus by using getWords.py and bigrams and trigrams were extracted from the Sentence data collected from the corpus using getGram2.py and getGram3.py. In case of the starting of sentence the tag "S within <>" was used.
Trial and effects -
After obtaining the unigrams and bigrams for Hindi, I ran the Peter Norvig's code to correct incorrect words. The result obtained are as follows: Accuracy - 20%
Obsevation -
There were some problems in the ground truth given to us. I modified them manually. However, this is not a necessary step but just an independent effort on my side.
Along with what was already given to us for testing, I pulled out a list of non-word errors and a list of sentences having real word errors. Thanks to Amit Sharma, who gave them to me. He had used the same for his AI project in which he designed a spell checker for Hindi. They all are present in my code folder (attached below) in the name of (test1.txt, test2.txt, test3.txt).
Error of a word: If the length of a word is more than 8, it is first segmented and then error is determined for the smaller words along with the original word. Irrespective of being a real word or a non word, a list of candidate words is generated and the probability of each is found out as the product of the likelihood and prior probability. Here, the prior probability is taken from the unigram data. The top 3 results are offered as suggestions.
Error in a sentence: A basic assumption that there is only 1 error in a sentence is made. Now if, there is any non-word in the sentence then it is corrected and the correct sentence is shown as suggestion. Otherwise, we generate a list of top 5 candidate words for all the real words in a sentence. Probability of a sentence is found based on the bigram and trigram data of each new sentence which has 1 modified word. The top 3 sentences are shown as suggestions.
Likelihood probability: It is the probability of an incorrect word given a correct word P(w/c). In general, (for English) we will look at a large set of mis-spellings and their corrections and from that we will built a set of possible edits and accordingly assign a probability for an edit. Dr. Norvig used 1587 unique edits for English which is only 26 characters. It we are supposed to follow the same procedure in Hindi which has about 60 characters we would need almost three times the data available for English. However, it turns out that we don't even 1/3rd of the data available to us. Therefore, the same likelihood probability for all cases, later on adding the phonetic rules.
Phonetic Rules: As phonetic information is expected to be of importance for Indian languages, I try to use the comprehensive, table-driven phonetic code mechanism. The rules allow specifying, for example, that क sounds like ख, क like क्, कि like की, कु like कू, etc. This turns out to be the single most important factor for improving the performance for Hindi. Apart from what already was provided by aspell, I added some more rules (न|ं ब|व) based on my knowledge and this link.
Other tweaks:
Test1 (Mailed to us by Prof. Mukerjee): Accuracy = 81.5%, With Aspell, accuracy = 64%
Test2 (Another list of word errors): Accuracy = 85%, With Aspell, accuracy = 75%
Test3 (Real word errors in sentences): Accuracy = 33%
Definition of Accuracy: If for a test case the correct spelling is found in the top 3 suggestions then it is counted in correct, otherwise it is counted in incorrect. Accuracy is report using the formula correct/(correct+incorrect).
There were some errors like: