从1开始的LSTM
为什么是“从1开始”?因为RNN的逻辑实在太绕,而且正逐渐被Transformer取代,所以我直接调用了nn.LSTM,重点在于数据集处理和训练,预测函数 123456789101112131415161718192021222324252627282930import torchfrom torch import nnimport collectionsimport reclass SimpleRNNModel(nn.Module): def __init__(self, vocab_size, num_hiddens): super().__init__() self.num_hiddens = num_hiddens # 1. Embedding 层:把字符 ID 转成稠密向量 self.embedding = nn.Embedding(vocab_size, num_hiddens) # 2. RNN 层:核心循环动力 self.rnn = nn.LSTM(num_hiddens,...
从0开始的ResNet
123456789101112131415161718192021222324import torchimport torchvisionimport torchvision.transforms as transformsimport torch.nn as nntransform_train=transforms.Compose([ transforms.RandomCrop(32,padding=4), transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994, 0.2010)),])transform_test=transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.4914, 0.4822, 0.4465), (0.2023, 0.1994,...
从0开始的Transformer
基于pytorch,从底层实现transformer1234import torchfrom torch import nnimport mathimport re 1device=torch.device('mps') 读取数据集,这里使用”time machine” 12345def read_time_machine(): # 这里假设你已经有了 txt 文件,或者直接从网络下载 with open('timemachine.txt', 'r') as f: lines = f.readlines() return [re.sub('[^A-Za-z]+', ' ', line).strip().lower() for line in...
BlogGuide
本文采用Hexo+Git+Nodejs+Github+Aliyun+Vercel方式搭建个人博客网站 一,必备工具的安装下载Git,Nodejs,Hexo 官网下载git,nodejs并安装 测试是否下载成功:打开cmd,输入: 123node -vnpm -v(这个是node附带的)git -v 出现版本号即为安装成功3. 下载Hexo:在cmd中输入: 1npm install hexo-cli -g git与github的账户配置(如果你已有git和github账号,请忽略此步) 进入任意文件夹,右键空白处然后点击Git Bash Here,输入: 12git config --global user.email "你的邮箱"git config --global user.name "你的名字" 进入GitHub网站,注册一个账号 二,创建GitHub仓库 进入GitHub网站,点击Create a new repository进入新建仓库页面,仓库名输入: 1用户名.github.io 勾选 Public 勾选...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment