示例#1
0
/// Make some consistent parse decision using the Classifier and an oracle.
/// If the Classifier makes a correct decision, then we make that.
/// Otherwise, we use an oracle to randomly choose
/// a consistent decision to perform.
void Parser::make_decision_with_oracle(ParseState& state) {
	Actions actions = state.legal_actions();
	assert(!actions.empty());

	Action action = this->best_action(state, actions).first;

	if(state.is_consistent(action)) {
		Debug::log(5) << "Correctly performing: " << action.to_string() << "\n";
		stats::correct_actions_add(1);
	} else {
		Debug::log(5) << "Instead of " << action.to_string() << ", ";

		actions = state.consistent_actions();
		assert(!actions.empty());
		if (parameter::parse_left_to_right() || parameter::parse_right_to_left()) {
			assert(actions.size() == 1);
		}
		// Randomly choose some consistent action.
		action = actions.at((unsigned)(drand48() * actions.size()));

		Debug::log(5) << "oracle chose " << action.to_string() << "\n";
	}
	bool ret = state.perform(action, true);
	assert(ret);
	stats::total_actions_add(1);

	// FIXME: Don't necessarily use _parse_span_chart.
	_parse_span_chart.subtract(SpanItem(action), _parse_prc, _parse_rcl, _parse_cbs);
	Debug::warning(__FILE__, __LINE__, this->current_scores());
}
示例#2
0
/// Make some consistent parse decision.
/// Randomly choose some consistent action, and perform it.
/// \param state The state in which the parse decision should be made.
/// \todo Allow classifier to confidence-rate actions, and choose highest rated
/// action to perform?
void Parser::make_consistent_decision(ParseState& state) {
	assert(!parameter::treebank_has_parse_paths());

	Actions actions = state.consistent_actions();
	assert(!actions.empty());

	if (parameter::parse_left_to_right() || parameter::parse_right_to_left()) {
		assert(actions.size() == 1);
	}
	
	// Randomly choose some consistent action.
	Action action = actions.at(ParsePathRandom.get(actions.size()));

	//Action action = this->best_action(state, actions);

	Debug::log(5) << "Performing: " << action.to_string() << "\n";
	state.perform(action);

	// FIXME: Don't necessarily use _parse_span_chart.
	_parse_span_chart.subtract(SpanItem(action), _parse_prc, _parse_rcl, _parse_cbs);
}
示例#3
0
/// Make some consistent parse decision using the Classifier.
/// Choose the highest confidence legal consistent action.
/// Only is no legal consistent action exists do
/// we choose an illegal (consistent) action.
/// \param state The state in which the parse decision should be made.
void Parser::make_consistent_decision_with_classifier(ParseState& state) {
	assert(!parameter::treebank_has_parse_paths());

	Actions actions = state.consistent_legal_actions();
	Action action;

	// If some consistent legal action exists,
	if (!actions.empty()) {
		action = this->best_action(state, actions).first;
		Debug::log(5) << "Performing: " << action.to_string() << "\n";

		bool debugout = false;
		double conf = this->confidence(state, action);
		if (conf <= -5) debugout = true;
		//if (conf <= -10) debugout = true;

		if (debugout) Debug::log(3) << "PRE  (conf=" << conf << "):  " << state.to_string() << "\n";
		bool ret = state.perform(action, true);
		assert(ret);
		if (debugout) Debug::log(3) << "POST (conf=" << conf << "): " << state.to_string() << "\n";
	} else {
		actions = state.consistent_illegal_actions();
		assert(!actions.empty());

		if (parameter::parse_left_to_right() || parameter::parse_right_to_left()) {
			assert(actions.size() == 1);
		}
	
		// Randomly choose some consistent (illegal) action.
		action = actions.at((unsigned)(drand48() * actions.size()));

		Debug::log(3) << "Performing illegal action: " << action.to_string() << "\n";
		bool ret = state.perform(action);
		assert(ret);
	}

	// FIXME: Don't necessarily use _parse_span_chart.
	_parse_span_chart.subtract(SpanItem(action), _parse_prc, _parse_rcl, _parse_cbs);
}