Search in sources :

Example 51 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class ScoreNormalizationFilter method addNumAnswersFeature.

/**
	 * Adds the number of factoid answers from the same extractor as a feature
	 * to the instance.
	 */
private static void addNumAnswersFeature(MutableInstance instance, Result result, Result[] results) {
    // get number of factoid answers
    int numFactoid = 0;
    //		String extractor = result.getExtractionTechniques()[0];
    for (Result r : results) if (r.getScore() > 0 && r.getScore() < Float.POSITIVE_INFINITY)
        //				if (r.extractedWith(extractor))
        numFactoid++;
    Feature feature = new Feature(NUM_ANSWERS_F);
    instance.addNumeric(feature, numFactoid);
}
Also used : Feature(edu.cmu.minorthird.classify.Feature) Result(info.ephyra.search.Result)

Example 52 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class ScoreNormalizationFilter method preserveOrderResorting.

/**
	 * Reassigns the normalized scores for each extraction technique to ensure
	 * that the order suggested by the original scores is preserved.
	 * 
	 * @param results array of <code>Result</code> objects
	 * @return array of <code>Result</code> objects with new normalized scores
	 */
public Result[] preserveOrderResorting(Result[] results) {
    List<Result> allResults = new ArrayList<Result>();
    // get answers by extractors
    Hashtable<String, ArrayList<Result>> allExtracted = new Hashtable<String, ArrayList<Result>>();
    for (Result result : results) {
        // only factoid answers with 1 extraction technique
        if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY || result.getExtractionTechniques() == null || result.getExtractionTechniques().length != 1) {
            allResults.add(result);
            continue;
        }
        String extractor = result.getExtractionTechniques()[0];
        ArrayList<Result> extracted = allExtracted.get(extractor);
        if (extracted == null) {
            extracted = new ArrayList<Result>();
            allExtracted.put(extractor, extracted);
        }
        extracted.add(result);
    }
    // normalize answer scores for each extractor
    for (List<Result> extracted : allExtracted.values()) {
        // sort results by their normalized scores in descending order
        Result[] factoids = extracted.toArray(new Result[extracted.size()]);
        factoids = (new NormalizedScoreSorterFilter()).apply(factoids);
        // get sorted normalized scores
        float[] normScores = new float[factoids.length];
        for (int i = 0; i < factoids.length; i++) normScores[i] = factoids[i].getNormScore();
        // sort results by their original scores in descending order
        factoids = (new ScoreSorterFilter()).apply(factoids);
        // reassign sorted normalized scores
        for (int i = 0; i < factoids.length; i++) factoids[i].setNormScore(normScores[i]);
        // merge answers
        for (Result norm : factoids) allResults.add(norm);
    }
    return allResults.toArray(new Result[allResults.size()]);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Result(info.ephyra.search.Result)

Example 53 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class ScoreNormalizationFilter method addMinScoreFeature.

/**
	 * Adds the minimum score of all factoid answers from the same extractor as
	 * a feature to the instance.
	 */
private static void addMinScoreFeature(MutableInstance instance, Result result, Result[] results) {
    // calculate minimum score
    double minScore = Double.POSITIVE_INFINITY;
    //		String extractor = result.getExtractionTechniques()[0];
    for (Result r : results) if (r.getScore() > 0 && r.getScore() < Float.POSITIVE_INFINITY)
        //				if (r.extractedWith(extractor))
        minScore = Math.min(r.getScore(), minScore);
    Feature feature = new Feature(MIN_SCORE_F);
    instance.addNumeric(feature, minScore);
}
Also used : Feature(edu.cmu.minorthird.classify.Feature) Result(info.ephyra.search.Result)

Example 54 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class ScoreNormalizationFilter method apply.

/**
	 * Normalizes the scores of the factoid answers, using the features
	 * specified in <code>SELECTED_FEATURES</code> and the classifier specified
	 * in <code>classifier</code>.
	 * 
	 * @param results array of <code>Result</code> objects
	 * @return array of <code>Result</code> objects with normalized scores
	 */
public Result[] apply(Result[] results) {
    // classifier not loaded
    if (classifier == null)
        return results;
    for (Result result : results) {
        // only factoid answers with 1 extraction technique
        if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY || result.getExtractionTechniques() == null || result.getExtractionTechniques().length != 1)
            continue;
        // create instance with selected features
        Instance instance = createInstance(SELECTED_FEATURES, result, results);
        // classify instance
        ClassLabel label = classifier.classification(instance);
        // get weight of positive class as result score
        double weight = label.posProbability();
        result.setNormScore((float) weight);
    }
    // preserve original order of results
    //		results = preserveOrderResorting(results);
    //		results = preserveOrderAveraging(results);
    results = preserveOrderTop(results);
    return results;
}
Also used : ClassLabel(edu.cmu.minorthird.classify.ClassLabel) MutableInstance(edu.cmu.minorthird.classify.MutableInstance) Instance(edu.cmu.minorthird.classify.Instance) Result(info.ephyra.search.Result)

Example 55 with Result

use of info.ephyra.search.Result in project lucida by claritylab.

the class ScoreNormalizationFilter method createDataset.

/**
	 * Creates a training/evaluation set from serialized judged
	 * <code>Result</code> objects.
	 * 
	 * @param features selected features
	 * @param serializedDir directory containing serialized results
	 * @return training/evaluation set
	 */
private static Dataset createDataset(String[] features, String serializedDir) {
    Dataset set = new BasicDataset();
    File[] files = FileUtils.getFilesRec(serializedDir);
    for (File file : files) {
        // one file per question
        String filename = file.getName();
        if (!filename.endsWith(".serialized"))
            continue;
        // get question ID and results
        String qid = filename.replace(".serialized", "");
        Result[] results = readSerializedResults(file);
        // create examples and add to data set
        for (Result result : results) {
            // only factoid answers with 1 extraction technique
            if (result.getScore() <= 0 || result.getScore() == Float.POSITIVE_INFINITY || result.getExtractionTechniques() == null || result.getExtractionTechniques().length != 1)
                continue;
            Example example = createExample(features, result, results, qid);
            set.add(example);
        }
    }
    return set;
}
Also used : BasicDataset(edu.cmu.minorthird.classify.BasicDataset) CrossValidatedDataset(edu.cmu.minorthird.classify.experiments.CrossValidatedDataset) Dataset(edu.cmu.minorthird.classify.Dataset) Example(edu.cmu.minorthird.classify.Example) BasicDataset(edu.cmu.minorthird.classify.BasicDataset) File(java.io.File) Result(info.ephyra.search.Result)

Aggregations

Result (info.ephyra.search.Result)68 ArrayList (java.util.ArrayList)36 Query (info.ephyra.querygeneration.Query)11 HashSet (java.util.HashSet)9 Hashtable (java.util.Hashtable)9 AnalyzedQuestion (info.ephyra.questionanalysis.AnalyzedQuestion)8 IOException (java.io.IOException)7 QuestionInterpretation (info.ephyra.questionanalysis.QuestionInterpretation)5 Feature (edu.cmu.minorthird.classify.Feature)4 HashMap (java.util.HashMap)4 Predicate (info.ephyra.nlp.semantics.Predicate)3 BagOfWordsG (info.ephyra.querygeneration.generators.BagOfWordsG)3 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 URL (java.net.URL)3 TRECTarget (info.ephyra.trec.TRECTarget)2 EOFException (java.io.EOFException)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStreamReader (java.io.InputStreamReader)2