rohan843 / dnncase

GNU General Public License v3.0
1 stars 0 forks source link

Layer nodes' output handles enabled or disabled? #48

Open rohan843 opened 1 year ago

rohan843 commented 1 year ago

Some Keras layers like LSTM have different number of outputs depending on the state of their hyperparameters. To account for this, layers in our system need to be analysed.

Representative code

lstm = tf.keras.layers.LSTM(4, return_sequences=True, return_state=True)
whole_seq_output, final_memory_state, final_carry_state = lstm(inputs)

# vs

lstm = tf.keras.layers.LSTM(4)
output = lstm(inputs)

Here, we clearly see different number of outputs based on the layer's hyperparameters return_sequences and return_state.

This can be accounted for by creating a specification file (or a configuration file) for each layer. That will specify any and every hyperparameters of the layer, their metadata like datatype and docs, as well as all inputs and outputs of the layer.

Now, some inputs' or outputs' validity may depend on the hyperparameters themselves (as seen in the above example). So, to account for this, each input/output will have a boolean valued function or a boolean value defined for it, against the property name of enabled. If a function is specified, it will be passed the entire hyperparameter object, so that it can use whatever hyperparameter(s) it needs to decide whether to return True or False. (Considering this may be specified by a user, we can keep the function input in python instead of JS.)

As an example, see the below (limited) config file for an LSTM:

{
    "name": "LSTM",
    "docstring-file": "docs/keras/lstm_doc.md",
    "hyperparameters": {
        "h1": "{... any relevant data ...}"
    },
    "inputs": [
        "{... data for input1 ...}",
        "{... data for input2 ...}",
        "... and so on"
    ]
    "outputs": [
        {
            "id": "final_carry_state",
            "enabled-function": "a python function that gets hyperparameters as input as a dict() and returns True iff the \"return_state\" hyperparameter is set to True."
        },
        "{... data for output2 ...}",
        "... and so on"
    ]
}