From c2882a3966d25e268aea5f6685f410ba584332dd Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 25 Mar 2019 16:12:19 -0400 Subject: [PATCH 01/10] create `keras.Sequential.MLPSoftmaxClassifier` primitive --- ...keras.Sequential.MLPSoftmaxClassifier.json | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json diff --git a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json new file mode 100644 index 00000000..3fdfd274 --- /dev/null +++ b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json @@ -0,0 +1,133 @@ +{ + "name": "keras.Sequential.MLPSoftmaxClassifier", + "contributors": [ + "Hector Dominguez " + ], + "description": "Multilayer Perceptron (MLP) for multi-class softmax classification", + "classifiers": { + "type": "estimator", + "subtype": "classifier" + }, + "modalities": [], + "primitive": "mlprimitives.adapters.keras.MLPSoftmaxClassifier", + "fit": { + "method": "fit", + "args": [ + { + "name": "X", + "type": "ndarray" + }, + { + "name": "y", + "type": "array" + }, + { + "name": "classes", + "type": "int", + "description": "Number of classes" + } + ] + }, + "produce": { + "method": "predict", + "args": [ + { + "name": "X", + "type": "ndarray" + } + ], + "output": [ + { + "name": "y", + "type": "array" + } + ] + }, + "hyperparameters": { + "fixed": { + "classification": { + "type": "bool", + "default": true + }, + "epochs": { + "type": "int", + "default": 20 + }, + "input_dim": { + "type": "int", + "default": 20 + }, + "conv_activation": { + "type": "str", + "default": "relu" + }, + "dense_activation": { + "type": "str", + "default": "softmax" + }, + "loss": { + "type": "str", + "default": "keras.losses.categorical_crossentropy" + }, + "optimizer": { + "type": "str", + "default": "keras.optimizers.SGD" + }, + "metrics": { + "type": "list", + "default": [ + "accuracy" + ] + }, + "layers": { + "type": "list", + "default": [ + { + "class": "keras.layers.Dense", + "parameters": { + "units": "classes", + "activation": "conv_activation", + "input_dim": "input_dim" + } + }, + { + "class": "keras.layers.Dropout", + "parameters": { + "rate": "dropout_rate" + } + }, + { + "class": "keras.layers.Dense", + "parameters": { + "units": "classes", + "activation": "conv_activation" + } + }, + { + "class": "keras.layers.Dropout", + "parameters": { + "rate": "dropout_rate" + } + }, + { + "class": "keras.layers.Dense", + "parameters": { + "units": "classes", + "activation": "dense_activation" + } + } + ] + } + }, + "tunable": { + "dropout_rate": { + "type": "float", + "default": 0.5, + "range": [ + 0.0, + 0.75 + ] + } + } + } +} From 49d1e164c9d3da05c4dffa56273720bffef5f275 Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 25 Mar 2019 17:28:05 -0400 Subject: [PATCH 02/10] fix typo --- mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json index 3fdfd274..9995b1cf 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json @@ -9,7 +9,7 @@ "subtype": "classifier" }, "modalities": [], - "primitive": "mlprimitives.adapters.keras.MLPSoftmaxClassifier", + "primitive": "mlprimitives.adapters.keras.Sequential", "fit": { "method": "fit", "args": [ From ab69f0bc250425497a431ee8ecabe09839d03f1a Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 25 Mar 2019 17:28:25 -0400 Subject: [PATCH 03/10] add pipeline for `keras.Sequential.MLPSoftmaxClassifier` primitive --- ...keras.Sequential.MLPSoftmaxClassifier.json | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pipelines/keras.Sequential.MLPSoftmaxClassifier.json diff --git a/pipelines/keras.Sequential.MLPSoftmaxClassifier.json b/pipelines/keras.Sequential.MLPSoftmaxClassifier.json new file mode 100644 index 00000000..b02c17d0 --- /dev/null +++ b/pipelines/keras.Sequential.MLPSoftmaxClassifier.json @@ -0,0 +1,22 @@ +{ + "metadata": { + "name": "keras.Sequential.MLPSoftmaxClassifier", + "data_type": "single_table", + "task_type": "classification" + }, + "validation": { + "dataset": "iris", + "context": { + "classes": 3 + } + }, + "primitives": [ + "keras.Sequential.MLPSoftmaxClassifier" + ], + "init_params": { + "keras.Sequential.MLPSoftmaxClassifier#1": { + "epochs": 1, + "input_dim": 4 + } + } +} From 4945a06138894036a67ae7f6d4a27b7587a5fb0b Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Tue, 26 Mar 2019 09:24:32 -0400 Subject: [PATCH 04/10] add `dense_units` and `batch_size` params --- .../jsons/keras.Sequential.MLPSoftmaxClassifier.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json index 9995b1cf..d750a851 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json @@ -61,6 +61,10 @@ "type": "str", "default": "relu" }, + "dense_units": { + "type": "int", + "default": 64 + }, "dense_activation": { "type": "str", "default": "softmax" @@ -85,7 +89,7 @@ { "class": "keras.layers.Dense", "parameters": { - "units": "classes", + "units": "dense_units", "activation": "conv_activation", "input_dim": "input_dim" } @@ -99,7 +103,7 @@ { "class": "keras.layers.Dense", "parameters": { - "units": "classes", + "units": "dense_units", "activation": "conv_activation" } }, @@ -127,6 +131,10 @@ 0.0, 0.75 ] + }, + "batch_size": { + "type": "int", + "default": 128 } } } From 4592017d9f51a411bf9ec3c0deeb224524d74b01 Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Tue, 26 Mar 2019 16:58:36 -0400 Subject: [PATCH 05/10] use `UniqueCounter` and fix param names --- ...keras.Sequential.MLPSoftmaxClassifier.json | 26 +++++++++---------- ...keras.Sequential.MLPSoftmaxClassifier.json | 15 ++++++++--- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json index d750a851..1b49c0c1 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json @@ -49,23 +49,19 @@ "type": "bool", "default": true }, - "epochs": { - "type": "int", - "default": 20 - }, - "input_dim": { + "dense_units": { "type": "int", - "default": 20 + "default": 64 }, - "conv_activation": { + "dense_activation": { "type": "str", "default": "relu" }, - "dense_units": { + "input_dim": { "type": "int", - "default": 64 + "default": 20 }, - "dense_activation": { + "last_dense_activation": { "type": "str", "default": "softmax" }, @@ -83,6 +79,10 @@ "accuracy" ] }, + "epochs": { + "type": "int", + "default": 20 + }, "layers": { "type": "list", "default": [ @@ -90,7 +90,7 @@ "class": "keras.layers.Dense", "parameters": { "units": "dense_units", - "activation": "conv_activation", + "activation": "dense_activation", "input_dim": "input_dim" } }, @@ -104,7 +104,7 @@ "class": "keras.layers.Dense", "parameters": { "units": "dense_units", - "activation": "conv_activation" + "activation": "dense_activation" } }, { @@ -117,7 +117,7 @@ "class": "keras.layers.Dense", "parameters": { "units": "classes", - "activation": "dense_activation" + "activation": "last_dense_activation" } } ] diff --git a/pipelines/keras.Sequential.MLPSoftmaxClassifier.json b/pipelines/keras.Sequential.MLPSoftmaxClassifier.json index b02c17d0..1500ee11 100644 --- a/pipelines/keras.Sequential.MLPSoftmaxClassifier.json +++ b/pipelines/keras.Sequential.MLPSoftmaxClassifier.json @@ -6,13 +6,22 @@ }, "validation": { "dataset": "iris", - "context": { - "classes": 3 - } + "context": {} }, "primitives": [ + "mlprimitives.custom.counters.UniqueCounter", "keras.Sequential.MLPSoftmaxClassifier" ], + "input_names": { + "mlprimitives.custom.counters.UniqueCounter#1": { + "X": "y" + } + }, + "output_names": { + "mlprimitives.custom.counters.UniqueCounter#1": { + "counts": "classes" + } + }, "init_params": { "keras.Sequential.MLPSoftmaxClassifier#1": { "epochs": 1, From bfb80e732eb4ddb218bfea636cbadf7441ccdb5d Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Fri, 29 Mar 2019 12:50:56 -0400 Subject: [PATCH 06/10] renaming primitive: MLPSoftmaxClassifier --> MLPMultiClassClassifier --- ...r.json => keras.Sequential.MLPMultiClassClassifier.json} | 2 +- ...r.json => keras.Sequential.MLPMultiClassClassifier.json} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename mlprimitives/jsons/{keras.Sequential.MLPSoftmaxClassifier.json => keras.Sequential.MLPMultiClassClassifier.json} (98%) rename pipelines/{keras.Sequential.MLPSoftmaxClassifier.json => keras.Sequential.MLPMultiClassClassifier.json} (78%) diff --git a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json similarity index 98% rename from mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json rename to mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json index 1b49c0c1..d8b88e81 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPSoftmaxClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json @@ -1,5 +1,5 @@ { - "name": "keras.Sequential.MLPSoftmaxClassifier", + "name": "keras.Sequential.MLPMultiClassClassifier", "contributors": [ "Hector Dominguez " ], diff --git a/pipelines/keras.Sequential.MLPSoftmaxClassifier.json b/pipelines/keras.Sequential.MLPMultiClassClassifier.json similarity index 78% rename from pipelines/keras.Sequential.MLPSoftmaxClassifier.json rename to pipelines/keras.Sequential.MLPMultiClassClassifier.json index 1500ee11..cb0e2dd1 100644 --- a/pipelines/keras.Sequential.MLPSoftmaxClassifier.json +++ b/pipelines/keras.Sequential.MLPMultiClassClassifier.json @@ -1,6 +1,6 @@ { "metadata": { - "name": "keras.Sequential.MLPSoftmaxClassifier", + "name": "keras.Sequential.MLPMultiClassClassifier", "data_type": "single_table", "task_type": "classification" }, @@ -10,7 +10,7 @@ }, "primitives": [ "mlprimitives.custom.counters.UniqueCounter", - "keras.Sequential.MLPSoftmaxClassifier" + "keras.Sequential.MLPMultiClassClassifier" ], "input_names": { "mlprimitives.custom.counters.UniqueCounter#1": { @@ -23,7 +23,7 @@ } }, "init_params": { - "keras.Sequential.MLPSoftmaxClassifier#1": { + "keras.Sequential.MLPMultiClassClassifier#1": { "epochs": 1, "input_dim": 4 } From 9f8a365ead1fb6251f9baf1115167f971687e52f Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Fri, 29 Mar 2019 12:54:42 -0400 Subject: [PATCH 07/10] fix architecture: relu --> relu --> softmax --- .../keras.Sequential.MLPMultiClassClassifier.json | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json index d8b88e81..0f6d5012 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json @@ -53,18 +53,10 @@ "type": "int", "default": 64 }, - "dense_activation": { - "type": "str", - "default": "relu" - }, "input_dim": { "type": "int", "default": 20 }, - "last_dense_activation": { - "type": "str", - "default": "softmax" - }, "loss": { "type": "str", "default": "keras.losses.categorical_crossentropy" @@ -90,7 +82,7 @@ "class": "keras.layers.Dense", "parameters": { "units": "dense_units", - "activation": "dense_activation", + "activation": "relu", "input_dim": "input_dim" } }, @@ -104,7 +96,7 @@ "class": "keras.layers.Dense", "parameters": { "units": "dense_units", - "activation": "dense_activation" + "activation": "relu" } }, { @@ -117,7 +109,7 @@ "class": "keras.layers.Dense", "parameters": { "units": "classes", - "activation": "last_dense_activation" + "activation": "softmax" } } ] From 908d42a71a138b63c87ad302026d456b98ad5b25 Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 1 Apr 2019 08:30:15 -0400 Subject: [PATCH 08/10] use independent dense units and dropout rates for each layer --- ...as.Sequential.MLPMultiClassClassifier.json | 41 ++++++++++++------- ...as.Sequential.MLPMultiClassClassifier.json | 10 ++--- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json index 0f6d5012..1a9a60e7 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json @@ -25,6 +25,11 @@ "name": "classes", "type": "int", "description": "Number of classes" + }, + { + "name": "features", + "type": "int", + "description": "Number of features in X" } ] }, @@ -49,14 +54,6 @@ "type": "bool", "default": true }, - "dense_units": { - "type": "int", - "default": 64 - }, - "input_dim": { - "type": "int", - "default": 20 - }, "loss": { "type": "str", "default": "keras.losses.categorical_crossentropy" @@ -81,28 +78,28 @@ { "class": "keras.layers.Dense", "parameters": { - "units": "dense_units", + "units": "dense_1_units", "activation": "relu", - "input_dim": "input_dim" + "input_dim": "features" } }, { "class": "keras.layers.Dropout", "parameters": { - "rate": "dropout_rate" + "rate": "dropout_1_rate" } }, { "class": "keras.layers.Dense", "parameters": { - "units": "dense_units", + "units": "dense_2_units", "activation": "relu" } }, { "class": "keras.layers.Dropout", "parameters": { - "rate": "dropout_rate" + "rate": "dropout_2_rate" } }, { @@ -116,7 +113,23 @@ } }, "tunable": { - "dropout_rate": { + "dense_1_units": { + "type": "int", + "default": 64 + }, + "dense_2_units": { + "type": "int", + "default": 64 + }, + "dropout_1_rate": { + "type": "float", + "default": 0.5, + "range": [ + 0.0, + 0.75 + ] + }, + "dropout_2_rate": { "type": "float", "default": 0.5, "range": [ diff --git a/pipelines/keras.Sequential.MLPMultiClassClassifier.json b/pipelines/keras.Sequential.MLPMultiClassClassifier.json index cb0e2dd1..dbc9d4e2 100644 --- a/pipelines/keras.Sequential.MLPMultiClassClassifier.json +++ b/pipelines/keras.Sequential.MLPMultiClassClassifier.json @@ -6,7 +6,9 @@ }, "validation": { "dataset": "iris", - "context": {} + "context": { + "features": 4 + } }, "primitives": [ "mlprimitives.custom.counters.UniqueCounter", @@ -21,11 +23,5 @@ "mlprimitives.custom.counters.UniqueCounter#1": { "counts": "classes" } - }, - "init_params": { - "keras.Sequential.MLPMultiClassClassifier#1": { - "epochs": 1, - "input_dim": 4 - } } } From 6b269569ce4c27acc49938fe3b380ddf3db47a18 Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 1 Apr 2019 08:34:20 -0400 Subject: [PATCH 09/10] define a range for dense units --- .../keras.Sequential.MLPMultiClassClassifier.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json index 1a9a60e7..87d22190 100644 --- a/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json +++ b/mlprimitives/jsons/keras.Sequential.MLPMultiClassClassifier.json @@ -115,11 +115,19 @@ "tunable": { "dense_1_units": { "type": "int", - "default": 64 + "default": 64, + "range": [ + 1, + 500 + ] }, "dense_2_units": { "type": "int", - "default": 64 + "default": 64, + "range": [ + 1, + 500 + ] }, "dropout_1_rate": { "type": "float", From 5d79c0292627080171287de332c2e7c1d6112d1e Mon Sep 17 00:00:00 2001 From: Hector Dominguez Date: Mon, 1 Apr 2019 08:47:55 -0400 Subject: [PATCH 10/10] use `mlprimitives.custom.counters.count_features` to get `features` --- pipelines/keras.Sequential.MLPMultiClassClassifier.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pipelines/keras.Sequential.MLPMultiClassClassifier.json b/pipelines/keras.Sequential.MLPMultiClassClassifier.json index dbc9d4e2..f124a2f7 100644 --- a/pipelines/keras.Sequential.MLPMultiClassClassifier.json +++ b/pipelines/keras.Sequential.MLPMultiClassClassifier.json @@ -6,12 +6,11 @@ }, "validation": { "dataset": "iris", - "context": { - "features": 4 - } + "context": {} }, "primitives": [ "mlprimitives.custom.counters.UniqueCounter", + "mlprimitives.custom.counters.count_features", "keras.Sequential.MLPMultiClassClassifier" ], "input_names": {