I am not sure the snippet you provided is matching the expected architecture displayed in the image since you have multiple outputs in your snippet but there is only 1 output with 3 units in the image displayed or maybe I am missing something.
My answer will be used to define the architecture displayed on the image.
You have several ways to do it, the first question is: do the weights of the Weighted Input layer are trainable or constant?
- If the weights are constant, you have 2 solutions:
1.1. Define a constant tensor with the weights and use it to multiply the input features:
import tensorflow as tf
n_features = 4
weights = tf.constant([1.1, 1.2, 1.3, 1.4])
input_ = tf.keras.layers.Input(shape=(n_features,))
input_weighted = tf.multiply(input_, weights)
dense_1 = tf.keras.layers.Dense(units=5, activation="relu")(input_weighted)
dense_2 = tf.keras.layers.Dense(units=4, activation="relu")(dense_1)
output = tf.keras.layers.Dense(units=3, activation="softmax")(dense_2)
model = tf.keras.Model(inputs=input_, outputs=output)
tf.keras.utils.plot_model(model, show_shapes=True)
This give you the following model:

1.2. Use an input layer to provide the weights
import tensorflow as tf
n_features = 4
input_ = tf.keras.layers.Input(shape=(n_features,))
weights = tf.keras.layers.Input(shape=(n_features,))
input_weighted = tf.keras.layers.Multiply(name="weighted_input")([input_, weights])
dense_1 = tf.keras.layers.Dense(units=5, activation="relu")(input_weighted)
dense_2 = tf.keras.layers.Dense(units=4, activation="relu")(dense_1)
output = tf.keras.layers.Dense(units=3, activation="softmax")(dense_2)
model = tf.keras.Model(inputs=[input_, weights], outputs=output)
tf.keras.utils.plot_model(model, show_shapes=True)
This gives you the following model:

- If the weights are trainable, you can create a custom layer and use it in your model
import tensorflow as tf
class WeightedLayer(tf.keras.layers.Layer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def build(self, input_shape):
self.kernel = self.add_weight("kernel", shape=(int(input_shape[-1]),))
def call(self, inputs):
return tf.multiply(inputs, self.kernel)
n_features = 4
input_ = tf.keras.layers.Input(shape=(n_features,))
input_weighted = WeightedLayer(name="weighted_input")(input_)
dense_1 = tf.keras.layers.Dense(units=5, activation="relu")(input_weighted)
dense_2 = tf.keras.layers.Dense(units=4, activation="relu")(dense_1)
output = tf.keras.layers.Dense(units=3, activation="softmax")(dense_2)
model = tf.keras.Model(inputs=input_, outputs=output)
tf.keras.utils.plot_model(model, show_shapes=True)
This gives you the following model:

By printing the model summary each time you can see that for the 2 first models you have 64 trainable parameters and for the last model you have 68 trainable parameters which corresponds to the 64 from the first two models + 4 weights added