print "Usage: "
    print "    ./label.py training_file test_file"
    sys.exit()

(train_file, test_file) = sys.argv[1:3]

print "Learning model..."
solver = Solver()
train_data = read_data(train_file)
solver.train(train_data)

print "Loading test data..."
test_data = read_data(test_file)

print "Testing classifiers..."
scorer = Score()
Algorithms = ("Simplified", "HMM VE", "HMM MAP")
Algorithm_labels = [ str(i+1) + ". " + Algorithms[i] for i in range(0, len(Algorithms) ) ]
for (s, gt) in test_data:
    outputs = {"0. Ground truth" : gt}
        
    # run all algorithms on the sentence
    for (algo, label) in zip(Algorithms, Algorithm_labels):
        outputs[label] = solver.solve( algo, s) 

    posteriors = { o: solver.posterior( s, outputs[o] ) for o in outputs }
    
    Score.print_results(s, outputs, posteriors)
        
    scorer.score(outputs)
    scorer.print_scores()
    sys.exit()

(train_file, test_file) = sys.argv[1:3]

print("Learning model...")
solver = Solver()
train_data = read_data(train_file)
prob_all, x, y = solver.train1(train_data)
#print(prob_all, x, y)
start_p, transition, tags_list = solver.train(train_data)

print("Loading test data...")
test_data = read_data(test_file)

print("Testing classifiers...")
scorer = Score()

Algorithms = ("Simple", "HMM", "Complex")
Algorithm_labels = [
    str(i + 1) + ". " + Algorithms[i] for i in range(0, len(Algorithms))
]
for (s, gt) in test_data:
    emission = solver.emission_probability(s, train_data, tags_list)
    outputs = {"0. Ground truth": gt}

    # run all algorithms on the sentence
    maxx = []
    for (algo, label) in zip(Algorithms, Algorithm_labels):
        outputs[label], proba = solver.solve(algo, s, prob_all, tags_list,
                                             start_p, transition, emission)
        maxx.append(proba)
예제 #3
0
if len(sys.argv) != 3:
    print "Usage: python label.py training_file test_file"
    sys.exit()

(train_file, test_file) = sys.argv[1:3]

print "Learning model..."
solver = Solver()
train_data = read_data(train_file)
solver.train(train_data)

print "Loading test data..."
test_data = read_data(test_file)

print "Testing classifiers..."
scorer = Score()
Algorithms = ("Naive", "Sampler", "Max marginal", "MAP", "Best")
for (s, gt) in test_data:
    outputs = {"0. Ground truth" : [[gt,], []]}

    # run all algorithms on the sentence
    for i in range(0, len(Algorithms)):
        outputs[ str(i+1) + ". " + Algorithms[i] ] = solver.solve(Algorithms[i], s)

    # compute posteriors for each solution
    posteriors = { algo: [ solver.posterior(s, output)  for output in outputs[algo][0] ] for algo in outputs }
    

    Score.print_results(s, outputs, posteriors)

    scorer.score(outputs)