

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Machine Learning (CS 5350/CS 6350) Due 29 Mar 2007
Note: Please submit the written aspects of assignments in postscript or PDF format only. I highly recom- mend you use LATEX to prepare the assignments. A solution will be posted here after the due date. See http://www.cs.utah.edu/classes/cs5350/handin.html for handin instructions.
Complete the following exercise from PRML: 13.6.
Bonus: 13.7.
There are two parts to the programming part.
The first programming part is to implement the Viterbi algorithm for an HMM. In the file hw4hmm.m, I have provided a shell for an HMM. This file contains transition probabilities, emission probabilities, and five test sequences that need to be labeled. Implement Viterbi and produce a sequence labeling for the five examples. I have also implemented a greedy search decoder, which you should also run on the five examples. Do the results differ? Why?
In this part of the assignment, we will make use of the MegaM tool (http://hal3.name/megam; there is also a compiled version in ~cs5350/bin/megam on CADE) to build a simple sequence labeler. MegaM implements both logistic regression and the perceptron algorithm, for both binary and multiclass classification problems. The format is identical to the FastDT format from HW2: each line in an input file is an example; the first column is the label (must be numeric) and the remaining columns list all active features. (I.e., all features are binary.) Given an input file train.data, you run:
megam multiclass train.data > train.weights
To produce weights. You can replace multiclass with multitron if you want to use a perceptron instead.
For making predictions, if test data is in test.data, you say:
Machine Learning (CS 5350/CS 6350) 2
megam -predict train.weights multiclass test.data > test.predictions
Now, test.predictions will contain one line for every example in test.data. The first column is the predicted class; the remaining columns are the probabilities for every class. (For this assignment you’ll only need to consider the first column.)
We will implement a two-iteration version of Searn. For this you may use whatever language you like. Even a shell script would be fine.
I have provided training data in the file train.data. This data does not contain any “structural” features
Step 1: Train a raw classifier on the training data and apply it on the test data. MegaM will report accuracies. Record them.
Step 2: Introduce structural features into the training data. We will use a first-order Markov model for simplicity. So, for each example in the training data, you will add a new feature corresponding to the label of the previous example. You can do this by appending the string “last-label-was-X” where “X” is whatever the last label was. Now, train a classifier on this data. Unfortunately, we can’t apply this directly to the test data. What we need to do is first predict the first test label, then use this to augment the features of the second test example. Then classify the second example and use the predicted label to add a feature to the third example and so on.
You can do this one of two ways. Either put each test example in its own file and go through one by one (this is the slow, but easy approach). Or, you can use the fact that MegaM can process examples one-at-a-time through a double-ended pipe. If you specify “-” (dash) as the filename to predict (i.e., megam -predict train.weights multiclass -) then it will read examples from stdin and write the results to stdout. You can use this to print the first example to MegaM, read the result, and then print another example. This method will be much faster, but if you’re not comfortable with opening pipes, feel free to do the first approach.
Once you’ve done this, record the accuracy of the model on the test data. Hint: it should be slightly higher than for step 1.
Step 3: This is the final step: the second iteration of Searn (after this, they’re all basically the same). What you’ll need to do here is first run your learned model on the training data, using either the one- example-per-file or the double-ended pipe method. This will give you predictions for each training example. We will do a “full Searn step” – i.e., use β = 1. That means that you will create a new version of the training data, but using the predictions rather than the true previous labels as features. Once you’ve done this, train a new classifier and run in on the test data. Record the accuracy. Hint: it should be slightly higher than for step 2.