<jupyter_start><jupyter_text>single layer neural network<jupyter_code>import tensorflow as tf

from numpy.random import RandomState

batch_size = 8

w1 = tf.Variable(tf.random_normal([2,3], stddev=1, seed=1))
w2 = tf.Variable(tf.random_normal([3,1], stddev=1, seed=1))

x = tf.placeholder(tf.float32, shape=(None, 2), name="x-input")
y_ = tf.placeholder(tf.float32, shape=(None, 1), name="y-input")


#a = tf.nn.relu(tf.matmul(x, w1))
a = tf.nn.sigmoid(tf.matmul(x, w1))
#a = tf.tanh(tf.matmul(x, w1))

y = tf.matmul(a, w2)

cross_entropy = -tf.reduce_mean(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0)) 
                               + (1 - y_) * tf.log(tf.clip_by_value(1-y, 1e-10, 1.0)))

train_step = tf.train.AdamOptimizer(0.001).minimize(cross_entropy)

dataset_size = 128

rdm = RandomState(1)
X = rdm.rand(dataset_size, 2)

Y = [[int(x1 + x2 < 1)] for (x1, x2) in X]


with tf.Session() as sess:
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    
    print(sess.run(w1))
    print(sess.run(w2))
    
    STEPS = 5000
    for i in range(STEPS):
        start = (i * batch_size) % dataset_size
        end = min(start + batch_size, dataset_size)
        #print(Y[start:end])
        #print(X[start:end])
        sess.run(train_step, feed_dict={x: X[start:end], y_: Y[start:end]})
        if i % 1000 == 0:
            total_cross_entropy = sess.run(
            cross_entropy, feed_dict={x: X, y_: Y})
            print("After %d training steps, cross entropy on all data is %g" % (i, total_cross_entropy))
    print(sess.run(w1))  
    print(sess.run(w2))<jupyter_output>[[-0.8113182   1.4845988   0.06532937]
 [-2.4427042   0.0992484   0.5912243 ]]
[[-0.8113182 ]
 [ 1.4845988 ]
 [ 0.06532937]]
After 0 training steps, cross entropy on all data is 8.60555
After 1000 training steps, cross entropy on all data is 1.18626
After 2000 training steps, cross entropy on all data is 1.04257
After 3000 training steps, cross entropy on all data is 0.95908
After 4000 training steps, cross entropy on all data is 0.875381
[[-0.4646573   0.9296048   1.0087776 ]
 [-2.1772292  -0.36850733  1.2463576 ]]
[[-0.24252824]
 [ 1.2319056 ]
 [-0.23045173]]
{'fraction_non_alphanumeric': 0.1503690036900369, 'fraction_numerical': 0.11854243542435425, 'mean_word_length': 3.244618395303327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '104003', 'license': 'Apache-2.0', 'n_tokens_mistral': 1027, 'n_tokens_neox': 873, 'n_words': 199, 'path': 'notebooks/tf-basic-single-nn.ipynb', 'repo_name': 'daiwk/grace_t', 'size': '2168'}