CRFBiasedClassifier<CoreLabel> crf = new CRFBiasedClassifier<>(props); String testFile = crf.flags.testFile; String loadPath = crf.flags.loadClassifier; crf.loadClassifierNoExceptions(loadPath, props); } else if (crf.flags.loadJarClassifier != null) { crf.loadClassifierNoExceptions(crf.flags.loadJarClassifier, props); } else { crf.loadDefaultClassifier(); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); crf.setBiasWeight(cname,w); log.info("Setting bias for class "+cname+" to "+w); DocumentReaderAndWriter<CoreLabel> readerAndWriter = crf.makeReaderAndWriter(); if (crf.flags.printFirstOrderProbs) { crf.printFirstOrderProbs(testFile, readerAndWriter); } else if (crf.flags.printProbs) { crf.printProbs(testFile, readerAndWriter); } else if (crf.flags.useKBest) { int k = crf.flags.kBest; crf.classifyAndWriteAnswersKBest(testFile, k, readerAndWriter); } else { crf.classifyAndWriteAnswers(testFile, readerAndWriter, true);
public void setBiasWeight(int cindex, double weight) { addBiasFeature(); int fi = featureIndex.indexOf(BIAS); weights[fi][cindex] = weight; }
@Override public void annotate(Annotation annotation) { if (verbose) { log.info("Adding true-case annotation..."); } if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { // classify tokens for each sentence for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); List<CoreLabel> output = this.trueCaser.classifySentence(tokens); for (int i = 0, size = tokens.size(); i < size; i++) { // add the truecaser tag to each token String neTag = output.get(i).get(CoreAnnotations.AnswerAnnotation.class); tokens.get(i).set(CoreAnnotations.TrueCaseAnnotation.class, neTag); setTrueCaseText(tokens.get(i)); } } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }
public TrueCaseAnnotator(String modelLoc, String classBias, String mixedCaseFileName, boolean overwriteText, boolean verbose) { this.overwriteText = overwriteText; this.verbose = verbose; Properties props = PropertiesUtils.asProperties( "loadClassifier", modelLoc, "mixedCaseMapFile", mixedCaseFileName, "classBias", classBias); trueCaser = new CRFBiasedClassifier<>(props); if (modelLoc != null) { trueCaser.loadClassifierNoExceptions(modelLoc, props); } else { throw new RuntimeException("Model location not specified for true-case classifier!"); } if (classBias != null) { StringTokenizer biases = new java.util.StringTokenizer(classBias,","); while (biases.hasMoreTokens()) { StringTokenizer bias = new java.util.StringTokenizer(biases.nextToken(),":"); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); trueCaser.setBiasWeight(cname,w); if (this.verbose) log.info("Setting bias for class " + cname + " to " + w); } } // Load map containing mixed-case words: mixedCaseMap = loadMixedCaseMap(mixedCaseFileName); }
props.setProperty("mixedCaseMapFile", mixedCaseFileName); props.setProperty("classBias", classBias); trueCaser = new CRFBiasedClassifier(props); trueCaser.loadClassifierNoExceptions(modelLoc, props); } else { throw new RuntimeException("Model location not specified for true-case classifier!"); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); trueCaser.setBiasWeight(cname,w); if(VERBOSE) System.err.println("Setting bias for class "+cname+" to "+w);
CRFBiasedClassifier<CoreLabel> crf = new CRFBiasedClassifier<>(props); String testFile = crf.flags.testFile; String loadPath = crf.flags.loadClassifier; crf.loadClassifierNoExceptions(loadPath, props); } else if (crf.flags.loadJarClassifier != null) { crf.loadClassifierNoExceptions(crf.flags.loadJarClassifier, props); } else { crf.loadDefaultClassifier(); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); crf.setBiasWeight(cname,w); log.info("Setting bias for class "+cname+" to "+w); DocumentReaderAndWriter<CoreLabel> readerAndWriter = crf.makeReaderAndWriter(); if (crf.flags.printFirstOrderProbs) { crf.printFirstOrderProbs(testFile, readerAndWriter); } else if (crf.flags.printProbs) { crf.printProbs(testFile, readerAndWriter); } else if (crf.flags.useKBest) { int k = crf.flags.kBest; crf.classifyAndWriteAnswersKBest(testFile, k, readerAndWriter); } else { crf.classifyAndWriteAnswers(testFile, readerAndWriter, true);
props.setProperty("mixedCaseMapFile", mixedCaseFileName); props.setProperty("classBias", classBias); trueCaser = new CRFBiasedClassifier(props); trueCaser.loadClassifierNoExceptions(modelLoc, props); } else { throw new RuntimeException("Model location not specified for true-case classifier!"); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); trueCaser.setBiasWeight(cname,w); if(VERBOSE) System.err.println("Setting bias for class "+cname+" to "+w);
public void setBiasWeight(int cindex, double weight) { addBiasFeature(); int fi = featureIndex.indexOf(BIAS); weights[fi][cindex] = weight; }
@SuppressWarnings("unchecked") public void annotate(Annotation annotation) { if (VERBOSE) { System.err.print("Adding true-case annotation..."); } if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { // classify tokens for each sentence for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); List<CoreLabel> output = this.trueCaser.classifySentence(tokens); for (int i = 0; i < tokens.size(); ++i) { // add the named entity tag to each token String neTag = output.get(i).get(CoreAnnotations.AnswerAnnotation.class); tokens.get(i).set(CoreAnnotations.TrueCaseAnnotation.class, neTag); setTrueCaseText(tokens.get(i)); } } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }
CRFBiasedClassifier<CoreLabel> crf = new CRFBiasedClassifier<CoreLabel>(props); String testFile = crf.flags.testFile; String loadPath = crf.flags.loadClassifier; crf.loadClassifierNoExceptions(loadPath, props); } else if (crf.flags.loadJarClassifier != null) { crf.loadJarClassifier(crf.flags.loadJarClassifier, props); } else { crf.loadDefaultClassifier(); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); crf.setBiasWeight(cname,w); System.err.println("Setting bias for class "+cname+" to "+w); DocumentReaderAndWriter<CoreLabel> readerAndWriter = crf.makeReaderAndWriter(); if (crf.flags.printFirstOrderProbs) { crf.printFirstOrderProbs(testFile, readerAndWriter); } else if (crf.flags.printProbs) { crf.printProbs(testFile, readerAndWriter); } else if (crf.flags.useKBest) { int k = crf.flags.kBest; crf.classifyAndWriteAnswersKBest(testFile, k, readerAndWriter); } else { crf.classifyAndWriteAnswers(testFile, readerAndWriter);
public TrueCaseAnnotator(String modelLoc, String classBias, String mixedCaseFileName, boolean overwriteText, boolean verbose) { this.overwriteText = overwriteText; this.verbose = verbose; Properties props = PropertiesUtils.asProperties( "loadClassifier", modelLoc, "mixedCaseMapFile", mixedCaseFileName, "classBias", classBias); trueCaser = new CRFBiasedClassifier<>(props); if (modelLoc != null) { trueCaser.loadClassifierNoExceptions(modelLoc, props); } else { throw new RuntimeException("Model location not specified for true-case classifier!"); } if (classBias != null) { StringTokenizer biases = new java.util.StringTokenizer(classBias,","); while (biases.hasMoreTokens()) { StringTokenizer bias = new java.util.StringTokenizer(biases.nextToken(),":"); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); trueCaser.setBiasWeight(cname,w); if (this.verbose) log.info("Setting bias for class " + cname + " to " + w); } } // Load map containing mixed-case words: mixedCaseMap = loadMixedCaseMap(mixedCaseFileName); }
public void setBiasWeight(int cindex, double weight) { addBiasFeature(); int fi = featureIndex.indexOf(BIAS); weights[fi][cindex] = weight; }
@SuppressWarnings("unchecked") public void annotate(Annotation annotation) { if (VERBOSE) { System.err.print("Adding true-case annotation..."); } if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { // classify tokens for each sentence for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); List<CoreLabel> output = this.trueCaser.classifySentence(tokens); for (int i = 0; i < tokens.size(); ++i) { // add the named entity tag to each token String neTag = output.get(i).get(AnswerAnnotation.class); tokens.get(i).set(CoreAnnotations.TrueCaseAnnotation.class, neTag); setTrueCaseText(tokens.get(i)); } } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }
CRFBiasedClassifier crf = new CRFBiasedClassifier(props); String testFile = crf.flags.testFile; String loadPath = crf.flags.loadClassifier; crf.loadClassifierNoExceptions(loadPath, props); } else if (crf.flags.loadJarClassifier != null) { crf.loadJarClassifier(crf.flags.loadJarClassifier, props); } else { crf.loadDefaultClassifier(); String cname = bias.nextToken(); double w = Double.parseDouble(bias.nextToken()); crf.setBiasWeight(cname,w); System.err.println("Setting bias for class "+cname+" to "+w); DocumentReaderAndWriter readerAndWriter = crf.makeReaderAndWriter(); if (crf.flags.printFirstOrderProbs) { crf.printFirstOrderProbs(testFile, readerAndWriter); } else if (crf.flags.printProbs) { crf.printProbs(testFile, readerAndWriter); } else if (crf.flags.useKBest) { int k = crf.flags.kBest; crf.classifyAndWriteAnswersKBest(testFile, k, readerAndWriter); } else { crf.classifyAndWriteAnswers(testFile, readerAndWriter);
public void setBiasWeight(int cindex, double weight) { addBiasFeature(); int fi = featureIndex.indexOf(BIAS); weights[fi][cindex] = weight; }
@Override public void annotate(Annotation annotation) { if (verbose) { log.info("Adding true-case annotation..."); } if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { // classify tokens for each sentence for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); List<CoreLabel> output = this.trueCaser.classifySentence(tokens); for (int i = 0, size = tokens.size(); i < size; i++) { // add the truecaser tag to each token String neTag = output.get(i).get(CoreAnnotations.AnswerAnnotation.class); tokens.get(i).set(CoreAnnotations.TrueCaseAnnotation.class, neTag); setTrueCaseText(tokens.get(i)); } } } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }