- #1
user366312
Gold Member
- 89
- 3
- TL;DR Summary
- I have 3 classes (A, B, and C). I have 6 features.
These features represent a 5-character string pattern comprising of 3-classes(e.g. AABBC, etc.). So, that means, features are not directly dependent on classes.
Hence, I am confused about the solution.
I have 3 classes (A, B, and C).
I have 6 features:
These features represent a 5-character string pattern comprising of 3-classes(e.g. AABBC, etc.).
Let, a 5-character string pattern is one-hot encoded as follows:
So, I think this is a Multi-task learning problem.
In the above source code, I am passing a 5-character string pattern as a 15-digit one-hot-encoded to be used as classes.
And, this is the dilemma for me.
Naturally, this is not working:
How can I properly design my neural network?
I have 6 features:
features:
train_x = [[ 6.442 6.338 7.027 8.789 10.009 12.566]
[ 6.338 7.027 5.338 10.009 8.122 11.217]
[ 7.027 5.338 5.335 8.122 5.537 6.408]
[ 5.338 5.335 5.659 5.537 5.241 7.043]]
These features represent a 5-character string pattern comprising of 3-classes(e.g. AABBC, etc.).
Let, a 5-character string pattern is one-hot encoded as follows:
one_hot_encoding:
train_z = [[0. 0. 1. 0. 0. 1. 0. 0. 1. 0. 0. 1. 1. 0. 0.]
[0. 0. 1. 0. 0. 1. 0. 0. 1. 1. 0. 0. 1. 0. 0.]
[0. 0. 1. 0. 0. 1. 1. 0. 0. 1. 0. 0. 1. 0. 0.]
[0. 0. 1. 1. 0. 0. 1. 0. 0. 1. 0. 0. 0. 0. 1.]]
So, I think this is a Multi-task learning problem.
source_code:
# there would be 6 inputs for 6 features
inputs_tensor = keras.Input(shape=(FEATURES_COUNT,))
# there would be 2 hidden layers
hidden_layer_1 = keras.layers.Dense(LAYER_1_NEURON_COUNT, activation="relu")
hidden_layer_2 = keras.layers.Dense(LAYER_2_NEURON_COUNT, activation="relu")
# there would be 5 outputs for 5-characters
# each o/p layer will have 3 neurons for 3 classes
output_layer_1 = keras.layers.Dense(CLASSES_COUNT, activation='softmax') # 3 neuraons for 3 classes
output_layer_2 = keras.layers.Dense(CLASSES_COUNT, activation='softmax') # -do-
output_layer_3 = keras.layers.Dense(CLASSES_COUNT, activation='softmax') # -do-
output_layer_4 = keras.layers.Dense(CLASSES_COUNT, activation='softmax') # -do-
output_layer_5 = keras.layers.Dense(CLASSES_COUNT, activation='softmax') # -do-
output_layer_6 = keras.layers.Dense(CLASSES_COUNT, activation='softmax') # -do-
# assembling the layers.
x = hidden_layer_1(inputs_tensor)
x = hidden_layer_2(x)
# configuring the output
output1 = output_layer_1(x)
output2 = output_layer_2(x)
output3 = output_layer_3(x)
output4 = output_layer_4(x)
output5 = output_layer_5(x)
model = keras.Model(inputs=[inputs_tensor],
outputs=[output1, output2, output3, output4, output5],
name="functional_model")
# model.summary()
opt_function = keras.optimizers.SGD(lr=0.01, decay=1e-1, momentum=0.9, nesterov=True)
model.compile(loss='categorical_crossentropy',
optimizer=opt_function,
metrics=['accuracy'])
model.fit(
tx, tz,
epochs=EPOCHS,
batch_size=BATCH_SIZE
)
In the above source code, I am passing a 5-character string pattern as a 15-digit one-hot-encoded to be used as classes.
And, this is the dilemma for me.
Naturally, this is not working:
error:
C:\ProgramData\Miniconda3\envs\by_nn\python.exe C:/Users/pc/source/repos/OneHotEncodingLayer__test/by_nn_k____5_outputs.py
using 2 points for training and 3 for validation
Traceback (most recent call last):
File "C:/Users/pc/source/repos/OneHotEncodingLayer__test/by_nn_k____5_outputs.py", line 63, in <module>
tz = tf.concat([tf.constant(d, shape=(1, CLASSES_COUNT), dtype=np.float32) for d in train_z], 0)
File "C:/Users/pc/source/repos/OneHotEncodingLayer__test/by_nn_k____5_outputs.py", line 63, in <listcomp>
tz = tf.concat([tf.constant(d, shape=(1, CLASSES_COUNT), dtype=np.float32) for d in train_z], 0)
File "C:\ProgramData\Miniconda3\envs\by_nn\lib\site-packages\tensorflow\python\framework\constant_op.py", line 263, in constant
return _constant_impl(value, dtype, shape, name, verify_shape=False,
File "C:\ProgramData\Miniconda3\envs\by_nn\lib\site-packages\tensorflow\python\framework\constant_op.py", line 275, in _constant_impl
return _constant_eager_impl(ctx, value, dtype, shape, verify_shape)
File "C:\ProgramData\Miniconda3\envs\by_nn\lib\site-packages\tensorflow\python\framework\constant_op.py", line 322, in _constant_eager_impl
raise TypeError("Eager execution of tf.constant with unsupported shape "
TypeError: Eager execution of tf.constant with unsupported shape (value has 15 elements, shape is (1, 3) with 3 elements).
Process finished with exit code 1
How can I properly design my neural network?