param = [0 for i in range(24)] # print 'Profiling started' # prof = cProfile.Profile() # prof.enable() memm = MEMM( data, tag, all_tag, param, wsj.tagged_sents()[:no_of_sentences], [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14], 0, ) memm.train() print "For", memm.num_calls_cost, "calls to cost total time taken is", memm.tot_time_cost print "Per call avg time taken is", memm.tot_time_cost / memm.num_calls_cost print "For", memm.num_calls_gradient, "calls to gradient total time taken is", memm.tot_time_gradient print "Per call avg time taken is", memm.tot_time_gradient / memm.num_calls_gradient # dt1 = datetime.datetime.now() # print 'before training: ', dt1 # memm.cost(param) # dt2 = datetime.datetime.now() # print 'after training: ', dt2, ' total time = ', (dt2 - dt1).total_seconds() # prof.disable() # s = StringIO.StringIO() # sortby = 'cumulative'
def f9(x, y): return round(random.random()) def f10(x, y): return round(random.random()) if __name__ == '__main__': data, tag = create_dataset() tag1 = list(set(tag)) punctuations = ['.', ',', ':', ';', '\"', '\'', '``', '\'\''] all_tag = [] for t in tag1: if t not in punctuations: all_tag.append(t) param = [0 for i in range(10)] print 'Profiling started' # prof = cProfile.Profile() # prof.enable() memm = MEMM(data, tag, all_tag, param, [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10], 0) memm.train() # prof.disable() # s = StringIO.StringIO() # sortby = 'cumulative' # ps = pstats.Stats(prof, stream=s).sort_stats(sortby) # ps.print_stats() # print s.getvalue()