在PyTorch中可以方便的验证SoftMax交叉熵损失和对输入梯度的计算
关于softmax_cross_entropy求导的过程,可以参考HERE
示例:
# -*- coding: utf-8 -*-
import torch
import torch.autograd as autograd
from torch.autograd import Variable
import torch.nn.functional as F
import torch.nn as nn
import numpy as np
# 对data求梯度, 用于反向传播
data = Variable(torc
1