本文整理汇总了Java中edu.berkeley.nlp.util.Pair.makePair方法的典型用法代码示例。如果您正苦于以下问题:Java Pair.makePair方法的具体用法?Java Pair.makePair怎么用?Java Pair.makePair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.berkeley.nlp.util.Pair
的用法示例。
在下文中一共展示了Pair.makePair方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getKBestChartAndBacktrace
import edu.berkeley.nlp.util.Pair; //导入方法依赖的package包/类
public Pair<int[][][][], double[][][]> getKBestChartAndBacktrace(
InstanceSequence<V, E, L> sequence, double[] w, int k) {
int n = sequence.getSequenceLength();
int numLabels = encoding.getNumLabels();
int[][][][] bestLabels = new int[n][numLabels][][];
double[][][] bestScores = new double[n][numLabels][];
double[] startScores = scoreCalculator.getLinearVertexScores(sequence,
0, w);
for (int l = 0; l < numLabels; l++) {
bestScores[0][l] = new double[] { startScores[l] };
bestLabels[0][l] = new int[][] { new int[] { -1, 0 } };
}
for (int i = 1; i < n; i++) {
double[][] scoreMatrix = scoreCalculator.getLinearScoreMatrix(
sequence, i, w);
for (int l = 0; l < numLabels; l++) {
PriorityQueue<Pair<Integer, Integer>> pq = new PriorityQueue<Pair<Integer, Integer>>();
for (int pl = 0; pl < numLabels; pl++) {
double edgeScore = scoreMatrix[pl][l];
for (int c = 0; c < bestScores[i - 1][pl].length; c++) {
double totalScore = edgeScore
+ bestScores[i - 1][pl][c];
pq.add(Pair.makePair(pl, c), totalScore);
}
}
int cands = Math.min(k, pq.size());
bestScores[i][l] = new double[cands];
bestLabels[i][l] = new int[cands][2];
for (int c = 0; c < cands; c++) {
bestScores[i][l][c] = pq.getPriority();
Pair<Integer, Integer> backtrace = pq.next();
bestLabels[i][l][c][0] = backtrace.getFirst();
bestLabels[i][l][c][1] = backtrace.getSecond();
}
}
}
return Pair.makePair(bestLabels, bestScores);
}
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:39,代码来源:Inference.java示例2: getLogNormalizationAndExpectedCounts
import edu.berkeley.nlp.util.Pair; //导入方法依赖的package包/类
public Pair<Double, List<Counter<F>>> getLogNormalizationAndExpectedCounts(
List<? extends InstanceSequence<V, E, L>> sequences, double[] w) {
int numLabels = encoding.getNumLabels();
List<Counter<F>> counts = new ArrayList<Counter<F>>(numLabels);
for (int l = 0; l < numLabels; l++) {
counts.add(new Counter<F>());
}
double totalLogZ = 0.0;
Logger.startTrack("Computing expected counts");
int index = 0;
for (InstanceSequence<V, E, L> s : sequences) {
double[][] alpha = inf.getAlphas(s, w);
double[][] beta = inf.getBetas(s, w);
totalLogZ += Math.log(inf.getNormalizationConstant(alpha, beta));
double[][] vertexPosteriors = inf.getVertexPosteriors(alpha, beta);
double[][][] edgePosteriors = inf.getEdgePosteriors(s, w, alpha,
beta);
for (int i = 0; i < s.getSequenceLength(); i++) {
Counter<F> vertexFeatures = vertexExtractor.extractFeatures(s
.getVertexInstance(i));
for (int l = 0; l < numLabels; l++) {
counts.get(l).incrementAll(
vertexFeatures.scaledClone(vertexPosteriors[i][l]));
}
if (i > 0) {
for (int pl = 0; pl < numLabels; pl++) {
Counter<F> edgeFeatures = edgeExtractor
.extractFeatures(s.getEdgeInstance(i,
encoding.getLabel(pl)));
for (int cl = 0; cl < numLabels; cl++) {
counts.get(cl)
.incrementAll(
edgeFeatures
.scaledClone(edgePosteriors[i][pl][cl]));
}
}
}
}
Logger.logs("Processed %d/%d sentences", ++index, sequences.size());
}
Logger.endTrack();
return Pair.makePair(totalLogZ, counts);
}
开发者ID:text-machine-lab,项目名称:CliRel,代码行数:44,代码来源:Counts.java本文标签属性:
示例:示例英语
代码:代码是什么
java:javascript18岁
Pair:Pair
makePair:makePair