use of org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class CrfSuiteOutcomeIDReport method generateProperties.
protected Properties generateProperties(Map<String, Integer> aMapping, List<String> predictions, List<String> testFeatures) throws Exception {
Properties p = new SortedKeyProperties();
int maxLines = predictions.size();
for (int idx = 1; idx < maxLines; idx++) {
String entry = predictions.get(idx);
String[] split = entry.split("\t");
if (split.length != 2) {
continue;
}
String featureEntry = testFeatures.get(idx - 1);
String id = extractTCId(featureEntry);
String[] idsplit = id.split("_");
// make ids sortable by enforcing zero-prefixing
String zeroPaddedId = String.format("%04d_%04d_%04d%s", Integer.valueOf(idsplit[0]), Integer.valueOf(idsplit[1]), Integer.valueOf(idsplit[2]), idsplit.length > 3 ? "_" + idsplit[3] : "");
int numGold = aMapping.get(split[0]);
String numPred = getPrediction(aMapping, split[1]);
p.setProperty(zeroPaddedId, numPred + SEPARATOR_CHAR + numGold + SEPARATOR_CHAR + THRESHOLD_DUMMY_CONSTANT);
}
return p;
}
use of org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class LibsvmDataFormatOutcomeIdReport method execute.
@Override
public void execute() throws Exception {
init();
baslinePreparation();
Map<Integer, String> id2label = getId2LabelMapping(isRegression);
String header = buildHeader(id2label, isRegression);
List<String> predictions = readPredictions();
Map<String, String> index2instanceIdMap = getMapping(isUnit || isSequence);
Properties prop = new SortedKeyProperties();
int lineCounter = 0;
for (String line : predictions) {
if (line.startsWith("#")) {
continue;
}
String[] split = line.split(";");
String key = index2instanceIdMap.get(lineCounter + "");
String predictionString = getPrediction(split[0]);
String goldString = split[1];
if (isRegression) {
prop.setProperty(key, predictionString + ";" + goldString + ";" + THRESHOLD_CONSTANT);
} else {
int pred = Double.valueOf(predictionString).intValue();
int gold = Double.valueOf(goldString).intValue();
prop.setProperty(key, pred + ";" + gold + ";" + THRESHOLD_CONSTANT);
}
lineCounter++;
}
File targetFile = getTargetOutputFile();
FileWriterWithEncoding fw = null;
try {
fw = new FileWriterWithEncoding(targetFile, "utf-8");
prop.store(fw, header);
} finally {
IOUtils.closeQuietly(fw);
}
}
use of org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class KerasMetaReport method execute.
@Override
public void execute() throws Exception {
String python = getDiscriminator(getContext(), DIM_PYTHON_INSTALLATION);
String kerasVersion = getKerasVersion(python);
String numpyVersion = getNumpyVersion(python);
String tensorFlowVersion = getTensorflowVersion(python);
String theanoVersion = getTheanoVersion(python);
Properties p = new SortedKeyProperties();
p.setProperty("KerasVersion", kerasVersion);
p.setProperty("NumpyVersion", numpyVersion);
p.setProperty("TensorFlowVersion", tensorFlowVersion);
p.setProperty("TheanoVersion", theanoVersion);
File file = getContext().getFile("softwareVersions.txt", AccessMode.READWRITE);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
p.store(fos, "Version information");
} finally {
IOUtils.closeQuietly(fos);
}
}
use of org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class BasicResultReport method execute.
@Override
public void execute() throws Exception {
String learningMode = getDiscriminator(getContext().getStorageService(), getContext().getId(), DIM_LEARNING_MODE);
Properties pa = new SortedKeyProperties();
pa = addPredictedResults(pa, learningMode);
pa = addMajorityBaselineResults(pa, learningMode);
pa = addRandomBaselineResult(pa, learningMode);
writeConfusionMatrixForSingleLabel(learningMode);
writeToDisk(pa);
}
use of org.dkpro.tc.ml.report.util.SortedKeyProperties in project dkpro-tc by dkpro.
the class DeepLearningId2OutcomeReport method execute.
@Override
public void execute() throws Exception {
init();
baselinePreparation();
File file = getContext().getFile(FILENAME_PREDICTION_OUT, AccessMode.READONLY);
List<String> predictions = getPredictions(file);
predictions = update(predictions);
Map<String, String> map = loadMap(isIntegerMode);
Map<String, String> inverseMap = inverseMap(map);
StringBuilder header = new StringBuilder();
header.append("ID=PREDICTION;GOLDSTANDARD;THRESHOLD\nlabels ");
List<String> k = new ArrayList<>(map.keySet());
for (Integer i = 0; i < map.keySet().size(); i++) {
if (!isRegression) {
if (!isIntegerMode) {
header.append(i + "=" + inverseMap.get(i + ""));
} else {
header.append(i + "=" + map.get(i + ""));
}
if (i + 1 < k.size()) {
header.append(" ");
}
}
}
List<String> nameOfTargets = getNameOfTargets();
Properties prop = new SortedKeyProperties();
int shift = 0;
for (int i = 0; i < predictions.size(); i++) {
String p = predictions.get(i);
if (p.startsWith("#Gold")) {
// targets files
continue;
}
if (p.trim().isEmpty()) {
shift++;
continue;
}
String id = determineId(nameOfTargets, i, shift);
String[] split = p.split("\t");
if (isMultiLabel) {
multilabelReport(id, split, isIntegerMode, prop, map);
continue;
}
String gold = null;
String prediction = null;
if (isRegression) {
gold = split[0];
prediction = split[1];
} else {
if (isIntegerMode) {
gold = split[0];
prediction = split[1];
} else {
gold = map.get(split[0]).toString();
prediction = map.get(split[1]).toString();
}
}
prop.setProperty("" + id, prediction + SEPARATOR_CHAR + gold + SEPARATOR_CHAR + THRESHOLD);
}
File id2o = getTargetFile();
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(new FileOutputStream(id2o), "utf-8");
prop.store(osw, header.toString());
} finally {
IOUtils.closeQuietly(osw);
}
}
Aggregations