APISonar


edu.stanford.nlp.util.logging.Redwood.log

> edu > stanford > nlp > util > logging > Redwood > log
edu APIs stanford APIs nlp APIs util APIs logging APIs Redwood APIs log APIs

Example 1
public void printWeightVector(PrintWriter writer) {
    SortedMap<String, Double> sortedWeights = getWeightVector();
    for (Map.Entry<String, Double> e : sortedWeights.entrySet()) {
      if (writer == null) {
        Redwood.log("scoref.train", e.getKey() + " => " + e.getValue());
      } else {
        writer.println(e.getKey() + " => " + e.getValue());
      }
    }
  }
Example 2
public static Map<String, Set<CandidatePhrase>> readSeedWords(Properties props) {
    String seedWordsFile = props.getProperty("seedWordsFiles");
    if(seedWordsFile != null)
      return readSeedWords(seedWordsFile);
    else{
      Redwood.log(Redwood.FORCE,"NO SEED WORDS FILES PROVIDED!!");
    return Collections.emptyMap();
    }
  }
Example 3
public boolean save(String dir) {
    try {
      IOUtils.ensureDir(new File(dir));
      String f = dir+"/allpatterns.ser";
      IOUtils.writeObjectToFile(this.patternsForEachToken, f);
      Redwood.log(Redwood.DBG, "Saving the patterns to " + f);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return true;
  }
Example 4
public static void printFinalConllScore(String summary) {
    double finalScore = getFinalConllScore(summary);
    Redwood.log(
            "Final conll score ((muc+bcub+ceafe)/3) = " + (new DecimalFormat("#.##")).format(finalScore));
  }
Example 5
public static void printFinalConllScore(String summary) {
    Pattern f1 = Pattern.compile("Coreference:.*F1: (.*)%");
    Matcher f1Matcher = f1.matcher(summary);
    double[] F1s = new double[5];
    int i = 0;
    while (f1Matcher.find()) {
      F1s[i++] = Double.parseDouble(f1Matcher.group(1));
    }
    double finalScore = (F1s[0]+F1s[1]+F1s[3])/3;
    Redwood.log("Final conll score ((muc+bcub+ceafe)/3) = " + (new DecimalFormat("#.##")).format(finalScore));
  }
Example 6
public Map<E, Set<String>> getFileSentIdsFromPats(Collection<E> pats) {
    Map<E, Set<String>> sents = new HashMap<E, Set<String>>();
    for(E pat: pats){
      Set<String> ids = getFileSentIds(pat.getRelevantWords());
      Redwood.log(ConstantsAndVariables.extremedebug, "For pattern with index " + pat + " extracted the following sentences from the index " + ids);
      sents.put(pat, ids);
    }
    return sents;
  }
Example 7
public static<E> List<List<E>> getThreadBatches(List<E> keyset, int numThreads){
    int num;
    if (numThreads == 1)
      num = keyset.size();
    else
      num = keyset.size() / (numThreads - 1);
    Redwood.log(ConstantsAndVariables.extremedebug, "keyset size is " + keyset.size());
    List<List<E>> threadedSentIds = new ArrayList<>();
    for (int i = 0; i < numThreads; i++) {
      List<E> keys = keyset.subList(i * num, Math.min(keyset.size(), (i + 1) * num));
      threadedSentIds.add(keys);
      Redwood.log(ConstantsAndVariables.extremedebug, "assigning from " + i * num + " till " + Math.min(keyset.size(), (i + 1) * num));
    }
    return threadedSentIds;
  }
Example 8
private void trainPolicy(List<List<Pair<CandidateAction, CandidateAction>>> examples) {
    List<Pair<CandidateAction, CandidateAction>> flattenedExamples = new ArrayList<>();
    examples.stream().forEach(flattenedExamples::addAll);

    for (int epoch = 0; epoch < NUM_EPOCHS; epoch++) {
      Collections.shuffle(flattenedExamples, random);
      flattenedExamples.forEach(classifier::learn);
    }

    double totalCost = flattenedExamples.stream()
        .mapToDouble(e -> classifier.bestAction(e).cost).sum();
    Redwood.log("scoref.train",
        String.format("Training cost: %.4f", 100 * totalCost / flattenedExamples.size()));
  }
Example 9
public static void loadGoogleNGrams() {
    if (googleNGram == null || googleNGram.size() == 0) {
      for (String line : IOUtils.readLines(googleNGramsFile)) {
        String[] t = line.split("\t");
        googleNGram.setCount(t[0], Double.valueOf(t[1]));
      }
      Redwood.log(ConstantsAndVariables.minimaldebug, "Data", "loading freq from google ngram file " + googleNGramsFile);
    }
  }
Example 10
public void printReasonForChoosing(Counter<CandidatePhrase> phrases){
    Redwood.log(Redwood.DBG, "Features of selected phrases");
    for(Entry<CandidatePhrase, Double> pEn: phrases.entrySet())
      Redwood.log(Redwood.DBG, pEn.getKey().getPhrase() + "\t" + pEn.getValue() + "\t" +  phraseScoresRaw.getCounter(pEn.getKey()));
  }
Example 11
public static void loadDomainNGrams() {
    assert(domainNGramsFile != null);
    if (domainNGramRawFreq == null || domainNGramRawFreq.size() == 0) {
      for (String line : IOUtils.readLines(domainNGramsFile)) {
        String[] t = line.split("\t");
        domainNGramRawFreq.setCount(t[0], Double.valueOf(t[1]));
      }
      Redwood.log(ConstantsAndVariables.minimaldebug, "Data", "loading freq from domain ngram file " + domainNGramsFile);
    }
  }
Example 12
public Counter<CandidatePhrase> scorePhrases(String label, TwoDimensionalCounter<CandidatePhrase, E> terms,
      TwoDimensionalCounter<CandidatePhrase, E> wordsPatExtracted, Counter<E> allSelectedPatterns,
      Set<CandidatePhrase> alreadyIdentifiedWords, boolean forLearningPatterns) throws IOException, ClassNotFoundException {
    getAllLabeledWordsCluster();
    Counter<CandidatePhrase> scores = new ClassicCounter<>();
    edu.stanford.nlp.classify.Classifier classifier = learnClassifier(label, forLearningPatterns, wordsPatExtracted, allSelectedPatterns);
    for (Entry<CandidatePhrase, ClassicCounter<E>> en : terms.entrySet()) {
      Double score = this.scoreUsingClassifer(classifier, en.getKey(), label, forLearningPatterns, en.getValue(), allSelectedPatterns);
      if(!score.isNaN() && !score.isInfinite()){
        scores.setCount(en.getKey(), score);
      }else
       Redwood.log(Redwood.DBG, "Ignoring " + en.getKey() + " because score is " + score);
    }
    return scores;
  }