大家好,欢迎来到IT知识分享网。
import edu.berkeley.nlp.util.Pair; //导入方法依赖的package包/类
public Pair>> getLogNormalizationAndExpectedCounts(
List extends InstanceSequence> sequences, double[] w) {
int numLabels = encoding.getNumLabels();
List> counts = new ArrayList>(numLabels);
for (int l = 0; l < numLabels; l++) {
counts.add(new Counter());
}
double totalLogZ = 0.0;
Logger.startTrack(“Computing expected counts”);
int index = 0;
for (InstanceSequence 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 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 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);
}
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/26457.html