Пример #1
0
std::string Manager::OutputNBest()
{
	arcLists.Sort();

	boost::unordered_set<size_t> distinctHypos;

	TrellisPaths<TrellisPath> contenders;
	m_search->AddInitialTrellisPaths(contenders);

	long transId = GetTranslationId();

	// MAIN LOOP
	stringstream out;
	//Moses2::FixPrecision(out);

	size_t maxIter = system.options.nbest.nbest_size * system.options.nbest.factor;
	size_t bestInd = 0;
	for (size_t i = 0; i < maxIter; ++i) {
		if (bestInd > system.options.nbest.nbest_size || contenders.empty()) {
			break;
		}

		//cerr << "bestInd=" << bestInd << endl;
		TrellisPath *path = contenders.Get();

		bool ok = false;
		if (system.options.nbest.only_distinct) {
			string tgtPhrase = path->OutputTargetPhrase(system);
			//cerr << "tgtPhrase=" << tgtPhrase << endl;
			boost::hash<std::string> string_hash;
			size_t hash = string_hash(tgtPhrase);

			if (distinctHypos.insert(hash).second) {
				ok = true;
			}
		}
		else {
			ok = true;
		}

		if (ok) {
			++bestInd;
			out << transId << " ||| ";
			path->OutputToStream(out, system);
			out << "\n";
		}

		// create next paths
		path->CreateDeviantPaths(contenders, arcLists, GetPool(), system);

		delete path;
	}

	return out.str();
}
Пример #2
0
void OutputFeatureScores( std::ostream& out, const TrellisPath &path, const FeatureFunction *ff, std::string &lastName )
{
  const StaticData &staticData = StaticData::Instance();
  bool labeledOutput = staticData.IsLabeledNBestList();

  // regular features (not sparse)
  if (ff->GetNumScoreComponents() != ScoreProducer::unlimited) {
    if( labeledOutput && lastName != ff->GetScoreProducerWeightShortName() ) {
      lastName = ff->GetScoreProducerWeightShortName();
      out << " " << lastName << ":";
    }
    vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer( ff );
    for (size_t j = 0; j<scores.size(); ++j) {
      out << " " << scores[j];
    }
  }

  // sparse features
  else {
    const FVector scores = path.GetScoreBreakdown().GetVectorForProducer( ff );

    // report weighted aggregate
    if (! ff->GetSparseFeatureReporting()) {
      const FVector &weights = staticData.GetAllWeights().GetScoresVector();
      if (labeledOutput && !boost::contains(ff->GetScoreProducerDescription(), ":"))
        out << " " << ff->GetScoreProducerWeightShortName() << ":";
      out << " " << scores.inner_product(weights);
    }

    // report each feature
    else {
      for(FVector::FNVmap::const_iterator i = scores.cbegin(); i != scores.cend(); i++) 
	out << " " << i->first << ": " << i->second;
	/*        if (i->second != 0) { // do not report zero-valued features
	  float weight = staticData.GetSparseWeight(i->first);
          if (weight != 0)
	  out << " " << i->first << "=" << weight;
	  }*/
    }
  }
}
Пример #3
0
void GetOutputFactors(const TrellisPath &path, vector <const Factor*> &translation){
	const std::vector<const Hypothesis *> &edges = path.GetEdges();
	const std::vector<FactorType>& outputFactorOrder = StaticData::Instance().GetOutputFactorOrder();
	assert (outputFactorOrder.size() == 1);

	// print the surface factor of the translation
	for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--)
	{
		const Hypothesis &edge = *edges[currEdge];
		const Phrase &phrase = edge.GetCurrTargetPhrase();
		size_t size = phrase.GetSize();
		for (size_t pos = 0 ; pos < size ; pos++)
		{
			
			const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[0]);
			translation.push_back(factor);
		}
	}
}
Пример #4
0
void OutputAlignment(OutputCollector* collector, size_t lineNo , const TrellisPath &path)
{
  if (collector) {
    OutputAlignment(collector,lineNo, path.GetEdges());
  }
}