PassageParser

class tupa.parse.PassageParser(passage, *args, **kwargs)[source]

Bases: tupa.parse.AbstractParser

Parser for a single passage, has a state and optionally an oracle

Attributes Summary

accuracy_str
num_tokens

Methods Summary

check_loop() Check if the current state has already occurred, indicating a loop
choose(true[, axis, name])
correct(axis, label, pred, scores, true, …)
evaluate([mode])
finish(status[, display, write, accuracies])
generate_descending(scores)
get_true_actions()
get_true_label(node)
init()
label_node([action])
parse([display, write, accuracies])
parse_internal() Internal method to parse a single passage.
predict(scores, values[, is_valid]) Choose action/label based on classifier Usually the best action/label is valid, so max is enough to choose it in O(n) time Otherwise, sorts all the other scores to choose the best valid one in O(n lg n) :return: valid action/label with maximum probability according to classifier
verify(guessed, ref) Compare predicted passage to true passage and raise an exception if they differ :param ref: true passage :param guessed: predicted passage to compare

Attributes Documentation

accuracy_str
num_tokens

Methods Documentation

check_loop()[source]

Check if the current state has already occurred, indicating a loop

choose(true, axis=None, name='action')[source]
correct(axis, label, pred, scores, true, true_keys)[source]
evaluate(mode=<ParseMode.test: 3>)[source]
finish(status, display=True, write=False, accuracies=None)[source]
static generate_descending(scores)[source]
get_true_actions()[source]
get_true_label(node)[source]
init()[source]
label_node(action=None)[source]
parse(display=True, write=False, accuracies=None)[source]
parse_internal()[source]

Internal method to parse a single passage. If training, use oracle to train on given passages. Otherwise just parse with classifier.

static predict(scores, values, is_valid=None)[source]

Choose action/label based on classifier Usually the best action/label is valid, so max is enough to choose it in O(n) time Otherwise, sorts all the other scores to choose the best valid one in O(n lg n) :return: valid action/label with maximum probability according to classifier

verify(guessed, ref)[source]

Compare predicted passage to true passage and raise an exception if they differ :param ref: true passage :param guessed: predicted passage to compare