![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pytorch学习笔记
pytorch的基础内容、框架、实战
qq_27860199
这个作者很懒,什么都没留下…
展开
-
pytorch实现word embedding :torch.nn.Embedding
import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Variable word_to_ix = {'hello': 0, 'world': 1} #每个单词用一个数字表示 embeds = nn.Embedding(2, ...原创 2020-04-02 22:21:09 · 770 阅读 · 0 评论 -
20200129-autograd与逻辑回归
torch.autograd torch.autograd.backward( tensor, #待求导张量 grad_tensors=None, #多维度权重 retain_graph=None, #保存计算图 create_graph=False) #创造导数计算图,用于高阶求导 功能:自动求取梯度 torch.autograd.grad( outputs, #...原创 2020-01-29 17:32:34 · 141 阅读 · 0 评论 -
线性回归
求解步骤 1.确定模型 y = wx +b 2.选择损失函数 MSE 3.求解梯度并更新w, b 梯度下降法求解 代码 import torch import matplotlib.pyplot as plt torch.manual_seed(10) lr = 0.1 #创建训练数据 x = torch.rand(20,1) * 10 y = 2 * x + (5 + torch.ran...原创 2020-01-16 23:24:58 · 147 阅读 · 0 评论 -
计算图与动态图机制
计算图 计算图用来描述运算的有向无环图,其中结点表示数据,如向量,矩阵,张量,边表示运算,如加减乘除、卷积等。 使用计算图的好处:(1)简介明了 (2)梯度求导方便 用计算图表示 y = (x + w) * (w + 1) 计算图与梯度求导 import torch w = torch.tensor([1.],requires_grad=True) x = torch.tensor([2.],r...原创 2020-01-16 23:23:35 · 557 阅读 · 0 评论 -
pytorch基础知识-tensor的操作
张量的操作 拼接 #将张量按维度dim进行拼接 #torch.cat(tensors, dim=0, out=None) t = torch.ones((2,3)) t_0 = torch.cat([t,t],dim=0) t_1 = torch.cat([t,t],dim=1) print("t_0:{}shape:{}\nt_1:{}shape:{}\n".format(t_0,t_0.s...原创 2020-01-16 16:02:23 · 321 阅读 · 0 评论 -
pytorch基础知识-tensor、variable
tensor tensor概念 1.tensor(张量)是什么? tensor是pytorch最基本的操作对象,表示的是一个多维的矩阵。 tensor与numpy相对应,可与numpy的ndarray相互转换。但pytorch可以再GPU上运行,ndarray只能在CPU上运行。 2.tensor的属性 #tensor的属性介绍 dtype 数据类型,如torch.FloatTensor,torc...原创 2020-01-13 22:52:44 · 585 阅读 · 0 评论