本文整理汇总了Java中cc.mallet.types.FeatureVectorSequence.size方法的典型用法代码示例。如果您正苦于以下问题:Java FeatureVectorSequence.size方法的具体用法?Java FeatureVectorSequence.size怎么用?Java FeatureVectorSequence.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.FeatureVectorSequence
的用法示例。
在下文中一共展示了FeatureVectorSequence.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preProcess
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count
int ii = 0;
int fi;
FeatureVector fv;
BitSet bitSet = new BitSet(data.size());
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
for (int ip = 0; ip < fvs.size(); ip++) {
fv = fvs.get(ip);
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
if (constraints.containsKey(fi)) {
constraints.get(fi).count += 1;
bitSet.set(ii);
}
}
}
ii++;
}
return bitSet;
}
示例2: preProcess
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count
BitSet bitSet = new BitSet(data.size());
int ii = 0;
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
for (int ip = 1; ip < fvs.size(); ip++) {
for (int fi : constraintsMap.keys()) {
// binary constraint features
if (fvs.get(ip).location(fi) >= 0) {
constraintsList.get(constraintsMap.get(fi)).count += 1;
bitSet.set(ii);
}
}
}
ii++;
}
return bitSet;
}
示例3: getSample
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public Sample getSample(int index) {
Instance2Sample s = integerToSampleMap.get(index);
if (s == null) {
int offset = 0;
Iterator<?> it = instanceList.iterator();
while (it.hasNext()) {
Instance instance = (Instance) it.next();
Object data = instance.getData();
if (data instanceof FeatureVectorSequence) {
FeatureVectorSequence fvs = (FeatureVectorSequence) data;
int size = fvs.size();
if (index - offset < size) {
s = new Instance2Sample(instance, index - offset);
integerToSampleMap.put(index, s);
return s;
} else {
offset += fvs.size();
}
}
}
}
return s;
}
示例4: computeExpectations
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public void computeExpectations(ArrayList<SumLattice> lattices) {
double[][][] xis;
TIntArrayList cache = new TIntArrayList();
for (int i = 0; i < lattices.size(); i++) {
if (lattices.get(i) == null) { continue; }
FeatureVectorSequence fvs = (FeatureVectorSequence)lattices.get(i).getInput();
SumLattice lattice = lattices.get(i);
xis = lattice.getXis();
for (int ip = 1; ip < fvs.size(); ++ip) {
cache.resetQuick();
FeatureVector fv = fvs.getFeatureVector(ip);
int fi;
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
// binary constraint features
if (constraintsMap.containsKey(fi)) {
cache.add(constraintsMap.get(fi));
}
}
for (int prev = 0; prev < map.getNumStates(); ++prev) {
int liPrev = map.getLabelIndex(prev);
if (liPrev != StateLabelMap.START_LABEL) {
for (int curr = 0; curr < map.getNumStates(); ++curr) {
int liCurr = map.getLabelIndex(curr);
if (liCurr != StateLabelMap.START_LABEL) {
double prob = Math.exp(xis[ip][prev][curr]);
for (int j = 0; j < cache.size(); j++) {
constraintsList.get(cache.getQuick(j)).expectation[liPrev][liCurr] += prob;
}
}
}
}
}
}
}
}
示例5: preProcess
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count
int ii = 0;
int fi;
FeatureVector fv;
BitSet bitSet = new BitSet(data.size());
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
for (int ip = 0; ip < fvs.size(); ip++) {
fv = fvs.get(ip);
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
if (constraints.containsKey(fi)) {
constraints.get(fi).count += 1;
bitSet.set(ii);
}
}
if (constraints.containsKey(fv.getAlphabet().size())) {
bitSet.set(ii);
constraints.get(fv.getAlphabet().size()).count += 1;
}
}
ii++;
}
return bitSet;
}
示例6: computeExpectations
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public void computeExpectations(ArrayList<SumLattice> lattices) {
double[][] gammas;
TIntArrayList cache = new TIntArrayList();
for (int i = 0; i < lattices.size(); i++) {
if (lattices.get(i) == null) { continue; }
SumLattice lattice = lattices.get(i);
FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
gammas = lattice.getGammas();
for (int ip = 0; ip < fvs.size(); ++ip) {
cache.resetQuick();
FeatureVector fv = fvs.getFeatureVector(ip);
int fi;
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
// binary constraint features
if (constraints.containsKey(fi)) {
cache.add(fi);
}
}
if (constraints.containsKey(fv.getAlphabet().size())) {
cache.add(fv.getAlphabet().size());
}
for (int s = 0; s < map.getNumStates(); ++s) {
int li = map.getLabelIndex(s);
if (li != StateLabelMap.START_LABEL) {
double gammaProb = Math.exp(gammas[ip+1][s]);
for (int j = 0; j < cache.size(); j++) {
constraints.get(cache.getQuick(j)).incrementExpectation(li,gammaProb);
}
}
}
}
}
}
示例7: preProcess
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count number of tokens
BitSet bitSet = new BitSet(data.size());
bitSet.set(0, data.size(), true);
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
this.numTokens += fvs.size();
}
return bitSet;
}
示例8: computeExpectations
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public void computeExpectations(ArrayList<SumLattice> lattices) {
double[][][] xis;
for (int i = 0; i < lattices.size(); i++) {
SumLattice lattice = lattices.get(i);
xis = lattice.getXis();
int numStates = xis[0].length;
FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
for (int ip = 0; ip < fvs.size(); ++ip) {
for (int si = 0; si < numStates; si++) {
this.expectation += Math.exp(xis[ip][si][si]);
}
}
}
System.err.println("Self transition expectation: " + (this.expectation/this.numTokens));
}
示例9: computeExpectations
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public void computeExpectations(ArrayList<SumLattice> lattices) {
double[][] gammas;
TIntArrayList cache = new TIntArrayList();
for (int i = 0; i < lattices.size(); i++) {
if (lattices.get(i) == null) { continue; }
SumLattice lattice = lattices.get(i);
FeatureVectorSequence fvs = (FeatureVectorSequence)lattice.getInput();
gammas = lattice.getGammas();
for (int ip = 0; ip < fvs.size(); ++ip) {
cache.resetQuick();
FeatureVector fv = fvs.getFeatureVector(ip);
int fi;
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
// binary constraint features
if (constraints.containsKey(fi)) {
cache.add(fi);
}
}
if (constraints.containsKey(fv.getAlphabet().size())) {
cache.add(fv.getAlphabet().size());
}
for (int s = 0; s < map.getNumStates(); ++s) {
int li = map.getLabelIndex(s);
if (li != StateLabelMap.START_LABEL) {
double gammaProb = Math.exp(gammas[ip+1][s]);
for (int j = 0; j < cache.size(); j++) {
constraints.get(cache.getQuick(j)).expectation[li] += gammaProb;
}
}
}
}
}
}
示例10: pipe
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
/**
* Add the token classifier's predictions as features to the instance.
* This method assumes the input instance contains FeatureVectorSequence as data
*/
public Instance pipe(Instance carrier)
{
FeatureVectorSequence fvs = (FeatureVectorSequence) carrier.getData();
InstanceList ilist = convert(carrier, (Noop) m_tokenClassifiers.getInstancePipe());
assert (fvs.size() == ilist.size());
// For passing instances to the token classifier, each instance's data alphabet needs to
// match that used by the token classifier at training time. For the resulting piped
// instance, each instance's data alphabet needs to contain token classifier's prediction
// as features
FeatureVector[] fva = new FeatureVector[fvs.size()];
for (int i = 0; i < ilist.size(); i++) {
Instance inst = ilist.get(i);
Classification c = m_tokenClassifiers.classify(inst, ! m_inProduction);
LabelVector lv = c.getLabelVector();
AugmentableFeatureVector afv1 = (AugmentableFeatureVector) inst.getData();
int[] indices = afv1.getIndices();
AugmentableFeatureVector afv2 = new AugmentableFeatureVector(m_dataAlphabet,
indices, afv1.getValues(), indices.length + m_predRanks2add.length);
for (int j = 0; j < m_predRanks2add.length; j++) {
Label label = lv.getLabelAtRank(m_predRanks2add[j]);
int idx = m_dataAlphabet.lookupIndex("TOK_PRED=" + label.toString() + "[email protected]_RANK_" + m_predRanks2add[j]);
assert(idx >= 0);
afv2.add(idx, 1);
}
fva[i] = afv2;
}
carrier.setData(new FeatureVectorSequence(fva));
return carrier;
}
示例11: convert
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
/**
*
* @param inst input instance, with FeatureVectorSequence as data.
* @param alphabetsPipe a Noop pipe containing the data and target alphabets for
* the resulting InstanceList and AugmentableFeatureVectors
* @return list of instances, each with one AugmentableFeatureVector as data
*/
public static InstanceList convert(Instance inst, Noop alphabetsPipe)
{
InstanceList ret = new InstanceList(alphabetsPipe);
Object obj = inst.getData();
assert(obj instanceof FeatureVectorSequence);
FeatureVectorSequence fvs = (FeatureVectorSequence) obj;
LabelSequence ls = (LabelSequence) inst.getTarget();
assert(fvs.size() == ls.size());
Object instName = (inst.getName() == null ? "NONAME" : inst.getName());
for (int j = 0; j < fvs.size(); j++) {
FeatureVector fv = fvs.getFeatureVector(j);
int[] indices = fv.getIndices();
FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(),
indices, fv.getValues(), indices.length);
Labeling target = ls.getLabelAtPosition(j);
String name = instName.toString() + "[email protected]_POS_" + (j + 1);
Object source = inst.getSource();
Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source));
ret.add(toAdd);
}
return ret;
}
示例12: getUnnormalizedClassificationScores
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
/** returns unnormalized scores, corresponding to the score an
* element of the InstanceList being the "top" instance
* @param instance instance with data field a {@link InstanceList}.
* @param scores has length = number of Instances in Instance.data,
* which is of type InstanceList */
public void getUnnormalizedClassificationScores (Instance instance, double[] scores)
{
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
assert (scores.length == fvs.size());
int numFeatures = instance.getDataAlphabet().size()+1;
for (int instanceNumber=0; instanceNumber < fvs.size(); instanceNumber++) {
FeatureVector fv = (FeatureVector)fvs.get(instanceNumber);
// Make sure the feature vector's feature dictionary matches
// what we are expecting from our data pipe (and thus our notion
// of feature probabilities.
assert (fv.getAlphabet ()
== this.instancePipe.getDataAlphabet ());
// Include the feature weights according to each label xxx is
// this correct ? we only calculate the dot prod of the feature
// vector with the "positiveLabel" weights
// xxx include multiple labels
scores[instanceNumber] = parameters[0*numFeatures + defaultFeatureIndex]
+ MatrixOps.rowDotProduct (parameters, numFeatures,
0, fv,
defaultFeatureIndex,
(perClassFeatureSelection == null
? featureSelection
: perClassFeatureSelection[0]));
}
}
示例13: getClassificationScores
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public void getClassificationScores (Instance instance, double[] scores)
{
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
int numFeatures = instance.getDataAlphabet().size()+1;
int numLabels = fvs.size();
assert (scores.length == fvs.size());
for (int instanceNumber=0; instanceNumber < fvs.size(); instanceNumber++) {
FeatureVector fv = (FeatureVector)fvs.get(instanceNumber);
// Make sure the feature vector's feature dictionary matches
// what we are expecting from our data pipe (and thus our notion
// of feature probabilities.
assert (fv.getAlphabet ()
== this.instancePipe.getDataAlphabet ());
// Include the feature weights according to each label
scores[instanceNumber] = parameters[0*numFeatures + defaultFeatureIndex]
+ MatrixOps.rowDotProduct (parameters, numFeatures,
0, fv,
defaultFeatureIndex,
(perClassFeatureSelection == null
? featureSelection
: perClassFeatureSelection[0]));
}
// Move scores to a range where exp() is accurate, and normalize
double max = MatrixOps.max (scores);
double sum = 0;
for (int li = 0; li < numLabels; li++)
sum += (scores[li] = Math.exp (scores[li] - max));
for (int li = 0; li < numLabels; li++) {
scores[li] /= sum;
// xxxNaN assert (!Double.isNaN(scores[li]));
}
}
示例14: classify
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
public Classification classify (Instance instance)
{
FeatureVectorSequence fvs = (FeatureVectorSequence) instance.getData();
int numClasses = fvs.size();
double[] scores = new double[numClasses];
getClassificationScores (instance, scores);
// Create and return a Classification object
return new Classification (instance, this,
createLabelVector (getLabelAlphabet(),
scores));
}
示例15: pipe
import cc.mallet.types.FeatureVectorSequence; //导入方法依赖的package包/类
@Override
public Instance pipe(Instance inst) {
FeatureVectorSequence vs = (FeatureVectorSequence) inst.getData();
for (int i = 0; i < vs.size(); i++) {
AugmentableFeatureVector v = (AugmentableFeatureVector) vs.get(i);
// System.out.println("Before augment: " + v.numLocations());
double[] values = scl.transform(v);
for (int j = 0; j < values.length; j++) {
String key = "SCL_AUG" + j;
// if (values[j] != 0)
// v.add("SCL_AUG" + j, values[j]);
// if (values[j] < -1) {
// v.add(key + "(<-1)", 1);
// } else if (values[j] < -0.5) {
// v.add(key + "(<-0.5)", 1);
// } else if (values[j] < 0) {
// v.add(key + "(<0)", 1);
// } else if (values[j] > 1) {
// v.add(key + "(>1)", 1);
// } else if (values[j] > 0.5) {
// v.add(key + "(>0.5)", 1);
// } else if (values[j] > 0) {
// v.add(key + "(>0)", 1);
// } else {
// v.add(key + "(=0)", 1);
// }
// if (values[j] > 0) {
// v.add(key + "(>0)", 1);
// } else if (values[j] < 0) {
// v.add(key + "(<0)", 1);
// }
if (values[j] != 0)
v.add(key, values[j]);
}
// System.out.println(v);
// System.out.println("After augment: " + v.numLocations());
}
return inst;
}