Skip to content

Instantly share code, notes, and snippets.

@sergei-mironov
Created November 28, 2019 10:29
Show Gist options
  • Select an option

  • Save sergei-mironov/71ce6c69a8fb4a2fa48872feb0baade3 to your computer and use it in GitHub Desktop.

Select an option

Save sergei-mironov/71ce6c69a8fb4a2fa48872feb0baade3 to your computer and use it in GitHub Desktop.
demo_ll.py
@tf.function
def model(x, w0, b0, w1, b1, ...):
x = tf.nn.sigmoid(tf.matmul(x, w0) + b0)
x = tf.nn.sigmoid(tf.matmul(x, w1) + b1)
return x
def train(...):
for (x,y) in train_ds:
with tf.GradientTape() as tape:
loss = compute_loss(model(x, ...), y)
grads = tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment