Last active
April 5, 2021 13:39
-
-
Save d3lm/4eb7b4f498ecf1ac61782427124b0dd2 to your computer and use it in GitHub Desktop.
tf_api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import tf_api as tf | |
# Create model | |
model = lambda x: 1.23 * x + 10 | |
# Create small dataset of 5 entries | |
train_X = np.linspace(0, 5, 5).reshape((-1, 1)) | |
train_Y = np.array([model(x) for x in train_X]).reshape((-1, 1)) | |
# Create default graph | |
tf.Graph().as_default() | |
X = tf.Placeholder() | |
# Weights | |
Wh = tf.Variable(np.array([[0.5, 0.3, 0.2]])) | |
Wo = tf.Variable(np.array([[0.4,0.1,0.2]]).T) | |
# Biases | |
Bh = tf.Variable(np.array([0.1, 0.2, 0.3])) | |
Bo = tf.Variable(np.array([0.2])) | |
# Computations (input → hidden and hidden → output) | |
hidden_output = tf.add(tf.matmul(X, Wh), Bh) | |
output = tf.add(tf.matmul(hidden_output, Wo), Bo) | |
# Create session | |
session = tf.Session() | |
# Run session and train for 5 epochs | |
for epoch in range(5): | |
for x in train_X: | |
pred = session.run(output, { X: x }) | |
print(pred) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment