{"action":"created","comment":{"url":"https://api.github.com/repos/bst-mug/n2c2/pulls/comments/182511915","pull_request_review_id":113322293,"id":182511915,"diff_hunk":"@@ -0,0 +1,656 @@\n+package at.medunigraz.imi.bst.n2c2.nn;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Random;\n+import java.util.concurrent.TimeUnit;\n+\n+import org.apache.logging.log4j.LogManager;\n+import org.apache.logging.log4j.Logger;\n+import org.deeplearning4j.api.storage.StatsStorage;\n+import org.deeplearning4j.earlystopping.EarlyStoppingConfiguration;\n+import org.deeplearning4j.earlystopping.EarlyStoppingModelSaver;\n+import org.deeplearning4j.earlystopping.EarlyStoppingResult;\n+import org.deeplearning4j.earlystopping.saver.InMemoryModelSaver;\n+import org.deeplearning4j.earlystopping.scorecalc.DataSetLossCalculator;\n+import org.deeplearning4j.earlystopping.termination.MaxEpochsTerminationCondition;\n+import org.deeplearning4j.earlystopping.termination.MaxScoreIterationTerminationCondition;\n+import org.deeplearning4j.earlystopping.termination.MaxTimeIterationTerminationCondition;\n+import org.deeplearning4j.earlystopping.termination.ScoreImprovementEpochTerminationCondition;\n+import org.deeplearning4j.earlystopping.trainer.EarlyStoppingTrainer;\n+import org.deeplearning4j.earlystopping.trainer.IEarlyStoppingTrainer;\n+import org.deeplearning4j.eval.Evaluation;\n+import org.deeplearning4j.eval.EvaluationBinary;\n+import org.deeplearning4j.nn.api.Layer;\n+import org.deeplearning4j.nn.conf.GradientNormalization;\n+import org.deeplearning4j.nn.conf.MultiLayerConfiguration;\n+import org.deeplearning4j.nn.conf.NeuralNetConfiguration;\n+import org.deeplearning4j.nn.conf.WorkspaceMode;\n+import org.deeplearning4j.nn.conf.layers.DenseLayer;\n+import org.deeplearning4j.nn.conf.layers.GravesBidirectionalLSTM;\n+import org.deeplearning4j.nn.conf.layers.GravesLSTM;\n+import org.deeplearning4j.nn.conf.layers.RnnOutputLayer;\n+import org.deeplearning4j.nn.conf.preprocessor.FeedForwardToRnnPreProcessor;\n+import org.deeplearning4j.nn.conf.preprocessor.RnnToFeedForwardPreProcessor;\n+import org.deeplearning4j.nn.multilayer.MultiLayerNetwork;\n+import org.deeplearning4j.nn.weights.WeightInit;\n+import org.deeplearning4j.optimize.listeners.ScoreIterationListener;\n+import org.deeplearning4j.ui.api.UIServer;\n+import org.deeplearning4j.ui.stats.StatsListener;\n+import org.deeplearning4j.ui.storage.InMemoryStatsStorage;\n+import org.deeplearning4j.util.ModelSerializer;\n+import org.nd4j.linalg.activations.Activation;\n+import org.nd4j.linalg.api.ndarray.INDArray;\n+import org.nd4j.linalg.dataset.DataSet;\n+import org.nd4j.linalg.factory.Nd4j;\n+import org.nd4j.linalg.indexing.NDArrayIndex;\n+import org.nd4j.linalg.learning.config.AdaGrad;\n+import org.nd4j.linalg.learning.config.Adam;\n+import org.nd4j.linalg.lossfunctions.LossFunctions;\n+\n+import at.medunigraz.imi.bst.n2c2.classifier.Classifier;\n+import at.medunigraz.imi.bst.n2c2.model.Criterion;\n+import at.medunigraz.imi.bst.n2c2.model.Eligibility;\n+import at.medunigraz.imi.bst.n2c2.model.Patient;\n+\n+/**\n+ * BI-LSTM classifier for n2c2 task 2018 refactored from dl4j examples.\n+ * \n+ * @author Markus\n+ *\n+ */\n+public class BILSTMC3GClassifier implements Classifier {\n+\n+\t// size of mini-batch for training\n+\tprivate int miniBatchSize = 10;\n+\n+\t// length for truncated backpropagation through time\n+\tprivate int tbpttLength = 50;\n+\n+\t// total number of training epochs\n+\tprivate int nEpochs = 35;\n+\n+\t// specifies time series length\n+\tpublic int truncateLength = 64;\n+\n+\tpublic int vectorSize;\n+\n+\t// training data\n+\tprivate List<Patient> patientExamples;\n+\n+\t// multi layer network\n+\tprivate MultiLayerNetwork net;\n+\n+\t// criterion index\n+\tprivate Map<Criterion, Integer> criterionIndex = new HashMap<Criterion, Integer>();\n+\n+\tpublic NGramIterator fullSetIteration;\n+\n+\tprivate static final Logger LOG = LogManager.getLogger();\n+\n+\tpublic BILSTMC3GClassifier() {\n+\t\tthrow new org.apache.commons.lang.NotImplementedException(\n+\t\t\t\t\"BILSTMClassifier empty constructor is not implemented!\");\n+\t}\n+\n+\tpublic BILSTMC3GClassifier(String pathToWordVectors, String modelName) {\n+\n+\t\tinitializeCriterionIndex();\n+\n+\t\t// TODO load from persisted variable via properties file\n+\t\tthis.truncateLength = 0;\n+\t\tthis.initializeNetworkFromFile(modelName);\n+\n+\t}\n+\n+\tpublic BILSTMC3GClassifier(List<Patient> examples) {\n+\n+\t\tthis.patientExamples = examples;\n+\n+\t\tinitializeNetworkBinaryMultiLabel();\n+\t\t// initializeNetworkDebug();\n+\t\tinitializeMonitoring();\n+\n+\t\tLOG.info(\"Minibatchsize  :\\t\" + miniBatchSize);\n+\t\tLOG.info(\"tbptt length   :\\t\" + tbpttLength);\n+\t\tLOG.info(\"Epochs         :\\t\" + nEpochs);\n+\t\tLOG.info(\"Truncate length:\\t\" + truncateLength);\n+\t}\n+\n+\tprivate void initializeCriterionIndex() {\n+\t\tthis.criterionIndex.put(Criterion.ABDOMINAL, 0);\n+\t\tthis.criterionIndex.put(Criterion.ADVANCED_CAD, 1);\n+\t\tthis.criterionIndex.put(Criterion.ALCOHOL_ABUSE, 2);\n+\t\tthis.criterionIndex.put(Criterion.ASP_FOR_MI, 3);\n+\t\tthis.criterionIndex.put(Criterion.CREATININE, 4);\n+\t\tthis.criterionIndex.put(Criterion.DIETSUPP_2MOS, 5);\n+\t\tthis.criterionIndex.put(Criterion.DRUG_ABUSE, 6);\n+\t\tthis.criterionIndex.put(Criterion.ENGLISH, 7);\n+\t\tthis.criterionIndex.put(Criterion.HBA1C, 8);\n+\t\tthis.criterionIndex.put(Criterion.KETO_1YR, 9);\n+\t\tthis.criterionIndex.put(Criterion.MAJOR_DIABETES, 10);\n+\t\tthis.criterionIndex.put(Criterion.MAKES_DECISIONS, 11);\n+\t\tthis.criterionIndex.put(Criterion.MI_6MOS, 12);\n+\t}\n+\n+\tpublic void initializeNetworkFromFile(String modelFile) {\n+\t\ttry {\n+\t\t\tFile networkFile = new File(getClass().getResource(\"/models/\" + modelFile).getPath());\n+\t\t\tthis.net = ModelSerializer.restoreMultiLayerNetwork(networkFile);\n+\t\t} catch (IOException e) {\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * SIGMOID activation and XENT loss function for binary multi-label\n+\t * classification.\n+\t */\n+\tprivate void initializeNetworkDebug() {\n+\n+\t\t// https://deeplearning4j.org/workspaces\n+\t\t// Nd4j.getMemoryManager().setAutoGcWindow(10000);\n+\t\tNd4j.getMemoryManager().togglePeriodicGc(false);\n+\n+\t\ttry {\n+\t\t\tfullSetIteration = new NGramIterator(patientExamples, miniBatchSize);\n+\t\t} catch (IOException e) {\n+\t\t\t// TODO Auto-generated catch block\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t\tvectorSize = fullSetIteration.vectorSize;\n+\t\ttruncateLength = fullSetIteration.maxSentences;\n+\n+\t\t// seed for reproducibility\n+\t\tfinal int seed = 12345;\n+\t\tMultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(seed)\n+\t\t\t\t.updater(Adam.builder().beta1(0.9).beta2(0.999).build()).regularization(true).l2(1e-5)\n+\t\t\t\t.weightInit(WeightInit.XAVIER).gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)\n+\t\t\t\t.gradientNormalizationThreshold(1.0).learningRate(2e-2).trainingWorkspaceMode(WorkspaceMode.SEPARATE)\n+\t\t\t\t.inferenceWorkspaceMode(WorkspaceMode.SEPARATE).list()\n+\t\t\t\t.layer(0, new GravesLSTM.Builder().nIn(vectorSize).nOut(256).activation(Activation.TANH).build())\n+\t\t\t\t.layer(1,\n+\t\t\t\t\t\tnew RnnOutputLayer.Builder().activation(Activation.SIGMOID)\n+\t\t\t\t\t\t\t\t.lossFunction(LossFunctions.LossFunction.XENT).nIn(256).nOut(13).build())\n+\t\t\t\t.pretrain(false).backprop(true).build();\n+\n+\t\tthis.net = new MultiLayerNetwork(conf);\n+\t\tthis.net.init();\n+\t\tthis.net.setListeners(new ScoreIterationListener(1));\n+\t}\n+\n+\t/**\n+\t * SIGMOID activation and XENT loss function for binary multi-label\n+\t * classification.\n+\t */\n+\tprivate void initializeNetworkBinaryMultiLabel() {\n+\n+\t\t// settings for memory management:\n+\t\t// https://deeplearning4j.org/workspaces\n+\n+\t\tNd4j.getMemoryManager().setAutoGcWindow(10000);\n+\t\t//Nd4j.getMemoryManager().togglePeriodicGc(false);\n+\n+\t\ttry {\n+\t\t\tfullSetIteration = new NGramIterator(patientExamples, miniBatchSize);\n+\t\t} catch (IOException e) {\n+\t\t\t// TODO Auto-generated catch block\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t\tvectorSize = fullSetIteration.vectorSize;\n+\t\ttruncateLength = fullSetIteration.maxSentences;\n+\n+\t\t// seed for reproducibility\n+\t\tfinal int seed = 12345;\n+\t\tMultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().seed(seed)\n+\t\t\t\t.updater(Adam.builder().beta1(0.9).beta2(0.999).build()).regularization(true).l2(1e-5)\n+\t\t\t\t.weightInit(WeightInit.XAVIER).gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)\n+\t\t\t\t.gradientNormalizationThreshold(1.0).learningRate(2e-2).trainingWorkspaceMode(WorkspaceMode.NONE)\n+\t\t\t\t.inferenceWorkspaceMode(WorkspaceMode.NONE).list()\n+\t\t\t\t.layer(0,\n+\t\t\t\t\t\tnew DenseLayer.Builder().activation(Activation.RELU).nIn(vectorSize).nOut(300)\n+\t\t\t\t\t\t\t\t.weightInit(WeightInit.RELU).updater(AdaGrad.builder().learningRate(0.01).build())\n+\t\t\t\t\t\t\t\t.gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)\n+\t\t\t\t\t\t\t\t.gradientNormalizationThreshold(10).learningRate(0.01).build())\n+\t\t\t\t.layer(1, new GravesBidirectionalLSTM.Builder().nIn(300).nOut(300).activation(Activation.TANH).build())\n+\t\t\t\t.layer(2, new GravesLSTM.Builder().nIn(300).nOut(300).activation(Activation.TANH).build())\n+\t\t\t\t.layer(3,\n+\t\t\t\t\t\tnew RnnOutputLayer.Builder().activation(Activation.SIGMOID)\n+\t\t\t\t\t\t\t\t.lossFunction(LossFunctions.LossFunction.XENT).nIn(300).nOut(13).build())\n+\t\t\t\t.inputPreProcessor(0, new RnnToFeedForwardPreProcessor())\n+\t\t\t\t.inputPreProcessor(1, new FeedForwardToRnnPreProcessor()).pretrain(false).backprop(true).build();\n+\n+\t\tthis.net = new MultiLayerNetwork(conf);\n+\t\tthis.net.init();\n+\t\tthis.net.setListeners(new ScoreIterationListener(1));\n+\t}\n+\n+\t/**\n+\t * Initialize monitoring.\n+\t * \n+\t */\n+\tprivate void initializeMonitoring() {\n+\t\t// setting monitor\n+\t\tUIServer uiServer = UIServer.getInstance();\n+\n+\t\t// Configure where the network information (gradients, score vs. time\n+\t\t// etc) is to be stored. Here: store in memory.\n+\t\t// Alternative: new FileStatsStorage(File), for saving and loading later\n+\t\tStatsStorage statsStorage = new InMemoryStatsStorage();\n+\n+\t\t// Attach the StatsStorage instance to the UI: this allows the contents\n+\t\t// of the StatsStorage to be visualized\n+\t\tuiServer.attach(statsStorage);\n+\n+\t\t// Then add the StatsListener to collect this information from the\n+\t\t// network, as it trains\n+\t\tnet.setListeners(new StatsListener(statsStorage));\n+\t}\n+\n+\t/**\n+\t * \n+\t * \n+\t * @param examples\n+\t * @param trainingSplit\n+\t * @param validationSplit\n+\t * @param testSplit\n+\t */\n+\tprivate void getSplits(List<Patient> examples, List<Patient> trainingSplit, List<Patient> validationSplit,\n+\t\t\tList<Patient> testSplit) {\n+\n+\t\t// TODO generalize\n+\t\t// --------------------------------------\n+\t\t// abdominal 60 split: 77 / 125 - 46 / 75\n+\t\t// abdominal 20 split: 77 / 125 - 16 / 25\n+\t\t// abdominal 20 split: 77 / 125 - 15 / 25\n+\t\t// --------------------------------------\n+\t\t// abdominal 100 : 77 / 125 - 77 / 25\n+\n+\t\tint counterPos = 1;\n+\t\tint counterNeg = 1;\n+\n+\t\tfor (Patient patient : examples) {\n+\t\t\tif (patient.getEligibility(Criterion.ABDOMINAL).equals(Eligibility.MET)) {\n+\t\t\t\tif (counterPos > 62) {\n+\t\t\t\t\ttestSplit.add(patient);\n+\t\t\t\t} else if (counterPos > 46) {\n+\t\t\t\t\tvalidationSplit.add(patient);\n+\t\t\t\t\tcounterPos++;\n+\t\t\t\t} else {\n+\t\t\t\t\ttrainingSplit.add(patient);\n+\t\t\t\t\tcounterPos++;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tif (counterNeg > 100) {\n+\t\t\t\t\ttestSplit.add(patient);\n+\t\t\t\t} else if (counterNeg > 75) {\n+\t\t\t\t\tvalidationSplit.add(patient);\n+\t\t\t\t\tcounterNeg++;\n+\t\t\t\t} else {\n+\t\t\t\t\ttrainingSplit.add(patient);\n+\t\t\t\t\tcounterNeg++;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tprivate void trainWithEarlyStoppingBML(List<Patient> examples) {\n+\n+\t\tList<Patient> trainingSplit = new ArrayList<Patient>();\n+\t\tList<Patient> validationSplit = new ArrayList<Patient>();\n+\t\tList<Patient> testSplit = new ArrayList<Patient>();\n+\n+\t\t// generate splits (60 20 20)\n+\t\tgetSplits(examples, trainingSplit, validationSplit, testSplit);\n+\n+\t\tNGramIterator training;\n+\t\tNGramIterator validation;\n+\t\tNGramIterator test;\n+\n+\t\ttry {\n+\t\t\ttraining = new NGramIterator(trainingSplit, miniBatchSize);\n+\t\t\tvalidation = new NGramIterator(validationSplit, miniBatchSize, training.characterNGram_3,\n+\t\t\t\t\ttraining.char3GramToIdxMap);\n+\t\t\ttest = new NGramIterator(testSplit, miniBatchSize, training.characterNGram_3, training.char3GramToIdxMap);\n+\n+\t\t\t// early stopping on validation\n+\t\t\tEarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();\n+\t\t\tEarlyStoppingConfiguration<MultiLayerNetwork> esConf = new EarlyStoppingConfiguration.Builder<MultiLayerNetwork>()\n+\t\t\t\t\t.epochTerminationConditions(new MaxEpochsTerminationCondition(100),\n+\t\t\t\t\t\t\tnew ScoreImprovementEpochTerminationCondition(5))\n+\t\t\t\t\t.iterationTerminationConditions(new MaxTimeIterationTerminationCondition(4, TimeUnit.HOURS),\n+\t\t\t\t\t\t\tnew MaxScoreIterationTerminationCondition(7.5))\n+\t\t\t\t\t.scoreCalculator(new DataSetLossCalculator(validation, true)).modelSaver(saver).build();\n+\n+\t\t\t// conduct early stopping training\n+\t\t\tIEarlyStoppingTrainer trainer = new EarlyStoppingTrainer(esConf, net, training);\n+\t\t\tEarlyStoppingResult result = trainer.fit();\n+\n+\t\t\tLOG.info(\"Termination reason: \" + result.getTerminationReason());\n+\t\t\tLOG.info(\"Termination details: \" + result.getTerminationDetails());\n+\t\t\tLOG.info(\"Total epochs: \" + result.getTotalEpochs());\n+\t\t\tLOG.info(\"Best epoch number: \" + result.getBestModelEpoch());\n+\t\t\tLOG.info(\"Score at best epoch: \" + result.getBestModelScore());\n+\n+\t\t\t// run evaluation on test data\n+\t\t\tLOG.info(\"Printing TEST evaluation measurements\");\n+\t\t\tEvaluation evaluationTest = net.evaluate(test);\n+\t\t\tLOG.info(evaluationTest.stats());\n+\n+\t\t\t// run evaluation on validation data\n+\t\t\tLOG.info(\"Printing VALIDAITON evaluation measurements\");\n+\t\t\tEvaluation evaluationValidation = net.evaluate(validation);\n+\t\t\tLOG.info(evaluationValidation.stats());\n+\n+\t\t\t// run evaluation on test data\n+\t\t\tLOG.info(\"Printing TRAINING evaluation measurements\");\n+\t\t\tEvaluation evaluationTraining = net.evaluate(training);\n+\t\t\tLOG.info(evaluationTraining.stats());\n+\n+\t\t} catch (IOException e) {\n+\t\t\t// TODO Auto-generated catch block\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t}\n+\n+\tprivate void trainWithEarlyStopping(List<Patient> examples) {\n+\n+\t\tList<Patient> trainingSplit = new ArrayList<Patient>();\n+\t\tList<Patient> validationSplit = new ArrayList<Patient>();\n+\t\tList<Patient> testSplit = new ArrayList<Patient>();\n+\n+\t\t// generate splits (60 20 20)\n+\t\tgetSplits(examples, trainingSplit, validationSplit, testSplit);\n+\n+\t\tNGramIterator training;\n+\t\tNGramIterator validation;\n+\t\tNGramIterator test;\n+\n+\t\ttry {\n+\t\t\ttraining = new NGramIterator(trainingSplit, miniBatchSize);\n+\t\t\tvalidation = new NGramIterator(validationSplit, miniBatchSize, training.characterNGram_3,\n+\t\t\t\t\ttraining.char3GramToIdxMap);\n+\t\t\ttest = new NGramIterator(testSplit, miniBatchSize, training.characterNGram_3, training.char3GramToIdxMap);\n+\n+\t\t\t// early stopping on validation\n+\t\t\tEarlyStoppingModelSaver<MultiLayerNetwork> saver = new InMemoryModelSaver<>();\n+\t\t\tEarlyStoppingConfiguration<MultiLayerNetwork> esConf = new EarlyStoppingConfiguration.Builder<MultiLayerNetwork>()\n+\t\t\t\t\t.epochTerminationConditions(new MaxEpochsTerminationCondition(100),\n+\t\t\t\t\t\t\tnew ScoreImprovementEpochTerminationCondition(5))\n+\t\t\t\t\t.iterationTerminationConditions(new MaxTimeIterationTerminationCondition(4, TimeUnit.HOURS),\n+\t\t\t\t\t\t\tnew MaxScoreIterationTerminationCondition(7.5))\n+\t\t\t\t\t.scoreCalculator(new DataSetLossCalculator(validation, true)).modelSaver(saver).build();\n+\n+\t\t\t// conduct early stopping training\n+\t\t\tIEarlyStoppingTrainer trainer = new EarlyStoppingTrainer(esConf, net, training);\n+\t\t\tEarlyStoppingResult result = trainer.fit();\n+\n+\t\t\tLOG.info(\"Termination reason: \" + result.getTerminationReason());\n+\t\t\tLOG.info(\"Termination details: \" + result.getTerminationDetails());\n+\t\t\tLOG.info(\"Total epochs: \" + result.getTotalEpochs());\n+\t\t\tLOG.info(\"Best epoch number: \" + result.getBestModelEpoch());\n+\t\t\tLOG.info(\"Score at best epoch: \" + result.getBestModelScore());\n+\n+\t\t\t// run evaluation on test data\n+\t\t\tLOG.info(\"Printing TEST evaluation measurements\");\n+\t\t\tEvaluation evaluationTest = net.evaluate(test);\n+\t\t\tLOG.info(evaluationTest.stats());\n+\n+\t\t\t// run evaluation on validation data\n+\t\t\tLOG.info(\"Printing VALIDAITON evaluation measurements\");\n+\t\t\tEvaluation evaluationValidation = net.evaluate(validation);\n+\t\t\tLOG.info(evaluationValidation.stats());\n+\n+\t\t\t// run evaluation on test data\n+\t\t\tLOG.info(\"Printing TRAINING evaluation measurements\");\n+\t\t\tEvaluation evaluationTraining = net.evaluate(training);\n+\t\t\tLOG.info(evaluationTraining.stats());\n+\n+\t\t} catch (IOException e) {\n+\t\t\t// TODO Auto-generated catch block\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t}\n+\n+\t/**\n+\t * Training for binary multi label classifcation.\n+\t * \n+\t * @param examples\n+\t *            Patient training examples.\n+\t */\n+\tprivate void trainFullSetBML(List<Patient> examples) {\n+\n+\t\tList<Patient> trainingSplit = new ArrayList<Patient>();\n+\t\tList<Patient> validationSplit = new ArrayList<Patient>();\n+\t\tList<Patient> combinedSplit = new ArrayList<Patient>();\n+\t\tList<Patient> testSplit = new ArrayList<Patient>();\n+\n+\t\t// generate splits (60 20 20)\n+\t\tgetSplits(examples, trainingSplit, validationSplit, testSplit);\n+\t\tcombinedSplit.addAll(trainingSplit);\n+\t\tcombinedSplit.addAll(validationSplit);\n+\n+\t\tNGramIterator training;\n+\t\tNGramIterator validation;\n+\t\tNGramIterator combined;\n+\t\tNGramIterator test;\n+\t\tNGramIterator fullSet;\n+\n+\t\tRandom rng = new Random(12345);\n+\n+\t\t// print the number of parameters in the network (and for each layer)\n+\t\tLayer[] layers = net.getLayers();\n+\t\tint totalNumParams = 0;\n+\t\tfor (int i = 0; i < layers.length; i++) {\n+\t\t\tint nParams = layers[i].numParams();\n+\t\t\tLOG.info(\"Number of parameters in layer \" + i + \": \" + nParams);\n+\t\t\ttotalNumParams += nParams;\n+\t\t}\n+\t\tLOG.info(\"Total number of network parameters: \" + totalNumParams);\n+\n+\t\ttry {\n+\n+\t\t\t// combined = new NGramIterator(combinedSplit, miniBatchSize);\n+\t\t\t// test = new NGramIterator(testSplit, miniBatchSize,\n+\t\t\t// combined.characterNGram_3, combined.char3GramToIdxMap);\n+\t\t\t// fullSet = new NGramIterator(examples, miniBatchSize,\n+\t\t\t// combined.characterNGram_3, combined.char3GramToIdxMap);\n+\n+\t\t\tfor (int i = 0; i < nEpochs; i++) {\n+\n+\t\t\t\tnet.fit(fullSetIteration);\n+\t\t\t\tfullSetIteration.reset();\n+\n+\t\t\t\tLOG.info(\"Epoch \" + i + \" complete.\");\n+\t\t\t\tLOG.info(\"Starting FULL SET evaluation:\");\n+\n+\t\t\t\tEvaluationBinary eb = new EvaluationBinary();\n+\t\t\t\twhile (fullSetIteration.hasNext()) {\n+\t\t\t\t\tDataSet t = fullSetIteration.next();\n+\t\t\t\t\tINDArray features = t.getFeatureMatrix();\n+\t\t\t\t\tINDArray lables = t.getLabels();\n+\t\t\t\t\tINDArray inMask = t.getFeaturesMaskArray();\n+\t\t\t\t\tINDArray outMask = t.getLabelsMaskArray();\n+\t\t\t\t\tINDArray predicted = net.output(features, false, inMask, outMask);\n+\n+\t\t\t\t\teb.eval(lables, predicted, outMask);\n+\t\t\t\t}\n+\t\t\t\tfullSetIteration.reset();\n+\t\t\t\tLOG.info(eb.stats());\n+\n+\t\t\t\t// net.fit(combined);\n+\t\t\t\t// combined.reset();\n+\t\t\t\t//\n+\t\t\t\t// LOG.info(\"Epoch \" + i + \" complete.\");\n+\t\t\t\t// LOG.info(\"Starting COMBINED (TRAINING + VALIDATION)\n+\t\t\t\t// evaluation:\");\n+\t\t\t\t//\n+\t\t\t\t// EvaluationBinary eb = new EvaluationBinary();\n+\t\t\t\t// while (combined.hasNext()) {\n+\t\t\t\t// DataSet t = combined.next();\n+\t\t\t\t// INDArray features = t.getFeatureMatrix();\n+\t\t\t\t// INDArray lables = t.getLabels();\n+\t\t\t\t// INDArray inMask = t.getFeaturesMaskArray();\n+\t\t\t\t// INDArray outMask = t.getLabelsMaskArray();\n+\t\t\t\t// INDArray predicted = net.output(features, false, inMask,\n+\t\t\t\t// outMask);\n+\t\t\t\t//\n+\t\t\t\t// eb.eval(lables, predicted, outMask);\n+\t\t\t\t// }\n+\t\t\t\t// combined.reset();\n+\t\t\t\t// LOG.info(System.getProperty(\"line.separator\") + eb.stats());\n+\t\t\t\t//\n+\t\t\t\t// LOG.info(\"Starting TEST evaluation:\");\n+\t\t\t\t// // run evaluation on test data\n+\t\t\t\t// eb = new EvaluationBinary();\n+\t\t\t\t// while (test.hasNext()) {\n+\t\t\t\t// DataSet t = test.next();\n+\t\t\t\t// INDArray features = t.getFeatureMatrix();\n+\t\t\t\t// INDArray lables = t.getLabels();\n+\t\t\t\t// INDArray inMask = t.getFeaturesMaskArray();\n+\t\t\t\t// INDArray outMask = t.getLabelsMaskArray();\n+\t\t\t\t// INDArray predicted = net.output(features, false, inMask,\n+\t\t\t\t// outMask);\n+\t\t\t\t//\n+\t\t\t\t// eb.eval(lables, predicted, outMask);\n+\t\t\t\t// }\n+\t\t\t\t// test.reset();\n+\t\t\t\t// LOG.info(System.getProperty(\"line.separator\") + eb.stats());\n+\t\t\t}\n+\n+\t\t\t// save model after n epochs\n+\t\t\tFile locationToSave = new File(\"N2c2BILSTMC3G_MBL_Full_\" + nEpochs + \".zip\");\n+\t\t\tboolean saveUpdater = true;\n+\t\t\tModelSerializer.writeModel(net, locationToSave, saveUpdater);\n+\n+\t\t} catch (IOException e) {\n+\t\t\t// TODO Auto-generated catch block\n+\t\t\te.printStackTrace();\n+\t\t}\n+\t}\n+\n+\tprivate void trainFullSet(List<Patient> examples) {","path":"src/main/java/at/medunigraz/imi/bst/n2c2/nn/BILSTMC3GClassifier.java","position":536,"original_position":536,"commit_id":"df36c13b180296d79e729269224413860c82eaed","original_commit_id":"df36c13b180296d79e729269224413860c82eaed","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars1.githubusercontent.com/u/19940114?v=4","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://app.codacy.com/assets/images/favicon.png) Issue found: [Avoid unused private methods such as 'trainFullSet(List)'.](https://app.codacy.com/app/michelole/n2c2/pullRequest?prid=1556603)","created_at":"2018-04-18T17:42:48Z","updated_at":"2018-04-18T17:42:48Z","html_url":"https://github.com/bst-mug/n2c2/pull/50#discussion_r182511915","pull_request_url":"https://api.github.com/repos/bst-mug/n2c2/pulls/50","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/bst-mug/n2c2/pulls/comments/182511915"},"html":{"href":"https://github.com/bst-mug/n2c2/pull/50#discussion_r182511915"},"pull_request":{"href":"https://api.github.com/repos/bst-mug/n2c2/pulls/50"}}},"pull_request":{"url":"https://api.github.com/repos/bst-mug/n2c2/pulls/50","id":182552662,"html_url":"https://github.com/bst-mug/n2c2/pull/50","diff_url":"https://github.com/bst-mug/n2c2/pull/50.diff","patch_url":"https://github.com/bst-mug/n2c2/pull/50.patch","issue_url":"https://api.github.com/repos/bst-mug/n2c2/issues/50","number":50,"state":"open","locked":false,"title":"Issue 48","user":{"login":"michelole","id":1688126,"avatar_url":"https://avatars2.githubusercontent.com/u/1688126?v=4","gravatar_id":"","url":"https://api.github.com/users/michelole","html_url":"https://github.com/michelole","followers_url":"https://api.github.com/users/michelole/followers","following_url":"https://api.github.com/users/michelole/following{/other_user}","gists_url":"https://api.github.com/users/michelole/gists{/gist_id}","starred_url":"https://api.github.com/users/michelole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michelole/subscriptions","organizations_url":"https://api.github.com/users/michelole/orgs","repos_url":"https://api.github.com/users/michelole/repos","events_url":"https://api.github.com/users/michelole/events{/privacy}","received_events_url":"https://api.github.com/users/michelole/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-04-18T17:39:55Z","updated_at":"2018-04-18T17:42:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d8bf6fba5bbe8dbc880590c5bcabfb0f24c9e302","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/bst-mug/n2c2/pulls/50/commits","review_comments_url":"https://api.github.com/repos/bst-mug/n2c2/pulls/50/comments","review_comment_url":"https://api.github.com/repos/bst-mug/n2c2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bst-mug/n2c2/issues/50/comments","statuses_url":"https://api.github.com/repos/bst-mug/n2c2/statuses/df36c13b180296d79e729269224413860c82eaed","head":{"label":"michelole:issue-48","ref":"issue-48","sha":"df36c13b180296d79e729269224413860c82eaed","user":{"login":"michelole","id":1688126,"avatar_url":"https://avatars2.githubusercontent.com/u/1688126?v=4","gravatar_id":"","url":"https://api.github.com/users/michelole","html_url":"https://github.com/michelole","followers_url":"https://api.github.com/users/michelole/followers","following_url":"https://api.github.com/users/michelole/following{/other_user}","gists_url":"https://api.github.com/users/michelole/gists{/gist_id}","starred_url":"https://api.github.com/users/michelole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michelole/subscriptions","organizations_url":"https://api.github.com/users/michelole/orgs","repos_url":"https://api.github.com/users/michelole/repos","events_url":"https://api.github.com/users/michelole/events{/privacy}","received_events_url":"https://api.github.com/users/michelole/received_events","type":"User","site_admin":false},"repo":{"id":125199257,"name":"n2c2","full_name":"michelole/n2c2","owner":{"login":"michelole","id":1688126,"avatar_url":"https://avatars2.githubusercontent.com/u/1688126?v=4","gravatar_id":"","url":"https://api.github.com/users/michelole","html_url":"https://github.com/michelole","followers_url":"https://api.github.com/users/michelole/followers","following_url":"https://api.github.com/users/michelole/following{/other_user}","gists_url":"https://api.github.com/users/michelole/gists{/gist_id}","starred_url":"https://api.github.com/users/michelole/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michelole/subscriptions","organizations_url":"https://api.github.com/users/michelole/orgs","repos_url":"https://api.github.com/users/michelole/repos","events_url":"https://api.github.com/users/michelole/events{/privacy}","received_events_url":"https://api.github.com/users/michelole/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/michelole/n2c2","description":"Supporting code for participation at the 2018 n2c2 Shared-Task","fork":true,"url":"https://api.github.com/repos/michelole/n2c2","forks_url":"https://api.github.com/repos/michelole/n2c2/forks","keys_url":"https://api.github.com/repos/michelole/n2c2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/michelole/n2c2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/michelole/n2c2/teams","hooks_url":"https://api.github.com/repos/michelole/n2c2/hooks","issue_events_url":"https://api.github.com/repos/michelole/n2c2/issues/events{/number}","events_url":"https://api.github.com/repos/michelole/n2c2/events","assignees_url":"https://api.github.com/repos/michelole/n2c2/assignees{/user}","branches_url":"https://api.github.com/repos/michelole/n2c2/branches{/branch}","tags_url":"https://api.github.com/repos/michelole/n2c2/tags","blobs_url":"https://api.github.com/repos/michelole/n2c2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/michelole/n2c2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/michelole/n2c2/git/refs{/sha}","trees_url":"https://api.github.com/repos/michelole/n2c2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/michelole/n2c2/statuses/{sha}","languages_url":"https://api.github.com/repos/michelole/n2c2/languages","stargazers_url":"https://api.github.com/repos/michelole/n2c2/stargazers","contributors_url":"https://api.github.com/repos/michelole/n2c2/contributors","subscribers_url":"https://api.github.com/repos/michelole/n2c2/subscribers","subscription_url":"https://api.github.com/repos/michelole/n2c2/subscription","commits_url":"https://api.github.com/repos/michelole/n2c2/commits{/sha}","git_commits_url":"https://api.github.com/repos/michelole/n2c2/git/commits{/sha}","comments_url":"https://api.github.com/repos/michelole/n2c2/comments{/number}","issue_comment_url":"https://api.github.com/repos/michelole/n2c2/issues/comments{/number}","contents_url":"https://api.github.com/repos/michelole/n2c2/contents/{+path}","compare_url":"https://api.github.com/repos/michelole/n2c2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/michelole/n2c2/merges","archive_url":"https://api.github.com/repos/michelole/n2c2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/michelole/n2c2/downloads","issues_url":"https://api.github.com/repos/michelole/n2c2/issues{/number}","pulls_url":"https://api.github.com/repos/michelole/n2c2/pulls{/number}","milestones_url":"https://api.github.com/repos/michelole/n2c2/milestones{/number}","notifications_url":"https://api.github.com/repos/michelole/n2c2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/michelole/n2c2/labels{/name}","releases_url":"https://api.github.com/repos/michelole/n2c2/releases{/id}","deployments_url":"https://api.github.com/repos/michelole/n2c2/deployments","created_at":"2018-03-14T11:00:23Z","updated_at":"2018-04-17T13:45:00Z","pushed_at":"2018-04-18T17:39:42Z","git_url":"git://github.com/michelole/n2c2.git","ssh_url":"git@github.com:michelole/n2c2.git","clone_url":"https://github.com/michelole/n2c2.git","svn_url":"https://github.com/michelole/n2c2","homepage":null,"size":6538,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bst-mug:master","ref":"master","sha":"449ef89ea1f7ca1f7af18906bf1dbcfacee7eadf","user":{"login":"bst-mug","id":27217493,"avatar_url":"https://avatars0.githubusercontent.com/u/27217493?v=4","gravatar_id":"","url":"https://api.github.com/users/bst-mug","html_url":"https://github.com/bst-mug","followers_url":"https://api.github.com/users/bst-mug/followers","following_url":"https://api.github.com/users/bst-mug/following{/other_user}","gists_url":"https://api.github.com/users/bst-mug/gists{/gist_id}","starred_url":"https://api.github.com/users/bst-mug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bst-mug/subscriptions","organizations_url":"https://api.github.com/users/bst-mug/orgs","repos_url":"https://api.github.com/users/bst-mug/repos","events_url":"https://api.github.com/users/bst-mug/events{/privacy}","received_events_url":"https://api.github.com/users/bst-mug/received_events","type":"Organization","site_admin":false},"repo":{"id":125067504,"name":"n2c2","full_name":"bst-mug/n2c2","owner":{"login":"bst-mug","id":27217493,"avatar_url":"https://avatars0.githubusercontent.com/u/27217493?v=4","gravatar_id":"","url":"https://api.github.com/users/bst-mug","html_url":"https://github.com/bst-mug","followers_url":"https://api.github.com/users/bst-mug/followers","following_url":"https://api.github.com/users/bst-mug/following{/other_user}","gists_url":"https://api.github.com/users/bst-mug/gists{/gist_id}","starred_url":"https://api.github.com/users/bst-mug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bst-mug/subscriptions","organizations_url":"https://api.github.com/users/bst-mug/orgs","repos_url":"https://api.github.com/users/bst-mug/repos","events_url":"https://api.github.com/users/bst-mug/events{/privacy}","received_events_url":"https://api.github.com/users/bst-mug/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bst-mug/n2c2","description":"Supporting code for participation at the 2018 n2c2 Shared-Task","fork":false,"url":"https://api.github.com/repos/bst-mug/n2c2","forks_url":"https://api.github.com/repos/bst-mug/n2c2/forks","keys_url":"https://api.github.com/repos/bst-mug/n2c2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bst-mug/n2c2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bst-mug/n2c2/teams","hooks_url":"https://api.github.com/repos/bst-mug/n2c2/hooks","issue_events_url":"https://api.github.com/repos/bst-mug/n2c2/issues/events{/number}","events_url":"https://api.github.com/repos/bst-mug/n2c2/events","assignees_url":"https://api.github.com/repos/bst-mug/n2c2/assignees{/user}","branches_url":"https://api.github.com/repos/bst-mug/n2c2/branches{/branch}","tags_url":"https://api.github.com/repos/bst-mug/n2c2/tags","blobs_url":"https://api.github.com/repos/bst-mug/n2c2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bst-mug/n2c2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bst-mug/n2c2/git/refs{/sha}","trees_url":"https://api.github.com/repos/bst-mug/n2c2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bst-mug/n2c2/statuses/{sha}","languages_url":"https://api.github.com/repos/bst-mug/n2c2/languages","stargazers_url":"https://api.github.com/repos/bst-mug/n2c2/stargazers","contributors_url":"https://api.github.com/repos/bst-mug/n2c2/contributors","subscribers_url":"https://api.github.com/repos/bst-mug/n2c2/subscribers","subscription_url":"https://api.github.com/repos/bst-mug/n2c2/subscription","commits_url":"https://api.github.com/repos/bst-mug/n2c2/commits{/sha}","git_commits_url":"https://api.github.com/repos/bst-mug/n2c2/git/commits{/sha}","comments_url":"https://api.github.com/repos/bst-mug/n2c2/comments{/number}","issue_comment_url":"https://api.github.com/repos/bst-mug/n2c2/issues/comments{/number}","contents_url":"https://api.github.com/repos/bst-mug/n2c2/contents/{+path}","compare_url":"https://api.github.com/repos/bst-mug/n2c2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bst-mug/n2c2/merges","archive_url":"https://api.github.com/repos/bst-mug/n2c2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bst-mug/n2c2/downloads","issues_url":"https://api.github.com/repos/bst-mug/n2c2/issues{/number}","pulls_url":"https://api.github.com/repos/bst-mug/n2c2/pulls{/number}","milestones_url":"https://api.github.com/repos/bst-mug/n2c2/milestones{/number}","notifications_url":"https://api.github.com/repos/bst-mug/n2c2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bst-mug/n2c2/labels{/name}","releases_url":"https://api.github.com/repos/bst-mug/n2c2/releases{/id}","deployments_url":"https://api.github.com/repos/bst-mug/n2c2/deployments","created_at":"2018-03-13T14:49:23Z","updated_at":"2018-04-17T16:02:58Z","pushed_at":"2018-04-18T17:39:57Z","git_url":"git://github.com/bst-mug/n2c2.git","ssh_url":"git@github.com:bst-mug/n2c2.git","clone_url":"https://github.com/bst-mug/n2c2.git","svn_url":"https://github.com/bst-mug/n2c2","homepage":null,"size":6553,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":20,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":2,"open_issues":20,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bst-mug/n2c2/pulls/50"},"html":{"href":"https://github.com/bst-mug/n2c2/pull/50"},"issue":{"href":"https://api.github.com/repos/bst-mug/n2c2/issues/50"},"comments":{"href":"https://api.github.com/repos/bst-mug/n2c2/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/bst-mug/n2c2/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/bst-mug/n2c2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bst-mug/n2c2/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/bst-mug/n2c2/statuses/df36c13b180296d79e729269224413860c82eaed"}},"author_association":"OWNER"}}
{"actor":{"display_login":"codacy-bot"}}