HMM for Address Validation


1. To build a HMM system to validate address.

2. Find optimal state sequence for the given observation.

Tool used:

To accomplish the mentioned objectives I stated to search for HMM implementation tools in internet. To my excite I found many tools popping on my screen but unfortunately none of them worked for me. So I have decided to sit and design my own tool to build hmm system for address validation.



To build an HMM system different state (label) has to be defined for the observations. In our case different states could be street, city / town, state, country.

State 1 –> Street

State 2 –> City / Town

State 3 –> State

State 4 –> Country

Observation and legends:

Primarily Hmm system (say lambda) has three important parameters lambda = (A,B,pi)

A –> The state-transition probability matrix.

B –> Observation probability distribution:

pi –> The initial state distribution

So we need to calculate all these probabilities from the Training corpus.

Training corpus should contain all the states as mentioned above in the form of observation. while training the system manual work is mandatory so in training corpus we should manually specify each and every observation its state and its sequence . I manually designed my own corpus training format such way that it could be process by my HMM system to training itself and compute the parameters.

Training corpus format

1:Ringsheimer Str.3 
4:the  Netherlands
1:Chemin d’avat  

Numbers represent the state –colon followed by a string represents the observations for that particular state.

Symbol # denote the end of sequence, this could be used for comments also.

To train the system I have considered 20 addresses as train corpus which is in above mentioned format.

Steps to execute:

It is advisable to work from command prompt event though there is a jar (executable file)

Go the directory and type the following command  java –jar “E:AssignmentsAssign -5 HMMHMM.jar"  (if the file is in some other directory the give the correct path). You will get a window(HMM for address validation ) opened.


Click Train HMM button and select Training corpus.


You can see some data arrived at command prompt. From the training corpus, it broke the strings into tokens and separate them on basis of their state.


Then again select the window again click Compute Observation Probability button and come back to command prompt.


Observation matrix will be computed and it will display in prompt. Then click Compute Transaction Probability button and give the data that are asked in command prompt.


State Transaction Matrix will be computed and it will be displayed.


Now it time to test . Click Test HMM : Estimate (testing the observation) button and enter the data that are asked in command prompt. for instance give observation and sequence as shown below.

Observation as : Kerkweg ZEDDAM the Netherlands

Sequence : 1 2 3 4 hmm8It will compute and validate the state sequence and observation.


Now come back to window and click Test HMM: Finding the Optimal sequence button, then select TestHMM2 corpus. Optimal state sequence will be computed and it will be displayed.


optimalhmmYou can open the TestHMM2 corpus and compare the result that displayed as optimal sequence in command prompt.



Different type of inputs where given to system to test the performance. For instance: To test optimal sequence  Unknown observation where given as the input Kumarappa st Chennai Tamilnadu India and sequence Transaction as 1 2 3 4

After computing , It say valid sequence  but Observations Invalid…


Even though the observation (Kumarappa st Chennai Tamilnadu India) is valid and as it is unknown to system, it considered as Invalid observation. In case of  sequence as it match with initial probability it say it is valid sequence.


It is both quality and quantity of the training corpus determine the accuracy of test data, for demo purpose I have used 20 addresses as my training corpus but for real time situation more the training , more the gain. In my experiment I was able find best optimal sequence for observation which is known to system. And also to validate the observation and sequence which is also known to system.

Note: I have not discussed about the program code of my HMM tool since it is not the ultimate objective in this experiment. You can download the file to try out experiment or to look the program code logic.

Download : HMM for Address Validation

Post a Comment

Your email is never published nor shared. Required fields are marked *