mirror of
https://github.com/mmaithani/data-science.git
synced 2022-04-24 02:56:41 +03:00
Created using Colaboratory
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
"colab": {
|
||||
"name": "PyTorch loss function.ipynb",
|
||||
"provenance": [],
|
||||
"authorship_tag": "ABX9TyN2ls8i+TU1RtdfYx0hlKp3",
|
||||
"authorship_tag": "ABX9TyNqBHXT6pkLWXMDT4iAggYW",
|
||||
"include_colab_link": true
|
||||
},
|
||||
"kernelspec": {
|
||||
@@ -61,7 +61,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "H_IA8ZaKaRLk",
|
||||
"outputId": "50618a35-02a2-4335-a4e8-db77cddb66d1"
|
||||
"outputId": "cfc6f35c-c6d7-4534-9874-68cea8a8a3d5"
|
||||
},
|
||||
"source": [
|
||||
"import numpy as np\r\n",
|
||||
@@ -78,7 +78,7 @@
|
||||
"mae_value = mae(y_pred, y_true)\r\n",
|
||||
"print (\"MAE error is: \" + str(mae_value))"
|
||||
],
|
||||
"execution_count": 50,
|
||||
"execution_count": 9,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
@@ -106,7 +106,7 @@
|
||||
"source": [
|
||||
"mae_loss = nn.L1Loss()"
|
||||
],
|
||||
"execution_count": null,
|
||||
"execution_count": 10,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
@@ -116,7 +116,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "8hFmTQetaqpx",
|
||||
"outputId": "f3e52cd9-c8a6-416e-be0e-d13864be361b"
|
||||
"outputId": "2d6f56a3-3ac5-4988-8e8d-d44d06ad5593"
|
||||
},
|
||||
"source": [
|
||||
"import torch\r\n",
|
||||
@@ -126,7 +126,7 @@
|
||||
"output = mae_loss(input, target)\r\n",
|
||||
"print(output)"
|
||||
],
|
||||
"execution_count": 19,
|
||||
"execution_count": 11,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
@@ -154,7 +154,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "o8b2cA7uZ65T",
|
||||
"outputId": "006589e3-0756-4c59-d556-32be32522a40"
|
||||
"outputId": "c32316ec-0a91-4150-b336-c3b0379451d4"
|
||||
},
|
||||
"source": [
|
||||
"input = torch.randn(3, 4, requires_grad=True)\r\n",
|
||||
@@ -169,18 +169,18 @@
|
||||
"print('target -: ', target)\r\n",
|
||||
"print('output -: ', output)"
|
||||
],
|
||||
"execution_count": 20,
|
||||
"execution_count": 12,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"input -: tensor([[ 1.1619, -2.0543, 1.0791, 0.2690],\n",
|
||||
" [-1.7409, -0.0396, 1.5357, 0.8317],\n",
|
||||
" [-0.7868, 0.2881, 0.1680, -2.2173]], requires_grad=True)\n",
|
||||
"target -: tensor([[ 0.8714, -0.4702, -0.2782, -0.4928],\n",
|
||||
" [ 0.4812, -0.0574, 1.7735, 0.6338],\n",
|
||||
" [-0.4336, 1.4518, -1.5495, -0.6904]])\n",
|
||||
"output -: tensor(1.4009, grad_fn=<MseLossBackward>)\n"
|
||||
"input -: tensor([[-0.8130, -0.1722, 2.1259, 0.9007],\n",
|
||||
" [ 0.4301, 0.2543, -0.3947, -1.8088],\n",
|
||||
" [ 0.0463, 1.6871, -0.4065, -0.5540]], requires_grad=True)\n",
|
||||
"target -: tensor([[ 0.9704, -0.1731, 0.0868, 0.8792],\n",
|
||||
" [-0.6950, -1.9831, -0.0518, -0.1137],\n",
|
||||
" [ 0.5052, 0.6071, 1.5943, -0.8278]])\n",
|
||||
"output -: tensor(1.8380, grad_fn=<MseLossBackward>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
@@ -211,7 +211,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "fb6Ev6VMffV-",
|
||||
"outputId": "ca174acf-cc7d-4be0-f7cd-d00a8a912068"
|
||||
"outputId": "cf989d97-7ce9-46d4-aa16-1b3efb1e0090"
|
||||
},
|
||||
"source": [
|
||||
"import numpy as np\r\n",
|
||||
@@ -228,7 +228,7 @@
|
||||
"bce_value = BCE(y_pred, y_true)\r\n",
|
||||
"print (\"BCE error is: \" + str(bce_value))"
|
||||
],
|
||||
"execution_count": 32,
|
||||
"execution_count": 13,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
@@ -255,7 +255,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "HxylWO3Bf48h",
|
||||
"outputId": "01817914-0403-48d8-bde2-cdc6a084f273"
|
||||
"outputId": "a59ec09f-813a-4ea7-cdcd-0246b12ffad8"
|
||||
},
|
||||
"source": [
|
||||
"bce_loss = torch.nn.BCELoss()\r\n",
|
||||
@@ -265,7 +265,7 @@
|
||||
"output = bce_loss(input, target)\r\n",
|
||||
"output"
|
||||
],
|
||||
"execution_count": 37,
|
||||
"execution_count": 14,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "execute_result",
|
||||
@@ -277,7 +277,49 @@
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"execution_count": 37
|
||||
"execution_count": 14
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "kMqXnUB8tg_w"
|
||||
},
|
||||
"source": [
|
||||
"## BCEWithLogitsLoss(nn.BCEWithLogitsLoss)\r\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "3zfpYHGjjHqP",
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"outputId": "76415ba8-ec05-4ecf-a9be-04a82d1313c9"
|
||||
},
|
||||
"source": [
|
||||
"import torch\r\n",
|
||||
"target = torch.ones([10, 64], dtype=torch.float32) # 64 classes, batch size = 10\r\n",
|
||||
"output = torch.full([10, 64], 1.5) # A prediction (logit)\r\n",
|
||||
"pos_weight = torch.ones([64]) # All weights are equal to 1\r\n",
|
||||
"criterion = torch.nn.BCEWithLogitsLoss(pos_weight=pos_weight)\r\n",
|
||||
"criterion(output, target) # -log(sigmoid(1.5))"
|
||||
],
|
||||
"execution_count": 15,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "execute_result",
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tensor(0.2014)"
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"execution_count": 15
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -297,7 +339,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "HpPl1N89fI4Y",
|
||||
"outputId": "c747da08-6857-45f7-c43c-df97d9d0da44"
|
||||
"outputId": "766fde07-a229-45ce-8202-eba0721859e6"
|
||||
},
|
||||
"source": [
|
||||
"input = torch.randn(3, 5, requires_grad=True)\r\n",
|
||||
@@ -313,21 +355,64 @@
|
||||
"print('target -: ', target)\r\n",
|
||||
"print('output -: ', output)"
|
||||
],
|
||||
"execution_count": 38,
|
||||
"execution_count": 16,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"input -: tensor([[-0.3998, 2.5459, 2.0591, 1.0049, 0.3083],\n",
|
||||
" [ 0.7276, 0.1679, 0.0694, -0.4694, -0.5898],\n",
|
||||
" [-0.6252, -0.8939, -1.1183, -0.8719, 0.1156]], requires_grad=True)\n",
|
||||
"input -: tensor([[ 0.2100, -0.2934, -0.2368, -0.9120, -0.8677],\n",
|
||||
" [ 0.1300, -0.4204, 0.5999, 0.2263, -0.0318],\n",
|
||||
" [ 1.0562, -0.6507, -2.2783, 0.2079, 0.2805]], requires_grad=True)\n",
|
||||
"target -: tensor([1, 0, 4])\n",
|
||||
"output -: tensor(0.8611, grad_fn=<NllLossBackward>)\n"
|
||||
"output -: tensor(1.5756, grad_fn=<NllLossBackward>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "OLIpmLghtjwe"
|
||||
},
|
||||
"source": [
|
||||
"## PoissonNLLLoss"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "t7MB8eCbtVC-",
|
||||
"colab": {
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"outputId": "733e1ec0-e091-4a05-8f7a-f61016e505ed"
|
||||
},
|
||||
"source": [
|
||||
"import torch.nn as nn\r\n",
|
||||
"loss = nn.PoissonNLLLoss()\r\n",
|
||||
"log_input = torch.randn(5, 2, requires_grad=True)\r\n",
|
||||
"target = torch.randn(5, 2)\r\n",
|
||||
"output = loss(log_input, target)\r\n",
|
||||
"output.backward()\r\n",
|
||||
"output"
|
||||
],
|
||||
"execution_count": 17,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "execute_result",
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"tensor(1.0439, grad_fn=<MeanBackward0>)"
|
||||
]
|
||||
},
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"execution_count": 17
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -345,7 +430,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "2mYMGOXthk8p",
|
||||
"outputId": "e33ec5e6-6d85-42c8-a43b-8e060969111b"
|
||||
"outputId": "00dc8cf0-d433-4d2a-f734-0fd6f0076028"
|
||||
},
|
||||
"source": [
|
||||
"input = torch.randn(3, 5, requires_grad=True)\r\n",
|
||||
@@ -359,16 +444,16 @@
|
||||
"print('target: ', target)\r\n",
|
||||
"print('output: ', output)"
|
||||
],
|
||||
"execution_count": 39,
|
||||
"execution_count": 18,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"input: tensor([[-0.0873, 0.2695, -1.0779, 0.2443, -1.2279],\n",
|
||||
" [ 0.5567, 0.3258, 0.3356, 0.4241, -0.9079],\n",
|
||||
" [-0.6800, 0.3731, -0.3557, 0.7839, 0.8058]], requires_grad=True)\n",
|
||||
"target: tensor([4, 2, 2])\n",
|
||||
"output: tensor(2.1639, grad_fn=<NllLossBackward>)\n"
|
||||
"input: tensor([[-0.5641, 2.0046, 0.4709, -1.3824, 0.3271],\n",
|
||||
" [ 0.2807, -0.8588, -0.6625, 1.1710, -1.1822],\n",
|
||||
" [-0.3820, 0.2075, 0.6264, -0.5623, -0.6328]], requires_grad=True)\n",
|
||||
"target: tensor([3, 2, 3])\n",
|
||||
"output: tensor(2.7897, grad_fn=<NllLossBackward>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
@@ -390,7 +475,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "xfStGspphvwy",
|
||||
"outputId": "4a8ce470-0688-4fea-ee49-0b9a9749700a"
|
||||
"outputId": "6dc99ac5-10f6-4e74-a3ac-55d624547c89"
|
||||
},
|
||||
"source": [
|
||||
"input = torch.randn(3, 5, requires_grad=True)\r\n",
|
||||
@@ -404,18 +489,18 @@
|
||||
"print('target -: ', target)\r\n",
|
||||
"print('output -: ', output)"
|
||||
],
|
||||
"execution_count": 42,
|
||||
"execution_count": 19,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"input -: tensor([[ 0.7387, -0.3632, -0.9038, 0.8583, -0.3724],\n",
|
||||
" [ 0.1367, -0.5990, -0.6288, -0.1092, -1.6801],\n",
|
||||
" [ 0.3843, 0.0901, -1.3474, -1.0471, 1.2579]], requires_grad=True)\n",
|
||||
"target -: tensor([[ 0.0659, -0.0695, -0.0055, 1.4541, -0.6346],\n",
|
||||
" [ 1.7301, -1.3945, -0.9082, -2.0155, 0.5129],\n",
|
||||
" [-3.1528, -0.8972, -1.1135, -1.6087, 1.5804]])\n",
|
||||
"output -: tensor(1.0172, grad_fn=<MeanBackward0>)\n"
|
||||
"input -: tensor([[-1.3021, 0.1646, -0.6010, 1.1430, 0.0962],\n",
|
||||
" [ 0.2079, 1.8048, -0.9333, 1.1201, -1.1432],\n",
|
||||
" [ 0.1606, -0.0297, 0.6047, 0.1355, 0.5362]], requires_grad=True)\n",
|
||||
"target -: tensor([[-1.5627, -1.5915, 0.5986, 0.4758, -1.1109],\n",
|
||||
" [-1.9742, 1.1048, -0.5299, -0.0454, 0.2371],\n",
|
||||
" [-0.0415, -0.3526, 0.9375, 0.6387, 0.6531]])\n",
|
||||
"output -: tensor(1.0712, grad_fn=<MeanBackward0>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
@@ -443,7 +528,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "JyN0cc1GiEZE",
|
||||
"outputId": "9aafa862-9a9f-4deb-ae24-7d7410f0cf48"
|
||||
"outputId": "7fdba3d7-00ac-49af-dd0f-c36f1f829cf1"
|
||||
},
|
||||
"source": [
|
||||
"first_input = torch.randn(3, requires_grad=True)\r\n",
|
||||
@@ -459,15 +544,15 @@
|
||||
"print('target: ', target)\r\n",
|
||||
"print('output: ', output)"
|
||||
],
|
||||
"execution_count": 43,
|
||||
"execution_count": 20,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"input one: tensor([-0.9101, -0.1720, 0.3739], requires_grad=True)\n",
|
||||
"input two: tensor([-0.1041, 1.8790, 0.6346], requires_grad=True)\n",
|
||||
"target: tensor([ 1., 1., -1.])\n",
|
||||
"output: tensor(0.9523, grad_fn=<MeanBackward0>)\n"
|
||||
"input one: tensor([ 0.0219, -0.7005, -1.2160], requires_grad=True)\n",
|
||||
"input two: tensor([-0.4255, 0.3859, -0.7394], requires_grad=True)\n",
|
||||
"target: tensor([-1., -1., 1.])\n",
|
||||
"output: tensor(0.3080, grad_fn=<MeanBackward0>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
@@ -489,7 +574,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "H-VV1XSNihPT",
|
||||
"outputId": "04d0f6f2-20b0-450a-880c-4019ac1211ee"
|
||||
"outputId": "d5add53c-177b-4e43-d88f-087a938dd4f6"
|
||||
},
|
||||
"source": [
|
||||
"anchor = torch.randn(100, 128, requires_grad=True)\r\n",
|
||||
@@ -505,36 +590,41 @@
|
||||
"print('negative -: ', negative)\r\n",
|
||||
"print('output -: ', output)"
|
||||
],
|
||||
"execution_count": 44,
|
||||
"execution_count": 21,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"anchors -: tensor([[ 2.2149, -0.4624, 0.1297, ..., -0.9314, 0.6589, -1.0044],\n",
|
||||
" [ 0.5554, -0.5520, 0.1106, ..., 1.6740, 0.1103, -0.2415],\n",
|
||||
" [ 0.8692, -0.6139, -0.0073, ..., 1.3570, 0.4758, 1.3609],\n",
|
||||
"anchors -: tensor([[-0.0458, -0.2617, 0.8472, ..., 1.7588, -1.3604, 0.7182],\n",
|
||||
" [ 1.2925, 1.7845, -1.0670, ..., -0.4664, -0.6562, -0.5562],\n",
|
||||
" [-0.4970, -0.5046, -1.8275, ..., -1.7325, -0.0448, 0.2471],\n",
|
||||
" ...,\n",
|
||||
" [-0.8563, -0.9356, 0.4538, ..., 0.4140, 0.6785, -0.5354],\n",
|
||||
" [-0.7295, -0.3626, 1.8515, ..., 0.2087, -1.0304, -0.4069],\n",
|
||||
" [ 0.9843, -0.5925, 0.8998, ..., -0.4079, -0.2412, -1.1588]],\n",
|
||||
" [ 0.5414, 0.1786, 0.8064, ..., -0.6623, -0.2556, -0.2867],\n",
|
||||
" [-1.1563, -1.7103, 2.2845, ..., 1.0123, -0.3839, -1.3699],\n",
|
||||
" [ 0.7297, -0.1043, -0.1768, ..., 0.3457, -0.8843, -0.0626]],\n",
|
||||
" requires_grad=True)\n",
|
||||
"positive -: tensor([[-0.0955, 0.8232, 1.8161, ..., 0.6107, 0.6104, 0.0668],\n",
|
||||
" [ 0.2414, -0.1431, 0.9935, ..., -0.8267, -1.6068, 0.4890],\n",
|
||||
" [ 1.6151, 0.0211, 0.6835, ..., 0.4580, 0.6620, 1.1240],\n",
|
||||
"positive -: tensor([[ 7.4869e-01, 1.3499e+00, -1.4480e+00, ..., -7.6688e-01,\n",
|
||||
" -1.7461e-03, -7.0950e-01],\n",
|
||||
" [-1.0364e+00, 1.0784e+00, 1.4848e+00, ..., -6.4932e-01,\n",
|
||||
" -2.4223e-01, 4.4354e-01],\n",
|
||||
" [ 1.9670e-01, -8.3027e-01, 2.5105e-01, ..., -9.0814e-01,\n",
|
||||
" -2.3587e-01, 1.3626e+00],\n",
|
||||
" ...,\n",
|
||||
" [-0.7226, 1.2047, -0.8483, ..., 1.7136, 0.4394, -0.5176],\n",
|
||||
" [-0.4288, 0.2157, 0.6404, ..., -1.4232, -0.1568, 0.9827],\n",
|
||||
" [-1.5980, -0.7540, -0.6185, ..., -0.6710, -0.1606, 0.6274]],\n",
|
||||
" requires_grad=True)\n",
|
||||
"negative -: tensor([[-0.5671, 1.0394, -1.9852, ..., 0.3935, 0.2195, -0.0899],\n",
|
||||
" [-0.9655, -0.0856, 0.3572, ..., 0.1853, -0.1454, 0.6056],\n",
|
||||
" [ 0.9698, 0.8990, 0.0716, ..., 1.7177, 1.0162, -0.3807],\n",
|
||||
" [-2.3753e+00, -1.0636e+00, 3.1268e+00, ..., 1.5887e-01,\n",
|
||||
" 6.0285e-02, 3.2817e-01],\n",
|
||||
" [ 1.0319e+00, -9.9035e-01, -9.8707e-01, ..., 1.2975e+00,\n",
|
||||
" 6.1644e-01, 1.2362e+00],\n",
|
||||
" [ 4.4754e-01, 1.7472e+00, -1.0116e+00, ..., 5.9146e-01,\n",
|
||||
" -3.1294e-01, -1.2864e-01]], requires_grad=True)\n",
|
||||
"negative -: tensor([[-1.5941, 0.7201, -0.8380, ..., 1.4464, 1.9402, 1.0685],\n",
|
||||
" [-1.3552, 0.9982, -0.2235, ..., -0.6102, 0.4565, -0.7907],\n",
|
||||
" [ 1.1297, -0.0303, 1.2934, ..., 1.0800, 1.0632, 2.3885],\n",
|
||||
" ...,\n",
|
||||
" [ 0.3375, -1.4678, -1.3988, ..., 0.8750, 0.2375, 0.6745],\n",
|
||||
" [ 0.2241, 0.0142, 1.2166, ..., -0.3842, 0.1596, 1.4880],\n",
|
||||
" [-1.1877, 0.9875, -0.0813, ..., 0.3107, 0.3279, -0.4012]],\n",
|
||||
" [-1.2044, -0.2218, -1.7082, ..., 0.7270, -1.3822, 0.9942],\n",
|
||||
" [-0.4531, -1.3416, -0.9141, ..., 1.0345, -0.5356, -0.9907],\n",
|
||||
" [-0.1342, -1.6461, 1.2896, ..., 0.1225, 1.3387, -0.8353]],\n",
|
||||
" requires_grad=True)\n",
|
||||
"output -: tensor(1.1650, grad_fn=<MeanBackward0>)\n"
|
||||
"output -: tensor(1.0123, grad_fn=<MeanBackward0>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
@@ -556,7 +646,7 @@
|
||||
"base_uri": "https://localhost:8080/"
|
||||
},
|
||||
"id": "RpnNQ0TpXHLz",
|
||||
"outputId": "bbba9b76-0018-4b68-de74-04a292e19215"
|
||||
"outputId": "2d7b6d1a-1e3f-4e7a-b277-deade7439f72"
|
||||
},
|
||||
"source": [
|
||||
"input = torch.randn(2, 3, requires_grad=True)\r\n",
|
||||
@@ -570,16 +660,16 @@
|
||||
"print('target tensor: ', target)\r\n",
|
||||
"print('Loss: ', output)"
|
||||
],
|
||||
"execution_count": 48,
|
||||
"execution_count": 22,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"input tensor: tensor([[-0.6098, -1.2917, 0.0380],\n",
|
||||
" [ 0.3440, 0.7980, 0.1073]], requires_grad=True)\n",
|
||||
"target tensor: tensor([[-1.9751, 0.1022, -0.1736],\n",
|
||||
" [-0.3326, -0.1292, -1.2224]])\n",
|
||||
"Loss: tensor(-0.0505, grad_fn=<DivBackward0>)\n"
|
||||
"input tensor: tensor([[-0.8168, 1.6042, -0.7599],\n",
|
||||
" [-0.6457, 0.3002, -0.7881]], requires_grad=True)\n",
|
||||
"target tensor: tensor([[ 1.1857, 0.6820, -0.5791],\n",
|
||||
" [-0.3623, -0.7202, -0.0946]])\n",
|
||||
"Loss: tensor(-0.0923, grad_fn=<DivBackward0>)\n"
|
||||
],
|
||||
"name": "stdout"
|
||||
}
|
||||
@@ -588,7 +678,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"metadata": {
|
||||
"id": "3zfpYHGjjHqP"
|
||||
"id": "swOodmepx_Su"
|
||||
},
|
||||
"source": [
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user