Package edu.stanford.nlp.sempre

Examples of edu.stanford.nlp.sempre.FeatureVector


              (token2.equals("czech") || token2.equals("republic")))
            continue;

          double[] targetTokenVec = wordVectors.get(paraExample.targetInfo.tokens.get(j));
          if(targetTokenVec!=null) {
            FeatureVector fv;
            if(vsmSimilarityFunc==SimilarityFunc.FULL_MATRIX)
              fv = getFullMatrixFeatures(sourceTokenVec, targetTokenVec);
            else if(vsmSimilarityFunc==SimilarityFunc.DIAGNONAL)
              fv = getDiagonalMatrixFeatures(sourceTokenVec, targetTokenVec);
            else
              fv = getDotProductFeature(sourceTokenVec, targetTokenVec);
            double score = fv.dotProduct(params);
            scoreList.add(Pair.newPair(paraExample.sourceInfo.tokens.get(i)+","+paraExample.targetInfo.tokens.get(j), alpha*score));
          }
        }
      }
    }
View Full Code Here


    LanguageInfo consequent = new LanguageInfo();
    consequent.addSpan(antecedent, 0, i);
    consequent.addWordInfos(rhsMatch);
    consequent.addSpan(antecedent, j, antecedent.numTokens());
    RuleApplication application = new RuleApplication(antecedent, consequent, new ApplicationInfo(SYNT_SUBST, rule.toString()));
    FeatureVector fv = new FeatureVector();
    fv.add(SYNT_SUBST, rule.toString());
    fv.add(SYNT_SUBST, "score" ,rule.count);
    application.addFeatures(fv);
    if(opts.verbose>0)
      LogInfo.logs("antecedent=%s, consequent=%s, rule=%s",antecedent.tokens,consequent.tokens,rule);
    return application;
  }
View Full Code Here

    application.addFeatures(featurizeParaphraseRule());
    return Collections.singletonList(application);
  }

  private FeatureVector featurizeParaphraseRule() {
    FeatureVector fv = new FeatureVector();
    fv.add(RULE, lhs+"_"+rhs);
    return fv;
  }
View Full Code Here

  }

  private FeatureVector featurizeDeletedSpan(Interval span, LanguageInfo utterance) {

    List<String> spanProperties = utterance.getSpanProperties(span.start,span.end);
    FeatureVector res = new FeatureVector();

    for(String spanProperty: spanProperties) {
      if(ParaphraseFeatureMatcher.containsDomain(DELETE))
        res.add(DELETE,"match: " + spanProperty);
      if(ParaphraseFeatureMatcher.containsDomain(DELETE_IN_CONTEXT)) {
        if(span.start>0) {
          List<String> lcProperties = utterance.getSpanProperties(span.start-1,span.start);
          for(String lcProperty: lcProperties) {
            res.add(DELETE_IN_CONTEXT,"match_" + spanProperty+",lc_"+lcProperty); //properties of deleted match
          }
        }
        if(span.end<utterance.numTokens()) {
          List<String> rcProperties = utterance.getSpanProperties(span.end,span.end+1);
          for(String rcProperty: rcProperties) {
            res.add(DELETE_IN_CONTEXT,"match_" + spanProperty+",rc_"+rcProperty); //properties of deleted match
          }
        }
      }
    }
    //verb semclass features
    if(ParaphraseFeatureMatcher.containsDomain(DELETE_V_SEM)) {
      String lemmaTokens = utterance.lemmaPhrase(span.start, span.end);
      Counter<String> cooccurringWords = verbSemclassMap.get(lemmaTokens);
      if(cooccurringWords!=null) {
        for(String lemma: utterance.lemmaTokens) {
          if(cooccurringWords.containsKey(lemma)) {
            res.add(DELETE_V_SEM,"match="+lemmaTokens+",context="+lemma);
            res.add(DELETE_V_SEM,"sim",Math.log(cooccurringWords.getCount(lemma)+1));
          }
        }
      }
    }
    return res;
View Full Code Here

      targetVec = phraseVectorCache.containsKey(ex.target) ? phraseVectorCache.get(ex.target) : computeUtteranceVec(ex.targetInfo);
      MapUtils.putIfAbsent(phraseVectorCache, ex.source, sourceVec);
      MapUtils.putIfAbsent(phraseVectorCache, ex.target, targetVec);
    }
    //combine them
    FeatureVector fv;
    if(vsmSimilarityFunc==SimilarityFunc.DIAGNONAL)
      fv = getDiagonalMatrixFeatures(sourceVec,targetVec);
    else if(vsmSimilarityFunc==SimilarityFunc.FULL_MATRIX)
      fv = getFullMatrixFeatures(sourceVec,targetVec);
    else //dot product
View Full Code Here

    //set stuff
    ex.setVectorSpaceSimilarity(new FeatureSimilarity(fv,ex.source,ex.target,params));
  }

  private FeatureVector getDotProductFeature(double[] sourceVec, double[] targetVec) {   
    FeatureVector res = new FeatureVector();
    res.add("VS","dot_product",ListUtils.dot(sourceVec, targetVec));
    return res;
  }
View Full Code Here

  }

  private FeatureVector getFullMatrixFeatures(double[] sourceVec,
      double[] targetVec) {
    //FeatureVector res = new FeatureVector();
    FeatureVector res = new FeatureVector(opts.vecCapacity*opts.vecCapacity);
    int featureNum=0;
    for(int i = 0; i < sourceVec.length; ++i) {
      for(int j = 0; j < targetVec.length; j++) {
        res.addDenseFeature(featureNum++, sourceVec[i]*targetVec[j]);
        //res.add("VS", "d"+i+",d"+j, sourceVec[i]*targetVec[j]);
      }
    }
    return res;
  }
View Full Code Here

    return res;
  }

  private FeatureVector getDiagonalMatrixFeatures(double[] source,
      double[] target) {
    FeatureVector res = new FeatureVector(opts.vecCapacity);
    int featureNum=0;
    for(int i = 0; i < source.length; ++i) {
      res.addDenseFeature(featureNum++, source[i]*target[i]);
    }
    return res;
  }
View Full Code Here

    this.vsSimilarity=paraEx.featureSimilarity;
    this.alignment=paraEx.alignment;
    this.fgInfo=fgInfo;
    this.formula = fgInfo.generateFormula();
    //extract feature vector
    featureVector = new FeatureVector();
    fExtractor.extractParaphraseDerivationFeatures(this);
    //compute score - we can do this here since all features are extracted in the constructor
    scoreProofDeriv(params);
  }
View Full Code Here

class LexicalOverlap implements FeatureSimilarityComputer {
  @Override
  public void computeSimilarity(ParaphraseExample ex, Params params) {
    ex.ensureAnnotated();
    double jaccard = MathUtils.jaccard(ex.sourceInfo.lemmaTokens, ex.targetInfo.lemmaTokens);
    FeatureVector fv = new FeatureVector();
    fv.add("Jaccard", "jaccard", jaccard);
    ex.setVectorSpaceSimilarity(new FeatureSimilarity(fv,ex.source,ex.target,params));
  }
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.sempre.FeatureVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.