# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# https://www.tensorflow.org/versions/r2.0/api_docs/python/tf
#
# https://keras.io/

# +
import tensorflow as tf

from tensorflow import keras
import numpy as np
from tensorflow.keras import layers
from tensorflow.keras.constraints import max_norm

data = np.random.random((1000, 32))
labels = np.random.random((1000, 10))

val_data = np.random.random((100, 32))
val_labels = np.random.random((100, 10))

# + jupyter={"outputs_hidden": true}
model = tf.keras.Sequential([
    
    layers.Dense(64, activation='relu', input_shape=(32,)),

    layers.Dense(64, activation='relu'),

    layers.Dense(10)])

model.compile(optimizer=tf.keras.optimizers.Adam(0.01),
              loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

model.fit(data, labels, epochs=10, batch_size=32,
          validation_data=(val_data, val_labels))

# + jupyter={"outputs_hidden": true}
model = tf.keras.Sequential()

model.add(layers.Dense(64, activation='relu', input_shape=(32,)))
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))

model.compile(optimizer=tf.keras.optimizers.Adam(0.01),
              loss=tf.keras.losses.CategoricalCrossentropy(),
              metrics=['accuracy'])

model.fit(data, labels, epochs=10, batch_size=32,
          validation_data=(val_data, val_labels))

# +
inputs = tf.keras.Input(shape=(32,))

x = layers.Dense(64, activation='relu')(inputs)
x = layers.Dense(64, activation='relu')(x)

predictions = layers.Dense(10)(x)


model = tf.keras.Model(inputs=inputs, outputs=predictions)

model.compile(optimizer=tf.keras.optimizers.Adam(0.01),
              loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

model.fit(data, labels, epochs=10, batch_size=32,
          validation_data=(val_data, val_labels))
# -

layers.Dense(units=64, activation=('relu'), 
    use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', 
    kernel_regularizer=regularizers.l2(0.01), activity_regularizer=regularizers.l1(0.01),
    bias_regularizer=l1_l2(l1=0.01, l2=0.01), kernel_constraint=max_norm(2.), bias_constraint=None)

layers.Conv2D(filters=32, kernel_size=5, strides=(1, 1), padding='valid', data_format='channels_last', dilation_rate=(1, 1), 
    activation="relu", 
    use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, 
    bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None)

layers.MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format='channels_last')


layers.LSTM(units=64, activation='tanh', recurrent_activation='sigmoid', use_bias=True, 
                  kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', 
                  unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, 
                  activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, 
                  dropout=0.0, recurrent_dropout=0.0, implementation=2, return_sequences=False, return_state=False, 
                  go_backwards=False, stateful=False, unroll=False)


layers.BatchNormalization(axis=-1, momentum=0.99, epsilon=0.001, center=True, scale=True, beta_initializer='zeros', 
                                gamma_initializer='ones', moving_mean_initializer='zeros', moving_variance_initializer='ones', 
                                beta_regularizer=None, gamma_regularizer=None, beta_constraint=None, gamma_constraint=None)


# +
inputs = tf.keras.Input(shape=(32,))

x = layers.Dense(64, activation='relu')(inputs)
x = layers.Dense(64, activation='relu')(x)

output1 = layers.Dense(64, activation='relu')(x)
output2 = layers.Dense(64, activation='relu')(x)

added = keras.layers.Add()([output1, output2])
subtracted = keras.layers.Subtract()([output1, output2])

multiply = keras.layers.Multiply()([output1, output2])
concatenate = keras.layers.Concatenate()([output1, output2])
average = keras.layers.Average()([output1, output2])

predictions = layers.Dense(10)(added)
# -

# Activations = sigmoid, tanh, relu, leaky relu, prelu, elu, threshold relu, selu, softmax, linear, softplus, softsign, hard sigmoid, exponential.
#
# initializers = zeros, ones, constant, random normal, random uniform, truncated normal, variance scaling, orthogonal, identity, lecun uniform, glorot normal, glorot uniform, he normal, lecun normal, he uniform. 
#
# losses = mean squared error, mean absolute error, mean absolute percentage error, mean squared logarithmic error, squared hinge, hinge, categorical hinge, logcash, huber loss, categorical crossentropy, sparse categorical crossentropy, binary crossentropy, kullback leibler divergence, poisson, cosine proximity, is categorical crossentropy.
#
# optimizers = SGD, rms prop, adagrad, adadelta, adamax, adam, nadam, amsgrad. 
#
# metrics = accuracy, binary accuracy, categorical accuracy, sparse categorical accuracy, top k categorical accuracy, sparse top k categorical accuracy, cosine proximity, clone metric. 

StarcoderdataJupyterScriptsDedupFiltered