-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCorefInfSolver.java
More file actions
79 lines (69 loc) · 2.18 KB
/
Copy pathCorefInfSolver.java
File metadata and controls
79 lines (69 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package coref;
import edu.illinois.cs.cogcomp.sl.core.AbstractInferenceSolver;
import edu.illinois.cs.cogcomp.sl.core.IInstance;
import edu.illinois.cs.cogcomp.sl.core.IStructure;
import edu.illinois.cs.cogcomp.sl.util.WeightVector;
import logic.Logic;
import utils.Params;
import java.io.Serializable;
public class CorefInfSolver extends AbstractInferenceSolver implements Serializable {
private static final long serialVersionUID = 5253748728743334706L;
private CorefFeatGen featGen;
public CorefInfSolver(CorefFeatGen featGen) throws Exception {
this.featGen = featGen;
}
@Override
public IStructure getBestStructure(WeightVector weight, IInstance ins)
throws Exception {
return getLossAugmentedBestStructure(weight, ins, null);
}
@Override
public IStructure getLossAugmentedBestStructure(WeightVector weight,
IInstance ins, IStructure goldStructure) throws Exception {
CorefX x = (CorefX) ins;
return getBestStructure(x, null, weight, false);
}
@Override
public float getLoss(IInstance ins, IStructure gold, IStructure pred) {
return CorefY.getLoss((CorefY)gold, (CorefY)pred);
}
public CorefY getBestStructure(CorefX x,
CorefY gold,
WeightVector weight,
boolean labelCompletion) {
double bestScore = -Double.MAX_VALUE;
CorefY best = null;
String label;
for(String key : Logic.getRelevantKeys(x.infType)) {
label = null;
if(x.infType.startsWith("Verb")) {
label = Logic.verb(x.tokens, x.schema.get(x.quantIndex1),
x.schema.get(x.quantIndex2), key);
}
if(x.infType.startsWith("Partition")) {
label = Logic.partition(key);
}
if(x.infType.startsWith("Math")) {
label = Logic.math(x.infType, key);
}
if(x.infType.startsWith("Rate")) {
label = Logic.unitDependency(x.infType, key);
}
if(label == null) continue;
if(labelCompletion) {
if(!label.equals(gold.label)) {
continue;
}
}
CorefY y = new CorefY(label, key);
// List<String> feats = CorefFeatGen.getFeatures(x, y);
// if(feats.contains("BestOption")) return y;
double score = weight.dotProduct(featGen.getFeatureVector(x, y));
if (bestScore < score) {
best = y;
bestScore = score;
}
}
return best;
}
}