<jupyter_start><jupyter_text><jupyter_code>#cpu 모드
import torch 
torch.manual_seed(777)
X = torch.FloatTensor([[0,0],[0,1],[1,0],[1,1]])
Y = torch.FloatTensor([[0],[1],[1],[0]])
X
Y<jupyter_output><empty_output><jupyter_text>NN 모델 정의<jupyter_code>#모델 정의 
#Layer 정의 
layer1  = torch.nn.Linear(2,2,bias=True)
layer2  = torch.nn.Linear(2,1,bias=True) # fully connected layer 2개입력 / 출력 1
sigmoid = torch.nn.Sigmoid()

model = torch.nn.Sequential(layer1,sigmoid,layer2,sigmoid) #입력이랑 출력이랑 연결해줌
#순서 중요 
model<jupyter_output><empty_output><jupyter_text>모델 학습<jupyter_code>#Binary Cross Entropy Loss
#매뉴얼 보면서 ㄹ
loss = torch.nn.BCELoss()

optimizer = torch.optim.SGD(model.parameters(),lr=1)
for stop in range(50000):
    optimizer.zero_grad()
    hypothesis = model(X)
    cost = loss(hypothesis,Y)
    cost.backward()
    optimizer.step()
    if stop % 100 == 0:
      print(stop,cost.item())<jupyter_output>0 0.7434073090553284
100 0.693165123462677
200 0.6931577920913696
300 0.6931517124176025
400 0.6931463479995728
500 0.6931411027908325
600 0.6931357383728027
700 0.6931294798851013
800 0.6931220889091492
900 0.6931126117706299
1000 0.6930999755859375
1100 0.693082332611084
1200 0.6930569410324097
1300 0.6930190324783325
1400 0.6929606199264526
1500 0.6928660273551941
1600 0.6927032470703125
1700 0.6923960447311401
1800 0.6917302012443542
1900 0.6899653673171997
2000 0.6838315725326538
2100 0.6561667919158936
2200 0.4311015009880066
2300 0.13489337265491486
2400 0.06630437076091766
2500 0.04216819629073143
2600 0.030453868210315704
2700 0.02366594225168228
2800 0.01927773468196392
2900 0.01622403785586357
3000 0.013983793556690216
3100 0.012273931875824928
3200 0.010928118601441383
3300 0.009842473082244396
3400 0.008949032984673977
3500 0.008201321586966515
3600 0.0075667379423975945
3700 0.007021686062216759
3800 0.006548595614731312
3900 0.006134253926575184
4000 0.005768375005573034[...]<jupyter_text>모델 평가<jupyter_code>with torch.no_grad():
    hypothesis = model(X)
    predicted = (hypothesis > 0.5).float()
    accuracy = (predicted == Y).float().mean()
    print('\n Hypothesis : ',hypothesis.numpy(),'\n Correct : ',predicted.numpy(),'\n Accuracy:',accuracy.item())<jupyter_output>Hypothesis :  [[1.6898758e-04]
 [9.9982661e-01]
 [9.9982661e-01]
 [2.5993527e-04]] 
 Correct :  [[0.]
 [1.]
 [1.]
 [0.]] 
 Accuracy: 1.0
{'fraction_non_alphanumeric': 0.12339880444064902, 'fraction_numerical': 0.410333048676345, 'mean_word_length': 5.713467048710601, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '541890', 'license': 'MIT', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1120, 'n_words': 171, 'path': 'XOR_Perceptron.ipynb', 'repo_name': 'LeeGitaek/2020_AI_Class', 'size': '2342'}