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


Java Util.runJobsInParallel方法代码示例

本文整理汇总了Java中edu.uw.easysrl.util.Util.runJobsInParallel方法的典型用法代码示例。如果您正苦于以下问题:Java Util.runJobsInParallel方法的具体用法?Java Util.runJobsInParallel怎么用?Java Util.runJobsInParallel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.uw.easysrl.util.Util的用法示例。


在下文中一共展示了Util.runJobsInParallel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evaluate

import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
public static Results evaluate(final SRLParser parser, final Collection<SRLParse> iterator,
		final int maxSentenceLength) throws FileNotFoundException {
	final List<String> autoOutput = new ArrayList<>();

	final Results results = new Results();
	int id = 0;

	final Collection<List<String>> failedToParse = new ArrayList<>();
	final AtomicInteger shouldParse = new AtomicInteger();
	final AtomicInteger parsed = new AtomicInteger();

	final Collection<Runnable> jobs = new ArrayList<>();

	final boolean oneThread = true;

	System.out.println("Parsing...");
	final Stopwatch stopwatch = Stopwatch.createStarted();

	for (final SRLParse srlParse : iterator) {
		id++;
		final List<CCGandSRLparse> parses = parser.parseTokens(InputWord.listOf(srlParse.getWords()));
		if (parses == null || parses.size() == 0) {
			if (srlParse.getWords().size() < maxSentenceLength) {
				failedToParse.add(srlParse.getWords());

			}

			results.add(new Results(0, 0, srlParse.getDependencies().size()));

			continue;
		} else {
			final CCGandSRLparse parse = parses.get(0);
			autoOutput.add(ParsePrinter.CCGBANK_PRINTER.print(parse != null ? parse.getCcgParse() : null, id));

			parsed.getAndIncrement();

			results.add(evaluate(srlParse, parse));
		}

	}

	if (!oneThread) {
		Util.runJobsInParallel(jobs, Runtime.getRuntime().availableProcessors());

	}

	for (final List<String> cov : failedToParse) {
		System.err.print("FAILED TO PARSE: ");
		for (final String word : cov) {
			System.err.print(word + " ");
		}
		System.err.println();
	}

	System.out.println(results);

	System.out.println("Coverage: " + Util.twoDP(100.0 * parsed.get() / shouldParse.get()));
	System.out.println("Time: " + stopwatch.elapsed(TimeUnit.SECONDS));

	return results;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:62,代码来源:SRLEvaluation.java

示例2: trainDistributed

import edu.uw.easysrl.util.Util; //导入方法依赖的package包/类
private double[] trainDistributed() throws IOException, NotBoundException {
	final Set<FeatureKey> boundedFeatures = new HashSet<>();
	final Map<FeatureKey, Integer> featureToIndex = makeKeyToIndexMap(trainingParameters.minimumFeatureFrequency,
			boundedFeatures);

	final Collection<RemoteTrainer> workers = getTrainers(featureToIndex);

	System.out.println("Training nodes: " + workers.size());

	final List<Runnable> tasks = new ArrayList<>();

	final int sentencesToLoad = Iterators.size(ParallelCorpusReader.READER.readCorpus(false /* not dev */));
	final int shardSize = sentencesToLoad / workers.size();

	int i = 0;
	for (final RemoteTrainer worker : workers) {
		final int start = i * shardSize;
		final int end = start + shardSize;
		tasks.add(new Runnable() {

			@Override
			public void run() {
				try {
					worker.loadData(start, end, dataParameters, trainingParameters.getModelFolder(), trainingLogger);
				} catch (final Throwable e) {
					throw new RuntimeException(e);
				}

			}
		});
		i++;

	}

	Util.runJobsInParallel(tasks, workers.size());

	final double[] weights = train(new DistributedLossFunction(workers, trainingParameters.getSigmaSquared()),
			featureToIndex, boundedFeatures);

	return weights;
}
 
开发者ID:uwnlp,项目名称:EasySRL,代码行数:42,代码来源:Training.java


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