- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中edu.illinois.cs.cogcomp.sl.util.WeightVector.dotProduct()
方法的一些代码示例,展示了WeightVector.dotProduct()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WeightVector.dotProduct()
方法的具体详情如下:
包路径:edu.illinois.cs.cogcomp.sl.util.WeightVector
类名称:WeightVector
方法名:dotProduct
暂无
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl-core
/***
* Computes wv^T\phi(x,y).
* Override this function if you have a faster implementation for computing
* wv^T\phi(x,y).
* @param wv
* @param x
* @param y
* @return
*/
public float decisionValue(WeightVector wv, IInstance x, IStructure y) {
return wv.dotProduct(getFeatureVector(x, y));
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl
/***
* Computes wv^T\phi(x,y).
* Override this function if you have a faster implementation for computing
* wv^T\phi(x,y).
* @param wv
* @param x
* @param y
* @return
*/
public float decisionValue(WeightVector wv, IInstance x, IStructure y) {
return wv.dotProduct(getFeatureVector(x, y));
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl
@Override
public IStructure getBestStructure(WeightVector weight, IInstance ins)
throws Exception {
RankingInstance ri = (RankingInstance) ins;
int maxIndex = -1;
double maxScore = Double.NEGATIVE_INFINITY;
for(int i=0; i < ri.featureList.size(); i ++){
double score = weight.dotProduct(ri.featureList.get(i));
if (score > maxScore){
maxScore = score;
maxIndex = i;
}
}
assert maxIndex != -1;
return new RankingLabel(maxIndex);
}
@Override
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl
@Override
public IStructure getLossAugmentedBestStructure(
WeightVector weight, IInstance ins, IStructure goldStructure)
throws Exception {
RankingInstance ri = (RankingInstance) ins;
RankingLabel lri = (RankingLabel) goldStructure;
int max_index = -1;
double max_score = Double.NEGATIVE_INFINITY;
for(int i=0; i < ri.featureList.size(); i ++){
float loss = -ri.scoreList.get(i)+ ri.scoreList.get(lri.pred_item);
if (loss< 0){
System.out.println("-----------");
System.out.println(ri.scoreList);
System.out.println("best: " + lri.pred_item);
}
assert loss >= 0;
float score = weight.dotProduct(ri.featureList.get(i)) + loss;
if (score > max_score){
max_score = score;
max_index = i;
}
}
assert max_index != -1;
RankingLabel pred = new RankingLabel(max_index);
//System.out.println("pred: " + max_index + " gold: " + lri.pred_item);
return pred;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl
@Override
public IStructure getLossAugmentedBestStructure(
WeightVector weight, IInstance ins, IStructure goldStructure)
throws Exception {
MultiClassInstance mi = (MultiClassInstance) ins;
MultiClassLabel lmi = (MultiClassLabel) goldStructure;
int bestOutput = -1;
float bestScore = Float.NEGATIVE_INFINITY;
for(int i=0; i < mi.numberOfClasses ; i ++){
float score = weight.dotProduct(mi.baseFv,mi.baseNfeature*i);
if (lmi!=null && i != lmi.output){
if(lossMatrix == null)
score += 1.0;
else
score += lossMatrix[lmi.output][i];
}
if (score > bestScore){
bestOutput = i;
bestScore = score;
}
}
assert bestOutput >= 0 ;
return new MultiClassLabel(bestOutput);
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-depparse
private String predictLabel(int head, int node, DepInst ins, WeightVector weight) {
if (head == -1)
throw new IllegalArgumentException("Invalid arc, head must be positive!");
String rel = null;
float max = Float.NEGATIVE_INFINITY;
String keyPOS = ins.strPos[head] + " " + ins.strPos[node];
Set<String> candidates = new HashSet<>();
if (deprelDict.get(keyPOS) != null)
candidates.addAll(deprelDict.get(keyPOS));
if (candidates.size() == 1)
return candidates.iterator().next();
else if (candidates.isEmpty()) {
if (keyPOS.contains("."))
return "P";
candidates.addAll(ALL_RELS);
}
for (String candidate : candidates) {
FeatureVectorBuffer edgefv = depfeat.getLabeledEdgeFeatures(head, node, ins, candidate);
float decision = weight.dotProduct(edgefv.toFeatureVector(false));
if (decision > max) {
rel = candidate;
max = decision;
}
}
return rel;
}
代码示例来源:origin: CogComp/cogcomp-nlp
private String predictLabel(int head, int node, DepInst ins, WeightVector weight) {
if (head == -1)
throw new IllegalArgumentException("Invalid arc, head must be positive!");
String rel = null;
float max = Float.NEGATIVE_INFINITY;
String keyPOS = ins.strPos[head] + " " + ins.strPos[node];
Set<String> candidates = new HashSet<>();
if (deprelDict.get(keyPOS) != null)
candidates.addAll(deprelDict.get(keyPOS));
if (candidates.size() == 1)
return candidates.iterator().next();
else if (candidates.isEmpty()) {
if (keyPOS.contains("."))
return "P";
candidates.addAll(ALL_RELS);
}
for (String candidate : candidates) {
FeatureVectorBuffer edgefv = depfeat.getLabeledEdgeFeatures(head, node, ins, candidate);
float decision = weight.dotProduct(edgefv.toFeatureVector(false));
if (decision > max) {
rel = candidate;
max = decision;
}
}
return rel;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/IllinoisSL-core
private void printErrorLogForIncorrectInference(WeightVector wv, float loss, IStructure h,
float xi, float dotProduct, float score,
float max_score_in_cache) {
logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
logger.error("The inference procedure is not correct!");
logger.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
logger.error("Pred: " + h);
logger.error("docproduct on pred: "
+ wv.dotProduct(h.getFeatureVector()));
logger.error("dotproduct on diff: " + dotProduct);
logger.error("loss: " + loss);
logger.error("xi: " + xi);
logger.error("Warning: the inference (argmax) code is not right......");
logger.error("score: " + score);
logger.error("max score in cache: " + max_score_in_cache);
for (int i = 0; i < goldStructureList.size(); i++) {
IStructure f = goldStructureList.get(i);
Pair<float[], FeatureVector> pair = alphaFeatureVectorList.get(i);
logger.error(">>>" + f + " alpha: " + pair.getFirst()[0]
+ " loss: " + pair.getFirst()[1]);
logger.error(">>> (dot) "
+ wv.dotProduct(pair.getSecond()));
}
logger.error("[GOLD]" + goldStructure);
logger.error("gold dot product: "
+ wv.dotProduct(goldStructure.getFeatureVector()));
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl-core
float dot_product = wv.dotProduct(fv);
float xij_norm2 = fv.getSquareL2Norm();
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl-core
float dotProduct = wv.dotProduct(diff);
float score = (loss - dotProduct) - xi; // line 12 in DCD-SSVM (algorithm 3 in paper)
for(AlphaStruct as:new ArrayList<AlphaStruct>(candidateAlphas)){
if(as !=null){
float s = as.loss - wv.dotProduct(as.alphaFeactureVector) - xi;
if (max_score_in_cache < s)
max_score_in_cache = s;
代码示例来源:origin: edu.illinois.cs.cogcomp/IllinoisSL-core
/**
* Get primal objective function value with respect to the weight vector wv
* @param sp
* @param wv
* @param infSolver
* @param C
* @return
* @throws Exception
*/
public static float getPrimalObjective(
StructuredProblem sp, WeightVector wv,
AbstractInferenceSolver infSolver, float C) throws Exception {
float obj = 0;
obj += wv.getSquareL2Norm() * 0.5;
List<IInstance> input_list = sp.instanceList;
List<IStructure> output_list = sp.goldStructureList;
for (int i = 0; i < input_list.size(); i++) {
IInstance ins = input_list.get(i);
IStructure gold_struct = output_list.get(i);
float sC= C;
Pair<IStructure, Float > res = infSolver
.getLossAugmentedBestStructure(wv, ins, gold_struct);
float loss = res.getSecond()
+ wv.dotProduct(res.getFirst().getFeatureVector())
- wv.dotProduct(gold_struct.getFeatureVector());
obj += sC * loss * loss;
}
return obj;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-srl
public double getIdentifierRawScore(SRLMulticlassInstance x) throws Exception {
log.debug("Classifying {}", x);
WeightVector w = manager.getModelInfo(Models.Identifier).getWeights();
SRLMulticlassLabel y1 = new SRLMulticlassLabel(1, Models.Identifier, manager);
SRLMulticlassLabel y0 = new SRLMulticlassLabel(0, Models.Identifier, manager);
double score1= w.dotProduct(x.getCachedFeatureVector(Models.Identifier),1 * manager.getModelInfo(Models.Identifier).getLexicon().size());
double score2= w.dotProduct(x.getCachedFeatureVector(Models.Identifier));
return (double) (score1 - score2);
}
代码示例来源:origin: CogComp/cogcomp-nlp
/**
* Scores instance for the different labels allowed for it
*/
public double[] getScores(SenseInstance x, boolean rescoreInvalidLabels) {
int numLabels = this.getNumLabels();
double[] scores = new double[numLabels];
WeightVector w;
try {
w = this.getModelInfo().getWeights();
assert w != null;
} catch (Exception e) {
log.error("Unable to load weight vector, exception:\n{}", e);
throw new RuntimeException(e);
}
for (int label = 0; label < numLabels; label++) {
if (!this.isValidLabel(x, label) && rescoreInvalidLabels) {
scores[label] = -50;
} else {
SenseStructure y = new SenseStructure(x, label, this);
scores[label] = w.dotProduct(y.getFeatureVector());
}
}
scores = MathUtilities.softmax(scores);
return scores;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-verbsense
/**
* Scores instance for the different labels allowed for it
*/
public double[] getScores(SenseInstance x, boolean rescoreInvalidLabels) {
int numLabels = this.getNumLabels();
double[] scores = new double[numLabels];
WeightVector w;
try {
w = this.getModelInfo().getWeights();
assert w != null;
} catch (Exception e) {
log.error("Unable to load weight vector, exception:\n{}", e);
throw new RuntimeException(e);
}
for (int label = 0; label < numLabels; label++) {
if (!this.isValidLabel(x, label) && rescoreInvalidLabels) {
scores[label] = -50;
} else {
SenseStructure y = new SenseStructure(x, label, this);
scores[label] = w.dotProduct(y.getFeatureVector());
}
}
scores = MathUtilities.softmax(scores);
return scores;
}
代码示例来源:origin: CogComp/cogcomp-nlp
double score = weight.dotProduct(y.getFeatureVector());
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-verbsense
double score = weight.dotProduct(y.getFeatureVector());
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-srl
/**
* Scores instance for the different labels allowed for it
*/
public double[] getScores(SRLMulticlassInstance x, Models type, boolean rescoreInvalidLabels) {
int numLabels = this.getNumLabels(type);
double[] scores = new double[numLabels];
WeightVector w;
try {
w = this.getModelInfo(type).getWeights();
assert w != null;
} catch (Exception e) {
log.error("Unable to load weight vector for {}", type, e);
throw new RuntimeException(e);
}
for (int label = 0; label < numLabels; label++) {
if (!this.isValidLabel(x, type, label) && rescoreInvalidLabels) {
scores[label] = -50;
}
else {
scores[label] = w.dotProduct(x.getCachedFeatureVector(type),label * this.getModelInfo(type).getLexicon().size());
}
}
scores = MathUtilities.softmax(scores);
return scores;
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-sl-core
IFeatureVector predictedFeatures = featureGenerator.getFeatureVector(example, prediction);
IFeatureVector update = goldFeatures.difference(predictedFeatures);
double loss_term = loss - w.dotProduct(update);
代码示例来源:origin: CogComp/cogcomp-nlp
@Override
public IStructure getLossAugmentedBestStructure(WeightVector weight, IInstance ins,
IStructure goldStructure) throws Exception {
DepInst sent = (DepInst) ins;
DepStruct gold = goldStructure != null ? (DepStruct) goldStructure : null;
// edgeScore[i][j] score of edge from head i to modifier j
// i (head) varies from 0..n, while j (token idx) varies over 1..n
double[][] edgeScore = new double[sent.size() + 1][sent.size() + 1];
String[][] edgeLabel = new String[sent.size() + 1][sent.size() + 1];
initEdge(edgeScore, edgeLabel);
for (int head = 0; head <= sent.size(); head++) {
for (int j = 1; j <= sent.size(); j++) {
if (head == j) {
edgeScore[head][j] = Double.NEGATIVE_INFINITY;
continue;
}
String deprel = predictLabel(head, j, sent, weight);
edgeLabel[head][j] = deprel;
FeatureVectorBuffer edgefv = depfeat.getCombineEdgeFeatures(head, j, sent, deprel);
// edge from head i to modifier j
edgeScore[head][j] = weight.dotProduct(edgefv.toFeatureVector(false));
if (gold != null) {
if (gold.heads[j] != head || !deprel.equals(gold.deprels[j])) // incur loss
edgeScore[head][j] += 1.0f;
}
}
}
return LabeledChuLiuEdmonds(edgeScore, edgeLabel);
}
代码示例来源:origin: edu.illinois.cs.cogcomp/illinois-depparse
@Override
public IStructure getLossAugmentedBestStructure(WeightVector weight, IInstance ins,
IStructure goldStructure) throws Exception {
DepInst sent = (DepInst) ins;
DepStruct gold = goldStructure != null ? (DepStruct) goldStructure : null;
// edgeScore[i][j] score of edge from head i to modifier j
// i (head) varies from 0..n, while j (token idx) varies over 1..n
double[][] edgeScore = new double[sent.size() + 1][sent.size() + 1];
String[][] edgeLabel = new String[sent.size() + 1][sent.size() + 1];
initEdge(edgeScore, edgeLabel);
for (int head = 0; head <= sent.size(); head++) {
for (int j = 1; j <= sent.size(); j++) {
if (head == j) {
edgeScore[head][j] = Double.NEGATIVE_INFINITY;
continue;
}
String deprel = predictLabel(head, j, sent, weight);
edgeLabel[head][j] = deprel;
FeatureVectorBuffer edgefv = depfeat.getCombineEdgeFeatures(head, j, sent, deprel);
// edge from head i to modifier j
edgeScore[head][j] = weight.dotProduct(edgefv.toFeatureVector(false));
if (gold != null) {
if (gold.heads[j] != head || !deprel.equals(gold.deprels[j])) // incur loss
edgeScore[head][j] += 1.0f;
}
}
}
return LabeledChuLiuEdmonds(edgeScore, edgeLabel);
}
我正在尝试在 C/CUDA 中实现点积。我主要从此处提供的 Nvidias 教程中复制了代码:http://www.nvidia.com/content/gtc-2010/pdfs/2131_gtc2
本文整理了Java中edu.illinois.cs.cogcomp.sl.util.WeightVector.dotProduct()方法的一些代码示例,展示了WeightVector.dotProd
我是一名优秀的程序员,十分优秀!