当前位置: 首页>>代码示例>>Java>>正文


Java CCGBankEvaluation类代码示例

本文整理汇总了Java中edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation的典型用法代码示例。如果您正苦于以下问题:Java CCGBankEvaluation类的具体用法?Java CCGBankEvaluation怎么用?Java CCGBankEvaluation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CCGBankEvaluation类属于edu.uw.easysrl.syntax.evaluation包,在下文中一共展示了CCGBankEvaluation类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DependencyEvaluator

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
public DependencyEvaluator(final File modelDir,
                           final Stream<DependencyParse> trainSentences) {
    try {
        dependencyGenerator = new DependencyGenerator(modelDir);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }

    log.info("Counting valid dependencies...");
    final ConcurrentHashMultiset<String> dependencyCounts = ConcurrentHashMultiset.create();
    trainSentences
            .parallel()
            .map(DependencyParse::getDependencies)
            .map(CCGBankEvaluation::asResolvedDependencies)
            .flatMap(Set::stream)
            .forEach(dep -> dependencyCounts.add(
                    dep.getCategory().toString() + dep.getArgNumber()));
    validDependencies = dependencyCounts.entrySet().stream()
            .filter(entry -> entry.getCount() >= 10)
            .map(Entry::getElement)
            .collect(Collectors.toSet());
    log.info("{} valid dependencies found", validDependencies.size());
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:24,代码来源:DependencyEvaluator.java

示例2: predictedDependencyStream

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
public Stream<ResolvedDependency> predictedDependencyStream(final SyntaxTreeNode parse,
                                                            final boolean generateDependencies,
                                                            final List<InputWord> leaves,
                                                            final boolean local) {
    if (parse == null) {
        return Stream.empty();
    }
    final Set<UnlabelledDependency> unlabeledDependencies = new HashSet<>();
    if (generateDependencies) {
        dependencyGenerator.generateDependencies(parse, unlabeledDependencies);
    } else {
        if (local) {
            unlabeledDependencies.addAll(parse.getResolvedUnlabelledDependencies());
        } else {
            SyntaxUtil.subtreeStream(parse).forEach(subtree -> unlabeledDependencies.addAll(subtree.getResolvedUnlabelledDependencies()));
        }
    }
    return CCGBankEvaluation
            .convertDeps(leaves, unlabeledDependencies)
            .stream()
            .filter(x -> x.getHead() != x.getArgument())
            .filter(x -> validDependencies.contains(x.getCategory().toString() + x.getArgNumber()));
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:24,代码来源:DependencyEvaluator.java

示例3: scoreNode

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
private int scoreNode(final SyntaxTreeNode node) {
	int score = 0;
	for (final UnlabelledDependency dep : node.getResolvedUnlabelledDependencies()) {
		if (!CCGBankEvaluation.filter(words.get(dep.getHead()), dep.getCategory(), dep.getArgNumber())) {
			for (final int arg : dep.getArguments()) {
				if (gold.contains(new ResolvedDependency(dep.getHead(), dep.getCategory(), dep.getArgNumber(), arg,
						SRLFrame.NONE, null))) {
					score++;
				} else {
					score--;
				}
			}
		}
	}
	return score;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:17,代码来源:OracleDependenciesModel.java

示例4: GoldInputToParser

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
public GoldInputToParser(final DependencyParse goldParse, final List<List<ScoredCategory>> inputSupertags) {
    super(
            goldParse.getWords(),
            goldParse.getLeaves()
                    .stream()
                    .map(SyntaxTreeNode::getCategory)
                    .collect(Collectors.toList()),
            inputSupertags,
            inputSupertags != null);
    this.goldDependencies = CCGBankEvaluation.asResolvedDependencies(goldParse.getDependencies());
    this.oracleParse = null;
}
 
开发者ID:uwnlp,项目名称:neuralccg,代码行数:13,代码来源:OracleModel.java

示例5: loadFromTestPool

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
public static Optional<ParseData> loadFromTestPool(boolean includeGold) {
    if (includeGold) {
        System.err.println("### Waring ### Reading test data with gold parses.");
    }
    POSTagger postagger = POSTagger.getStanfordTagger(Util.getFile(BaseCcgParser.modelFolder + "/posTagger"));
    List<List<InputReader.InputWord>> sentenceInputWords = new ArrayList<>();
    List<Parse> goldParses = new ArrayList<>();
    Iterator<ParallelCorpusReader.Sentence> sentenceIterator;
    try {
        sentenceIterator = ParallelCorpusReader.READER.readCcgTestSet();
    } catch (IOException e) {
        System.out.println(String.format("Failed to read %d sentences.", sentenceInputWords.size()));
        return Optional.empty();
    }
    while (sentenceIterator.hasNext()) {
        ParallelCorpusReader.Sentence sentence = sentenceIterator.next();
        List<InputReader.InputWord> taggedInput = postagger.tag(sentence.getInputWords());
        sentenceInputWords.add(taggedInput);
        Set<ResolvedDependency> goldDependencies = CCGBankEvaluation
                .asResolvedDependencies(sentence.getCCGBankDependencyParse().getDependencies());
        if (includeGold) {
            goldParses.add(new Parse(sentence.getCcgbankParse(), sentence.getLexicalCategories(), goldDependencies));
        } else {
            goldParses.add(null);
        }
    }
    System.out.println(String.format("Read %d sentences.", sentenceInputWords.size()));
    return Optional.of(makeParseData(sentenceInputWords, goldParses));
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:30,代码来源:ParseDataLoader.java

示例6: loadFromPropBank

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
private static Optional<ParseData> loadFromPropBank(final boolean readDev) {
    if(readDev && devData != null) {
        return devData;
    }
    POSTagger postagger = POSTagger.getStanfordTagger(Util.getFile(BaseCcgParser.modelFolder + "/posTagger"));
    List<List<InputReader.InputWord>> sentenceInputWords = new ArrayList<>();
    List<Parse> goldParses = new ArrayList<>();
    Iterator<ParallelCorpusReader.Sentence> sentenceIterator;
    try {
        sentenceIterator = ParallelCorpusReader.READER.readCcgCorpus(readDev);
    } catch (IOException e) {
        System.out.println(String.format("Failed to read %d sentences.", sentenceInputWords.size()));
        devData = Optional.empty();
        return devData;
    }
    while (sentenceIterator.hasNext()) {
        ParallelCorpusReader.Sentence sentence = sentenceIterator.next();
        List<InputReader.InputWord> taggedInput = postagger.tag(sentence.getInputWords());
        sentenceInputWords.add(taggedInput);
        Set<ResolvedDependency> goldDependencies = CCGBankEvaluation
                .asResolvedDependencies(sentence.getCCGBankDependencyParse().getDependencies());
        goldParses.add(new Parse(sentence.getCcgbankParse(), sentence.getLexicalCategories(), goldDependencies));
    }
    System.out.println(String.format("Read %d sentences.", sentenceInputWords.size()));
    Optional<ParseData> data = Optional.of(makeParseData(sentenceInputWords, goldParses));
    if(readDev) {
        devData = data;
    }
    return data;
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:31,代码来源:ParseDataLoader.java

示例7: getParse

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
protected Parse getParse(final List<InputReader.InputWord> sentence, final Scored<SyntaxTreeNode> scoredParse,
                         DependencyGenerator dependencyGenerator) {
    SyntaxTreeNode ccgParse = scoredParse.getObject();
    List<Category> categories = ccgParse.getLeaves().stream().map(SyntaxTreeNode::getCategory)
            .collect(Collectors.toList());
    Set<UnlabelledDependency> unlabelledDeps = new HashSet<>();
    dependencyGenerator.generateDependencies(ccgParse, unlabelledDeps);
    Set<ResolvedDependency> dependencies = CCGBankEvaluation.convertDeps(sentence, unlabelledDeps)
                    .stream()
                    .filter(x -> x.getHead() != x.getArgument())
                    .filter(x -> frequentDependenciesSet.contains(x.getCategory() + "." +  x.getArgNumber()))
                    .collect(Collectors.toSet());
    return new Parse(scoredParse.getObject(), categories, dependencies, scoredParse.getScore());
}
 
开发者ID:uwnlp,项目名称:hitl_parsing,代码行数:15,代码来源:BaseCcgParser.java

示例8: buildAgenda

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
@Override
public void buildAgenda(final Agenda queue, final List<InputWord> words) {
	int i = 0;
	for (final InputWord w : words) {

		double max = 0.0;
		final Category goldCat = goldDeps.getLeaves().get(i).getCategory();
		for (final ScoredCategory scoredCat : tags.get(i)) {
			final Category c = scoredCat.getCategory();
			int numberOfDeps = 0;
			for (int j = 1; j <= c.getNumberOfArguments(); j++) {
				if (!CCGBankEvaluation.filter(this.words.get(i), c, j)) {
					numberOfDeps++;
				}
			}
			max = Math.max(max, scoredCat.getScore());
			if (c != goldCat) {
				// continue;
			} else {
				continue;
			}
			final int upperBound = c == goldCat ? goldDeps.getDependencies(i).size() : -numberOfDeps;
			queue.add(new AgendaItem(new SyntaxTreeNodeLeaf(w.word, w.pos, w.ner, c, i), scoredCat.getScore()
					* catScore, getOutsideUpperBound(i, i + 1) + upperBound, i, 1, true));

		}

		if (categories.contains(goldCat)) {
			queue.add(new AgendaItem(new SyntaxTreeNodeLeaf(w.word, w.pos, w.ner, goldCat, i), max * catScore,
					getOutsideUpperBound(i, i + 1) + goldDeps.getDependencies(i).size(), i, 1, true));
		}

		i++;
	}

}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:37,代码来源:OracleDependenciesModel.java

示例9: makePipelineParser

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
private static PipelineSRLParser makePipelineParser(final File folder,
		final CommandLineArguments commandLineOptions, final double supertaggerBeam,
		final boolean outputDependencies) throws IOException {
	final POSTagger posTagger = POSTagger.getStanfordTagger(new File(folder, "posTagger"));
	final File labelClassifier = new File(folder, "labelClassifier");
	final LabelClassifier classifier = labelClassifier.exists() && outputDependencies ? Util
			.deserialize(labelClassifier) : CCGBankEvaluation.dummyLabelClassifier;

			return new PipelineSRLParser(new ParserAStar.Builder(folder).maxChartSize(100000)
			.supertaggerBeam(supertaggerBeam).nBest(commandLineOptions.getNbest())
			.maximumSentenceLength(commandLineOptions.getMaxLength()).build(), classifier, posTagger);
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:13,代码来源:EasySRL.java

示例10: main

import edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation; //导入依赖的package包/类
public static void main(final String[] args) throws IOException {
	final String pipelineFolder = Util.getHomeFolder() + "/Downloads/cnn/models/model_ccgbank";
	final Set<Category> categories = ImmutableSet.copyOf(TaggerEmbeddings.loadCategories(new File(pipelineFolder,
			"categories")));
	final Tagger tagger = Tagger.make(Util.getFile("~/Downloads/cnn/models/model_ccgbank"), 0.001, 50, null);// 0.1
	final OracleDependenciesModelFactory modelFactory = new OracleDependenciesModelFactory(tagger, categories);

	final File output = new File(Util.getHomeFolder() + "/Downloads/cnn/ccgbank_oracle0.01/train.stagged");
	final ParserAStar parser = new ParserAStar(modelFactory, 250, 1, Arrays.asList(Category.valueOf("S[dcl]"),
			Category.valueOf("S[q]"), Category.valueOf("S[wq]"), Category.valueOf("NP"),
			Category.valueOf("S[b]\\NP"), Category.valueOf("NP[nb]")), new File(pipelineFolder), 100000);
	int coverage = 0;
	int sentences = 0;
	int correctTags = 0;
	int totalTags = 0;
	final PrintWriter out = new PrintWriter(output);
	final Results results = new Results();
	for (final DependencyParse gold : CCGBankDependencies.loadCorpus(

			new File("/Users/mike/Documents/git/easyccg/testfiles/ccgbank"), Partition.TRAIN)) {

		final List<Scored<SyntaxTreeNode>> parses = parser.doParsing(new InputToParserWithGoldDeps(gold.getWords(),
				null, null, false, gold));

		if (sentences % 100 == 0) {
			System.out.println("Coverage:     " + Util.twoDP(100.0 * coverage / sentences));
			System.out.println("Supertagging: " + Util.twoDP(100.0 * correctTags / totalTags));
			System.out.println(results);
		}
		sentences++;
		if (parses == null) {
			continue;
		}
		coverage++;
		final SyntaxTreeNode parse = parses.get(0).getObject();
		int tagAcc = 0;
		for (int i = 0; i < gold.getWords().size(); i++) {
			if (parse.getLeaves().get(i).getCategory() == gold.getLeaves().get(i).getCategory()) {
				tagAcc++;
			}
		}

		final Set<UnlabelledDependency> deps2 = new HashSet<>();
		CCGBankEvaluation.extractDependencies(parse, deps2);
		Set<ResolvedDependency> deps = CCGBankEvaluation.convertDeps(gold.getWords(), deps2);
		final Set<ResolvedDependency> goldDeps = ImmutableSet.copyOf(gold.getResolvedDependencies());

		deps = deps.stream().filter(x -> validDeps.count(x.getCategory().toString() + x.getArgNumber()) >= 10)
				.collect(Collectors.toSet());

		results.add(new Results(deps.size(), com.google.common.collect.Sets.intersection(deps, goldDeps).size(),
				goldDeps.size()));

		correctTags += tagAcc;
		totalTags += gold.getWords().size();
		if (tagAcc < gold.getWords().size()) {
			System.out.println(tagAcc + "/" + gold.getWords().size());
			// System.out.println(ParsePrinter.SUPERTAG_PRINTER.print(parses.get(0).getObject(), 0));
			for (int i = 0; i < gold.getWords().size(); i++) {
				System.out.print(gold.getWords().get(i).word);
				if (parse.getLeaves().get(i).getCategory() != gold.getLeaves().get(i).getCategory()) {
					System.out.print("|" + gold.getLeaves().get(i).getCategory() + "|"
							+ parse.getLeaves().get(i).getCategory());
				}

				System.out.print(" ");
			}
			System.out.println();
		}

		out.println(ParsePrinter.SUPERTAG_PRINTER.print(parses.get(0).getObject(), 0));

	}

	out.close();
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:77,代码来源:OracleDependenciesModel.java


注:本文中的edu.uw.easysrl.syntax.evaluation.CCGBankEvaluation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。