- 博客(12)
- 收藏
- 关注
原创 PyTorch学习笔记(五):自动微分机制
1. 利用backward方法求导数loss.backward(),无返回值梯度信息在需要求导的变量的属性中:w1.grad、w2.grad# f(x) = a*x^2 + b*x + c的导数x = torch.tensor(0.0, requires_grad=True) # x需要被求导a = torch.tensor(1.0)b = torch.tensor(-2.0)c = torch.tensor(1.0)y = a*torch.pow(x,2) + b*x + c y.
2021-12-02 08:31:30 1211
原创 torch.where()
torch.where(condition, x, y) → TensorReturn a tensor of elements selected from either x or y, depending on condition.condition = torch.tensor([[0.6, 0.7], [0.8, 0.4]])print(condition)x = torch.zeros(2,2)print(x)y = torch.ones(2,2)print(y)# 输出ten.
2021-11-30 09:33:24 708
原创 PyTorch学习笔记(四):Tensor合并与分割
cata = torch.rand(4,32,8)b = torch.rand(5,32,8)print(torch.cat([a, b], dim=0).shape) # torch.Size([9, 32, 8])stack: create new dima = torch.rand(32,8)b = torch.rand(32,8)print(torch.stack([a, b], dim=0).shape) # torch.Size([2, 32, 8])split:
2021-11-30 09:20:58 1440
原创 PyTorch学习笔记(三):Tensor变换
view/reshapea = torch.rand(4,1,28,28)print(a.shape) # torch.Size([4, 1, 28, 28])print(a.view(4, 28*28).shape) # torch.Size([4, 784])print(a.reshape(4, 28*28).shape) # torch.Size([4, 784])print(a.view(4, -1).shape) #
2021-11-30 09:02:09 520
原创 PyTorch学习笔记(二):索引与切片
Indexing: dim 0 firsta = torch.rand(4,3,28,28)print(a.dim()) print(a.shape)# 输出4torch.Size([4, 3, 28, 28])print(a[0].shape) # torch.Size([3, 28, 28])print(a[0, 0].shape) # torch.Size([28, 28])print(a[0, 0, 0].shape) # torch.S
2021-11-29 21:49:42 285
原创 PyTorch学习笔记(一):创建Tensor
1、Tensor的维度和尺寸不同类型的数据可以用不同维度(dimension)的张量来表示,标量为0维张量,向量为1维张量,矩阵为2维以上的张量;可以简单地总结为:有几层中括号,就是多少维的张量;可以使用shape属性或者size()方法查看张量在每一维的长度;标量:# 标量(0维张量)scalar = torch.tensor(1)print(scalar)print(scalar.dim()) print(scalar.size())print(scalar.shape)# 输出te
2021-11-29 21:28:43 264
原创 nn.Parameter()
class Model(nn.Module): def __init__(self): super(Model, self).__init__() self.embedding = nn.Embedding(5, 10) self.dense_1 = nn.Linear(10, 5, bias=True) self.dense_2 = nn.Linear(5, 1, bias=True) def
2021-11-29 20:46:30 1407
原创 conda管理Jupyter Notebook中的kernel
查看jupyter kernelspec list删除jupyter kernelspec remove ‘kernelname’添加conda虚拟环境激活conda环境:source activate 环境名称安装ipykernel:conda install ipykernel将环境写入notebook的kernel中:python -m ipykernel install --user --name 环境名称 --display-name “你想为kernel添加的名称..
2021-11-29 20:02:55 424
原创 tf.gather和tf.gather_nd
tf.gatherGather slices from params axis according to indices.tf.gather(params, indices, validate_indices=None, axis=None, batch_dims=0, name=None)Example:# data: [classes, students, subjects]data = tf.ones([4,35,8])print(data.shape) # TensorShap
2021-11-23 09:10:10 883
原创 torch.gather()
torch.gather(input, dim, index) → TensorGathers values along an axis specified by dim.For a 3-D tensor the output is specified by:out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0out[i][j][k] = input[i][index[i][j][k]][k] # if dim.
2021-11-23 08:46:30 1108
原创 知识追踪(一):BKT
知识追踪(Knowledge Tracing)是根据学生过去的答题情况对学生的知识掌握情况进行建模,从而得到学生当前知识状态表示的一种技术。Bayesian Knowledge Tracing (BKT) 1是最早期的一种知识追踪模型,是含有隐变量的Hidden Markov Model(HMM)。BKT对每个知识点单独建立一个HMM模型,来预测学生在特定知识点的掌握情况(模型不考虑知识点之间的相关性)。
2021-11-02 20:36:23 6381
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人