Added per-epoch logs and fixed an issue where all the data would not be iterated through each epoch.
@@ -244,8 +244,8 @@ public class NeuralModel extends SupportingModel {
log.trace("Initial fitting {}.", this);
- model.clear();
-
+ for (int i = 0; i < initialEpochs; i++) {
+ // Note that we need to create a new Iterable because the inner Iterable does not support resetting.
Iterable<Pair<INDArray, INDArray>> pairs = IteratorUtils.map(
observedLabels.entrySet(),
new IteratorUtils.MapFunction<Map.Entry<Integer, float[]>, Pair<INDArray, INDArray>> () {
@@ -256,17 +256,20 @@ public class NeuralModel extends SupportingModel {
});
DataSetIterator data = new INDArrayDataSetIterator(pairs, Math.min(initialMaxBatchSize, observedLabels.size()));
- model.fit(data, initialEpochs);
- log.trace("Done initial fitting {}.", this);
+ model.clear();
+ model.fit(data);
+
+ log.trace("Epoch: {} / {}, Score: {} {}", i + 1, initialEpochs, model.score(), lossFunction);
+ }
+
+ log.debug("Done initial fitting {} with {} epochs. Score: {} {}.", this, initialEpochs, model.score(), lossFunction);
}
@Override
public void fit() {
log.trace("Fitting {}.", this);
- model.clear();
-
if (normalizeLabels) {
normalizeLabels();
}
@@ -285,6 +288,8 @@ public class NeuralModel extends SupportingModel {
INDArray labels = Nd4j.create(manualLabels);
+ for (int i = 0; i < epochs; i++) {
+ // Note that we need to create a new Iterable because the inner Iterable does not support resetting.
Iterable<Pair<INDArray, INDArray>> pairs = IteratorUtils.map(
IteratorUtils.newIterable(IteratorUtils.count(entityIndexMapping.size())),
new IteratorUtils.MapFunction<Integer, Pair<INDArray, INDArray>> () {
@@ -294,11 +299,15 @@ public class NeuralModel extends SupportingModel {
}
});
-
DataSetIterator data = new INDArrayDataSetIterator(pairs, Math.min(maxBatchSize, entityIndexMapping.size()));
- model.fit(data, epochs);
- log.trace("Done fitting {}.", this);
+ model.clear();
+ model.fit(data);
+
+ log.trace("Epoch: {} / {}, Score: {} {}", i + 1, epochs, model.score(), lossFunction);
+ }
+
+ log.debug("Done fitting {} with {} epochs. Score: {} {}.", this, epochs, model.score(), lossFunction);
}
private void normalizeLabels() {
