<jupyter_start><jupyter_text><jupyter_code>try:
  # %tensorflow_version only exists in Colab.
  %tensorflow_version 2.x
except Exception:
  pass
X = [[0, 0], [0, 1], [1, 0], [1, 1]]
y = [0, 1, 1, 0]



# sgd cant do this with 1 node 
import tensorflow as tf
import numpy as np

X = np.array(X)
y = np.array(y)

model = tf.keras.models.Sequential([
  tf.keras.layers.Dense(2, activation='relu'),
])
sgd = tf.keras.optimizers.SGD(learning_rate=0.1)
model.compile(optimizer= sgd,
              
              loss='mean_squared_error',
              metrics=['mean_squared_error'])
model.fit(X, y, epochs=1000, verbose=0)
_, acc = model.evaluate(X, y)
print('acc = ' + str(acc))
import tensorflow as tf
import numpy as np

X = np.array(X)
y = np.array(y)

model = tf.keras.models.Sequential([
  tf.keras.layers.Dense(2, activation='tanh', input_shape=(2,)),
  tf.keras.layers.Dense(1, activation='sigmoid'),
])
sgd = tf.keras.optimizers.SGD(learning_rate=0.1)
model.compile(optimizer=sgd,
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.fit(X, y, batch_size = 4, epochs=10000, verbose=0)
_, acc = model.evaluate(X, y)
print(model.predict_proba(X))
print(model.get_weights())

print(model.predict(X,batch_size=4))
print('acc = ' + str(acc))

#adam much better but still 100 
import tensorflow as tf
import numpy as np

X = np.array(X)
y = np.array(y)

model = tf.keras.models.Sequential([
  tf.keras.layers.Dense(2, activation='tanh', input_shape=(2,)),
  tf.keras.layers.Dense(1, activation='sigmoid'),
])
sgd = tf.keras.optimizers.Adam(learning_rate=0.1)
model.compile(optimizer=sgd,
              loss='binary_crossentropy',
              metrics=['accuracy'])
model.fit(X, y, batch_size = 4, epochs=100, verbose=1)
_, acc = model.evaluate(X, y)
print(model.predict_proba(X))
print(model.get_weights())

print(model.predict(X,batch_size=4))
print('acc = ' + str(acc))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16614906832298137, 'fraction_numerical': 0.025362318840579712, 'mean_word_length': 4.238482384823849, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '627044', 'license': 'MIT', 'n_tokens_mistral': 780, 'n_tokens_neox': 739, 'n_words': 145, 'path': '2_xor_composition.ipynb', 'repo_name': 'bklooste/ANNe', 'size': '1932'}