08 2022 档案
摘要:点击查看代码 import torch from torch import nn from d2l import torch as d2l net = nn.Sequential( nn.Conv2d(1, 6, kernel_size=5, padding=2), nn.Sigmoid(), nn
阅读全文
摘要:点击查看代码 import torch from torch import nn from d2l import torch as d2l # 输出为输入中每个区域的最大值或平均值 def pool2d(X, pool_size, mode='max'): p_h, p_w = pool_size
阅读全文
摘要:点击查看代码 import torch from d2l import torch as d2l def corr2d_multi_in(X, K): # 先遍历“X”和“K”的第0个维度(通道维度),再把它们加在一起 # print('K.shape = ', K.shape) return su
阅读全文
摘要:点击查看代码 import torch from torch import nn # 此函数初始化卷积层权重,并对输入和输出提高和缩减相应的维数 def comp_conv2d(conv2d, X): # 这里的(1,1)表示批量大小和通道数都是1 X = X.reshape((1, 1) + X.
阅读全文
摘要:点击查看代码 import torch from torch import nn from d2l import torch as d2l def corr2d(X, K): #@save """计算二维互相关运算""" h, w = K.shape Y = torch.zeros((X.shape
阅读全文
摘要:点击查看代码 import json import multiprocessing import os import torch from torch import nn from d2l import torch as d2l d2l.DATA_HUB['bert.base'] = (d2l.DA
阅读全文
摘要:点击查看代码 import os import re import torch from torch import nn from d2l import torch as d2l #@save d2l.DATA_HUB['SNLI'] = ( 'https://nlp.stanford.edu/pr
阅读全文
摘要:点击查看代码 import torch from torch import nn from d2l import torch as d2l batch_size, max_len = 512, 64 train_iter, vocab = d2l.load_data_wiki(batch_size,
阅读全文
摘要:点击查看代码 import os import random import torch from d2l import torch as d2l #@save d2l.DATA_HUB['wikitext-2'] = ( 'https://s3.amazonaws.com/research.meta
阅读全文
摘要:点击查看代码 import math import pandas as pd import torch from torch import nn from d2l import torch as d2l #@save class PositionWiseFFN(nn.Module): """基于位置
阅读全文
摘要:点击查看代码 import math import pandas as pd import torch from torch import nn from d2l import torch as d2l #@save class PositionWiseFFN(nn.Module): """基于位置
阅读全文
摘要:点击查看代码 import math import torch from torch import nn from d2l import torch as d2l # 选择缩放点积注意力作为每一个注意力头 # 𝑝𝑞=𝑝𝑘=𝑝𝑣=𝑝𝑜/ℎ # 查询、键和值的线性变换的输出数量设置为 �
阅读全文
摘要:点击查看代码 import math import torch from torch import nn from d2l import torch as d2l # 自注意力 num_hiddens, num_heads = 100, 5 attention = d2l.MultiHeadAtte
阅读全文
摘要:点击查看代码 import math import torch from torch import nn from d2l import torch as d2l # 掩蔽softmax操作 #@save def masked_softmax(X, valid_lens): """通过在最后一个轴上
阅读全文
摘要:点击查看代码 import torch from torch import nn from d2l import torch as d2l # 带有注意力机制解码器的基本接口 #@save class AttentionDecoder(d2l.Decoder): """带有注意力机制解码器的基本接口
阅读全文
摘要:点击查看代码 import torch from torch import nn from d2l import torch as d2l # 生成数据集 n_train = 50 # 训练样本数 x_train, _ = torch.sort(torch.rand(n_train) * 5) #
阅读全文