From 6a123529a0d36f3456e6003449da6e9cbc241154 Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Wed, 3 Apr 2019 22:54:23 -0400 Subject: [PATCH 1/5] create `keras.Sequential.LSTMBinaryTextClassifier` primitive --- ...s.Sequential.LSTMBinaryTextClassifier.json | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json diff --git a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json new file mode 100644 index 00000000..5f3042f8 --- /dev/null +++ b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json @@ -0,0 +1,133 @@ +{ + "name": "keras.Sequential.LSTMBinaryTextClassifier", + "contributors": [ + "Hector Dominguez " + ], + "description": "Long Short-Term Memory (LSTM) Binary Classifier for texts", + "classifiers": { + "type": "estimator", + "subtype": "classifier" + }, + "modalities": [], + "primitive": "mlprimitives.adapters.keras.Sequential", + "fit": { + "method": "fit", + "args": [ + { + "name": "X", + "type": "ndarray" + }, + { + "name": "y", + "type": "array" + }, + { + "name": "vocabulary_size", + "type": "int", + "description": "vocabulary size + 1: number of known words in input." + } + ] + }, + "produce": { + "method": "predict", + "args": [ + { + "name": "X", + "type": "ndarray" + } + ], + "output": [ + { + "name": "y", + "type": "array" + } + ] + }, + "hyperparameters": { + "fixed": { + "classification": { + "type": "bool", + "default": true + }, + "loss": { + "type": "str", + "default": "keras.losses.binary_crossentropy" + }, + "optimizer": { + "type": "str", + "default": "keras.optimizers.RMSprop" + }, + "metrics": { + "type": "list", + "default": [ + "accuracy" + ] + }, + "epochs": { + "type": "int", + "default": 20 + }, + "layers": { + "type": "list", + "default": [ + { + "class": "keras.layers.Embedding", + "parameters": { + "input_dim": "vocabulary_size", + "output_dim": "embedding_output_dim" + } + }, + { + "class": "keras.layers.LSTM", + "parameters": { + "units": "lstm_units" + } + }, + { + "class": "keras.layers.Dropout", + "parameters": { + "rate": "dropout_rate" + } + }, + { + "class": "keras.layers.Dense", + "parameters": { + "units": 1, + "activation": "sigmoid" + } + } + ] + } + }, + "tunable": { + "embedding_output_dim": { + "type": "int", + "default": 100, + "range": [ + 100, + 500 + ] + }, + "lstm_units": { + "type": "int", + "default": 100, + "range": [ + 100, + 500 + ] + }, + "dropout_rate": { + "type": "float", + "default": 0.5, + "range": [ + 0.0, + 0.75 + ] + }, + "batch_size": { + "type": "int", + "default": 128 + } + } + } +} From 082aa7cb8ffac585005b0388ecbc4a18c43b905f Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Thu, 4 Apr 2019 15:12:00 -0400 Subject: [PATCH 2/5] pipeline for `keras.Sequential.LSTMBinaryTextClassifier` primitive --- ...s.Sequential.LSTMBinaryTextClassifier.json | 2 +- ...s.Sequential.LSTMBinaryTextClassifier.json | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 pipelines/keras.Sequential.LSTMBinaryTextClassifier.json diff --git a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json index 5f3042f8..5d015205 100644 --- a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json @@ -92,7 +92,7 @@ { "class": "keras.layers.Dense", "parameters": { - "units": 1, + "units": 2, "activation": "sigmoid" } } diff --git a/pipelines/keras.Sequential.LSTMBinaryTextClassifier.json b/pipelines/keras.Sequential.LSTMBinaryTextClassifier.json new file mode 100644 index 00000000..db8fddb2 --- /dev/null +++ b/pipelines/keras.Sequential.LSTMBinaryTextClassifier.json @@ -0,0 +1,28 @@ +{ + "metadata": { + "name": "keras.Sequential.LSTMBinaryTextClassifier", + "data_type": "text", + "task_type": "classification" + }, + "validation": { + "dataset": "personae" + }, + "primitives": [ + "mlprimitives.custom.counters.VocabularyCounter", + "mlprimitives.custom.feature_extraction.StringVectorizer", + "keras.Sequential.LSTMBinaryTextClassifier" + ], + "output_names": { + "mlprimitives.custom.counters.VocabularyCounter#1": { + "counts": "vocabulary_size" + } + }, + "init_params": { + "mlprimitives.custom.counters.VocabularyCounter#1": { + "add": 1 + }, + "keras.Sequential.LSTMBinaryTextClassifier#1": { + "epochs": 1 + } + } +} From 928cfabd41bfc600038685c2e6eeee14aa9c1bc9 Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 15 Apr 2019 08:51:38 -0400 Subject: [PATCH 3/5] remove `batch_size` tunable hyperparameter --- .../jsons/keras.Sequential.LSTMBinaryTextClassifier.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json index 5d015205..39c3e63d 100644 --- a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json @@ -123,10 +123,6 @@ 0.0, 0.75 ] - }, - "batch_size": { - "type": "int", - "default": 128 } } } From 1b2b7f474e6dfb064f0466d61f255b7e144c5c2e Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 15 Apr 2019 08:55:04 -0400 Subject: [PATCH 4/5] add a fixed `verbose` hyperparameter --- .../jsons/keras.Sequential.LSTMBinaryTextClassifier.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json index 39c3e63d..48a4a2cb 100644 --- a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json @@ -67,6 +67,14 @@ "type": "int", "default": 20 }, + "verbose": { + "type": "int", + "default": 1, + "range": [ + 0, + 2 + ] + }, "layers": { "type": "list", "default": [ From 6a366fa924749c81e6e4e9aa1862d1a263eedbde Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 15 Apr 2019 09:30:45 -0400 Subject: [PATCH 5/5] default `verbose` to 0 --- .../jsons/keras.Sequential.LSTMBinaryTextClassifier.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json index 48a4a2cb..6e82af8a 100644 --- a/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.LSTMBinaryTextClassifier.json @@ -69,7 +69,7 @@ }, "verbose": { "type": "int", - "default": 1, + "default": 0, "range": [ 0, 2