

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!


Problem Set 2 and Lab 1 See calendar for due dates
Problem Set 2
really well there's been uh actually some pretty interesting interesting topics that i've had i've had things from uh tax reform to baseball to fishing those are the three i've participated in no okay yeah yeah yeah i- i think uh there could be a lot of peo- i thi- people close this is really we're well the problem is that gas at a dollar a a gallon These transcripts have already been preprocessed to remove punctuation (with the exception of the hyphens which indicate a word that was not fully pronounced), and case differences. In this lab, you should write the following function to build your models:
function [models, counts] = ngram(order, filename, laplace) % Generate an n-gram and appropriate counts of specified order % inputs: % order - build up to order N grams (e.g. order=2 --> unigram, bigram) % filename - file containing training text
% laplace - true|false: Use Laplace (additive) smoothing. % outputs: % models - cell array of probability models models{k} is the % order k model % counts - cell array of counts (similar)
Prior to Matlab 2008b, there is no intrinsic support for hash tables, which is an appropriate data structure for building an N-grams and counts. Conceptually, for the trigram “riding a bike,”, a natural representation would be to construct a three level hash table: hashtable[riding][a][bike], and it is suggested that you may wish to use this type of data structure when coding your solution. As Matlab permits one to integrate Java code, you can use a Java HashMap to create appropriate data structures for your code. Using Java in Matlab is reasonably straight forward, here are a few tips that can make life easier:
fopen, fclose, fgetl, strtok
Write the following function to evaluate the perplexity of your model.
function pp = perplexity(model, test_file) % Return the estimated perplexity of model as evaluated by test_file