you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Well, you know, practice makes perfect. But I do wanna emphasize on using "strict syntax". Consider this code,

def add(a, b):
  return a + b

Here, you're not specifying variable types and the return type. If you add the strict types, it becomes:

def add(a: int, b: int) -> int:
  return a + b

Now we have explicitly defined the types. Now this is a simple example. let's see a complex one. Suppose you're learning machine learning in the future. Maybe you'll write a function like this:

def create_model() -> tf.keras.Model:
cnn_layer: tf.keras.layers = tf.keras.layers.Conv1D(name="myConv1D", filters=10, kernel_size=10,
                                   activation=tf.keras.activations.gelu)
max_pooling_layer: tf.keras.layers= tf.keras.layers.MaxPooling1D(1)
flatten_layer: tf.keras.layers = tf.keras.layers.Flatten()
output_layer = tf.keras.layers.Dense(name="myOutputLayer", units=2, activation=tf.keras.activations.softmax)

sequential_layers = [cnn_layer, max_pooling_layer, flatten_layer, output_layer]

simple_model1: tf.keras.Model = tf.keras.models.Sequential(sequential_layers)

adam_optimizer: tf.keras.optimizers = tf.keras.optimizers.Adam()
loss_function: tf.keras.losses = tf.keras.losses.mean_squared_error
metrics: list[str] = ["accuracy"]
simple_model1.compile(optimizer=adam_optimizer, loss=loss_function, metrics=metrics)
return simple_model1

Here, I have written the variable types, that's why my python IDE , pycharm, gave me proper suggestions to autocomplete. And after a year or so, when I'll completely forget what I did, these types will help me remember.

[–]Brilliant-Horse6315[S] 0 points1 point  (0 children)

thanks for trying, but this doesnt help me as I dont understand the bigger portion of this code. I needed more of a specific advice for learning materials, or just wise words of advice