From 666cf2eb6a311fee527401093f2cb1defc11ec80 Mon Sep 17 00:00:00 2001 From: Hachimocho <47281583+Hachimocho@users.noreply.github.com> Date: Wed, 13 Mar 2019 21:07:44 -0400 Subject: [PATCH] Add files via upload Changed stuff --- MTGAI-MiniBatch-v2-Copy2.ipynb | 299 ++++++++++++++++++++++++++++----- 1 file changed, 257 insertions(+), 42 deletions(-) diff --git a/MTGAI-MiniBatch-v2-Copy2.ipynb b/MTGAI-MiniBatch-v2-Copy2.ipynb index c966997..5ea2ce5 100644 --- a/MTGAI-MiniBatch-v2-Copy2.ipynb +++ b/MTGAI-MiniBatch-v2-Copy2.ipynb @@ -568,32 +568,33 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "tensor([[[-0.0368],\n", - " [ 1.7802],\n", - " [-0.0195],\n", + "3398\n", + "tensor([[[ 0.9633],\n", + " [ 0.7502],\n", + " [-0.5240],\n", " ...,\n", " [ 0.0000],\n", " [ 0.0000],\n", " [ 0.0000]],\n", "\n", - " [[ 1.0150],\n", - " [-0.4068],\n", - " [ 0.9770],\n", + " [[-1.3836],\n", + " [ 0.3328],\n", + " [-0.6156],\n", " ...,\n", " [ 0.0000],\n", " [ 0.0000],\n", " [ 0.0000]],\n", "\n", - " [[ 0.2954],\n", - " [-2.5393],\n", - " [ 1.1302],\n", + " [[-0.3394],\n", + " [-1.5314],\n", + " [ 0.2858],\n", " ...,\n", " [ 0.0000],\n", " [ 0.0000],\n", @@ -601,48 +602,259 @@ "\n", " ...,\n", "\n", - " [[ 0.1609],\n", - " [-1.5069],\n", - " [-2.5393],\n", + " [[ 0.7652],\n", + " [ 1.0033],\n", + " [-1.5314],\n", " ...,\n", " [ 0.0000],\n", " [ 0.0000],\n", " [ 0.0000]],\n", "\n", - " [[-0.1565],\n", - " [-2.5393],\n", - " [ 0.2954],\n", + " [[-0.7370],\n", + " [-1.5314],\n", + " [-0.3394],\n", " ...,\n", " [ 0.0000],\n", " [ 0.0000],\n", " [ 0.0000]],\n", "\n", - " [[-0.7049],\n", - " [-0.0195],\n", - " [-2.5393],\n", + " [[ 0.1024],\n", + " [-0.5240],\n", + " [-1.5314],\n", " ...,\n", " [ 0.0000],\n", " [ 0.0000],\n", " [ 0.0000]]], device='cuda:0', grad_fn=)\n", "torch.Size([100, 444, 1])\n", - "torch.Size([100, 444, 500])\n" + "torch.Size([100, 444, 50])\n", + "torch.Size([100, 444, 3398])\n", + "tensor([[[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [-0.3150],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " ...,\n", + "\n", + " [[ 0.1200],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [-0.3351],\n", + " [-0.0241],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]]], device='cuda:0', grad_fn=)\n", + "torch.Size([100, 444, 1])\n", + "torch.Size([100, 444, 50])\n", + "torch.Size([100, 444, 3398])\n", + "Trained on 100 cards.\n", + "Avg loss is: nan\n", + "tensor([[[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " ...,\n", + "\n", + " [[-0.0329],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [-1.4525],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]]], device='cuda:0', grad_fn=)\n", + "torch.Size([100, 444, 1])\n", + "torch.Size([100, 444, 50])\n", + "torch.Size([100, 444, 3398])\n", + "Trained on 200 cards.\n", + "Avg loss is: nan\n", + "tensor([[[-1.9569],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[-0.3117],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[-0.4553],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " ...,\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [ 0.0000],\n", + " [ 0.0000],\n", + " [ 0.0000]]], device='cuda:0', grad_fn=)\n", + "torch.Size([100, 444, 1])\n", + "torch.Size([100, 444, 50])\n", + "torch.Size([100, 444, 3398])\n", + "Trained on 300 cards.\n", + "Avg loss is: nan\n", + "tensor([[[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [0.0000],\n", + " [0.0000],\n", + " [0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [0.0000],\n", + " [0.0000],\n", + " [0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [0.0000],\n", + " [0.0000],\n", + " [0.0000]],\n", + "\n", + " ...,\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [0.0000],\n", + " [0.0000],\n", + " [0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [0.0000],\n", + " [0.0000],\n", + " [0.0000]],\n", + "\n", + " [[ nan],\n", + " [ nan],\n", + " [ nan],\n", + " ...,\n", + " [0.0000],\n", + " [0.0000],\n", + " [0.0000]]], device='cuda:0', grad_fn=)\n", + "torch.Size([100, 444, 1])\n", + "torch.Size([100, 444, 50])\n", + "torch.Size([100, 444, 3398])\n" ] }, { - "ename": "SystemExit", + "ename": "KeyboardInterrupt", "evalue": "", "output_type": "error", "traceback": [ - "An exception has occurred, use %tb to see the full traceback.\n", - "\u001b[0;31mSystemExit\u001b[0m\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/bryce/anaconda3/envs/pt/lib/python3.6/site-packages/IPython/core/interactiveshell.py:3275: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n", - " warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n" + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 73\u001b[0m \u001b[0mloss\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mLossF1\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpredictions\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbloop\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtargets\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbloop\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 74\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 75\u001b[0;31m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mretain_graph\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 76\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[0mtotalloss\u001b[0m\u001b[0;34m+=\u001b[0m \u001b[0mloss\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/lib/python3.6/site-packages/torch/tensor.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(self, gradient, retain_graph, create_graph)\u001b[0m\n\u001b[1;32m 91\u001b[0m \u001b[0mproducts\u001b[0m\u001b[0;34m.\u001b[0m \u001b[0mDefaults\u001b[0m \u001b[0mto\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;31m`\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 92\u001b[0m \"\"\"\n\u001b[0;32m---> 93\u001b[0;31m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mautograd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbackward\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgradient\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mretain_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_graph\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 94\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mregister_hook\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhook\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/.local/lib/python3.6/site-packages/torch/autograd/__init__.py\u001b[0m in \u001b[0;36mbackward\u001b[0;34m(tensors, grad_tensors, retain_graph, create_graph, grad_variables)\u001b[0m\n\u001b[1;32m 88\u001b[0m Variable._execution_engine.run_backward(\n\u001b[1;32m 89\u001b[0m \u001b[0mtensors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgrad_tensors\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mretain_graph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcreate_graph\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 90\u001b[0;31m allow_unreachable=True) # allow_unreachable flag\n\u001b[0m\u001b[1;32m 91\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 92\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " ] } ], @@ -718,15 +930,16 @@ " #sys.exit()\n", " #print(len(predictions))\n", " #loss = LossF1(torch.narrow(predictions.view(-1, len(Dict)), 0, 0, lengths[x]), torch.narrow(targets[x], 0, 0, lengths[x]))\n", - " loss = LossF1(predictions, targets)\n", + " for bloop in range(batch_size):\n", + " loss = LossF1(predictions[bloop], targets[bloop])\n", "\n", - " loss.backward(retain_graph=True)\n", + " loss.backward(retain_graph=True)\n", "\n", - " totalloss+= loss.item()\n", - " # `clip_grad_norm` helps prevent the exploding gradient problem in RNNs / LSTMs.\n", - " torch.nn.utils.clip_grad_norm_(AI.parameters(), .25)\n", + " totalloss+= loss.item()\n", + " # `clip_grad_norm` helps prevent the exploding gradient problem in RNNs / LSTMs.\n", + " torch.nn.utils.clip_grad_norm_(AI.parameters(), .25)\n", "\n", - " OptimF1.step()\n", + " OptimF1.step()\n", " if i != 0:\n", " print(\"Trained on \",i*batch_size, \" cards.\")\n", " print(\"Avg loss is: \",totalloss/(i*100))\n", @@ -790,7 +1003,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -799,10 +1012,12 @@ " def __init__(self, Dsize, input_size):\n", " super(MTGAI, self).__init__()\n", " self.Embed1 = nn.Embedding(Dsize, 1, padding_idx=0)\n", - " self.GRU = nn.GRU(1, 500, 3, batch_first=True) # input size, hidden size, num of layers to use\n", + " self.GRU = nn.GRU(1, 50, 3, batch_first=True) # input size, hidden size, num of layers to use\n", " self.Drop1 = nn.Dropout(.5)\n", " self.Drop2 = nn.Dropout(.5)\n", - " self.Lin1 = nn.Linear(500, Dsize)\n", + " self.dsize = Dsize\n", + " print(self.dsize)\n", + " self.Lin1 = nn.Linear(50, self.dsize)\n", " #self.Lin1.bias.data.fill_(0)\n", " #self.Lin1.weight.data.uniform_(-.1, .1)\n", " self.input_size = input_size\n", @@ -816,8 +1031,8 @@ " print(y.size())\n", " y, newh = self.GRU(y, h)\n", " print(y.size())\n", - " sys.exit()\n", " y = self.Lin1(y)\n", + " print(y.size())\n", " #for z in x:\n", " #y = self.Embed1(z).view(1, 1, -1)\n", " #y, newh = self.GRU(y, h)\n", @@ -835,7 +1050,7 @@ " \n", " def init_hidden(self, batch_size, input_size=1):\n", " weight = next(self.parameters()).data\n", - " return Variable(weight.new(3, 100, 500).zero_())" + " return Variable(weight.new(3, 100, 50).zero_())" ] }, {