/** * Bigrams encode indices of trees, rather than the String representations themselves, i.e., "3 * 56", denotes the prevElemTree indexed at position 3, and the elemTree at position 56 of their * corresponding indexers. * * @param input * @param unlex * @return */ private String toStringBigram( String input, boolean unlex, DiscriminativeFeatureIndexers featureIndexers) { if (input.equals("0") || input.equals("U")) return "U"; StringBuilder str = new StringBuilder(); String[] inputAr = input.split(" "); if (inputAr[0].equals("U")) str.append(inputAr[0]); else { int prevId = Integer.valueOf(inputAr[0]); str.append( unlex ? featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_PREV_ELEM_TREE_UNLEX, prevId) : featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_PREV_ELEM_TREE, prevId)); } str.append(" "); if (inputAr[1].equals("U")) { str.append(inputAr[1]); } else { int curId = Integer.valueOf(inputAr[1]); str.append( unlex ? featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_ELEM_TREE_UNLEX, curId) : featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_ELEM_TREE, curId)); } return str.toString(); }
/** * Input srl triple is encoded with ids, to save space, in the format role_id, arg_id, pred_id. * * @param input * @param unlex * @return */ private String toStringSrlTriple( String input, boolean unlex, DiscriminativeFeatureIndexers featureIndexers) { if (input.equals("0")) return "U"; String[] ar = input.split(","); if (!unlex) return String.format( "<%s,%s,%s>", featureIndexers.getRole(Integer.valueOf(ar[0])), featureIndexers.getWord(Integer.valueOf(ar[1])), featureIndexers.getWord(Integer.valueOf(ar[2]))); else return String.format( "<%s,%s,%s>", featureIndexers.getRole(Integer.valueOf(ar[0])), featureIndexers.getPos(Integer.valueOf(ar[1])), featureIndexers.getPos(Integer.valueOf(ar[2]))); }
public void setNeighboursL2( String[] neighboursStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.neighboursL2 = new int[neighboursStr.length]; for (int i = 0; i < neighboursStr.length; i++) neighboursL2[i] = featureIndexers.getIndexOfFeature( ExtractFeatures.FEAT_NEIGHBOURS_L2, neighboursStr[i], train); }
public void setSrlTriplesPos( String[] srlTriplesPosStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.srlTriplesPos = new int[srlTriples.length]; for (int i = 0; i < srlTriplesPosStr.length; i++) srlTriplesPos[i] = featureIndexers.getIndexOfFeature( ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplesPosStr[i], train); }
public String[] srlTriplesFull(DiscriminativeFeatureIndexers featureIndexers) { String[] out = new String[srlTriples.length]; for (int i = 0; i < srlTriples.length; i++) { String srlTriple = featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_SRL_TRIPLES, srlTriples[i]); if (srlTriple.equals("0")) { out[i] = "U"; } else { String[] srlTripleAr = srlTriple.split(","); String[] srlTriplePosAr = featureIndexers .getValueOfFeature(ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplesPos[i]) .split(","); out[i] = String.format( "<%s,%s/%s,%s/%s>:%s", featureIndexers.getRole(Integer.valueOf(srlTripleAr[0])), // role featureIndexers.getWord(Integer.valueOf(srlTripleAr[1])), featureIndexers.getPos(Integer.valueOf(srlTriplePosAr[1])), // arg featureIndexers.getWord(Integer.valueOf(srlTripleAr[2])), featureIndexers.getPos(Integer.valueOf(srlTriplePosAr[2])), // pred argComplete.get(i)); } } return out; }
private String toStringFeatureWeight( int vecId, int featureId, DiscriminativeFeatureIndexers featureIndexers, DiscriminativeParams params) { return String.format( "%s\t:\t%s", featureIndexers.getValueOfFeature(vecId, featureId), params.getParamVecWeight(vecId, featureId)); }
public void setElemTreeUnlex( String elemTreeUnlexStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.elemTreeUnlex = featureIndexers.getIndexOfFeature( ExtractFeatures.FEAT_ELEM_TREE_UNLEX, elemTreeUnlexStr, train); }
public void setElemTreeBigram( String elemTreeBigramStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.elemTreeBigram = featureIndexers.getIndexOfFeature( ExtractFeatures.FEAT_ELEM_TREE_BIGRAM, elemTreeBigramStr, train); }
public void setPrevElemTree( String prevElemTreeStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.prevElemTree = featureIndexers.getIndexOfFeature( ExtractFeatures.FEAT_PREV_ELEM_TREE, prevElemTreeStr, train); }
public String toString( DiscriminativeFeatureIndexers featureIndexers, DiscriminativeParams params) { StringBuilder str = new StringBuilder(); str.append(baselineScore) .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_BASELINE_SCORE, 0)) .append("\n") .append(baselineWordScore) .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_BASELINE_WORD_SCORE, 0)) .append("\n") .append( toStringFeatureWeight( ExtractFeatures.FEAT_ELEM_TREE, elemTree, featureIndexers, params)) .append("\n") .append( toStringFeatureWeight( ExtractFeatures.FEAT_PREV_ELEM_TREE, prevElemTree, featureIndexers, params)) .append("\n") .append( toStringBigram( featureIndexers.getValueOfFeature( ExtractFeatures.FEAT_ELEM_TREE_BIGRAM, elemTreeBigram), false, featureIndexers)) .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_ELEM_TREE_BIGRAM, elemTreeBigram)) .append("\n") .append( toStringFeatureWeight( ExtractFeatures.FEAT_ELEM_TREE_UNLEX, elemTreeUnlex, featureIndexers, params)) .append("\n") .append( toStringFeatureWeight( ExtractFeatures.FEAT_PREV_ELEM_TREE_UNLEX, prevElemTreeUnlex, featureIndexers, params)) .append("\n") .append( toStringBigram( featureIndexers.getValueOfFeature( ExtractFeatures.FEAT_ELEM_TREE_UNLEX_BIGRAM, elemTreeUnlexBigram), true, featureIndexers)) .append("\t:\t") .append( params.getParamVecWeight( ExtractFeatures.FEAT_ELEM_TREE_UNLEX_BIGRAM, elemTreeUnlexBigram)) .append("\n") .append( toStringFeatureWeight( ExtractFeatures.FEAT_INTEGRATION_POINT, integrationPoint, featureIndexers, params)) .append("\n") .append( toStringIpTree( featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTree), false, featureIndexers)) .append("\n") .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTree)) .append("\n") .append( toStringIpTree( featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTree), true, featureIndexers)) .append("\n") .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_IP_ELEM_TREE_UNLEX, ipElemTreeUnlex)) .append("\n"); for (Integer srlTriple : srlTriples) str.append( toStringSrlTriple( featureIndexers.getValueOfFeature(ExtractFeatures.FEAT_SRL_TRIPLES, srlTriple), false, featureIndexers)) .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_SRL_TRIPLES, srlTriple)) .append(", "); str.append("\n"); for (Integer srlTriplePos : srlTriplesPos) str.append( toStringSrlTriple( featureIndexers.getValueOfFeature( ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplePos), true, featureIndexers)) .append("\t:\t") .append(params.getParamVecWeight(ExtractFeatures.FEAT_SRL_TRIPLES_POS, srlTriplePos)) .append(", "); // str.append("\n").append(semanticScore); return str.toString(); }
public void setWordL3( String wordL3Str, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.wordL3 = featureIndexers.getIndexOfFeature(ExtractFeatures.FEAT_WORD_L3, wordL3Str, train); }
public void setIpElemTree( String ipElemTreeStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.ipElemTree = featureIndexers.getIndexOfFeature(ExtractFeatures.FEAT_IP_ELEM_TREE, ipElemTreeStr, train); }
public void setHeavy( String[] heavyStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.heavy = new int[heavyStr.length]; for (int i = 0; i < heavyStr.length; i++) heavy[i] = featureIndexers.getIndexOfFeature(ExtractFeatures.FEAT_HEAVY, heavyStr[i], train); }
public void setCoLenPar( String coLenParStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.coLenPar = featureIndexers.getIndexOfFeature(ExtractFeatures.FEAT_CO_LEN_PAR, coLenParStr, train); }
public void setIntegrationPoint( String integrationPointStr, DiscriminativeFeatureIndexers featureIndexers, boolean train) { this.integrationPoint = featureIndexers.getIndexOfFeature( ExtractFeatures.FEAT_INTEGRATION_POINT, integrationPointStr, train); }