<jupyter_start><jupyter_text>다층 퍼셉트론으로 XOR 게이트 구현하기<jupyter_code>import tensorflow as tf
import numpy as np

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import RMSprop
from tensorflow.keras.losses import mse
tf.random.set_seed(42)

# dataset
x = np.array([[0, 0], [1, 0], [0, 1], [1, 1]])
y = np.array([[0], [1], [1], [0]])

# model set-up
model = Sequential()
model.add(Dense(32, input_shape = (2, ), activation='relu'))
model.add(Dense(1, activation='sigmoid'))

model.compile(
    optimizer = RMSprop(),
    loss = mse,
    metrics = ['acc'])

# training
model.fit(x, y, epochs=100)<jupyter_output>Epoch 1/100
1/1 [==============================] - 1s 1s/step - loss: 0.2424 - acc: 0.5000
Epoch 2/100
1/1 [==============================] - 0s 5ms/step - loss: 0.2408 - acc: 0.2500
Epoch 3/100
1/1 [==============================] - 0s 5ms/step - loss: 0.2396 - acc: 0.5000
Epoch 4/100
1/1 [==============================] - 0s 5ms/step - loss: 0.2386 - acc: 0.5000
Epoch 5/100
1/1 [==============================] - 0s 4ms/step - loss: 0.2377 - acc: 0.5000
Epoch 6/100
1/1 [==============================] - 0s 3ms/step - loss: 0.2370 - acc: 0.5000
Epoch 7/100
1/1 [==============================] - 0s 5ms/step - loss: 0.2364 - acc: 0.5000
Epoch 8/100
1/1 [==============================] - 0s 4ms/step - loss: 0.2358 - acc: 0.5000
Epoch 9/100
1/1 [==============================] - 0s 5ms/step - loss: 0.2352 - acc: 0.7500
Epoch 10/100
1/1 [==============================] - 0s 4ms/step - loss: 0.2347 - acc: 0.7500
Epoch 11/100
1/1 [==============================] - 0s 6ms/step - loss: 0.2341 -[...]
{'fraction_non_alphanumeric': 0.34026128266033256, 'fraction_numerical': 0.12826603325415678, 'mean_word_length': 3.9558823529411766, 'pattern_counts': {'":': 0, '<': 4, '<?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': '619356', 'license': 'MIT', 'n_tokens_mistral': 800, 'n_tokens_neox': 646, 'n_words': 161, 'path': '33_XOR_gate.ipynb', 'repo_name': 'gongsh93/tensorflow-example', 'size': '1684'}