摘要: 解码器在做多头注意力的掩码时候, 得到的相似度矩阵 相似度矩阵A A = Q@KT : [batch_size,n_head,seq_len,seq_len] 第一个为Q的seq_len,第二个为K的seq_len 对A做因果掩码 生成下三角掩码矩阵: M: [seq_len,seq_len] 将该 阅读全文
posted @ 2025-03-09 23:39 xiezhengcai 阅读(162) 评论(0) 推荐(0)
摘要: 通用部分 批次数量: batch_size 句子长度:seq_len 模型维度:d_model 多头头数:n_head 词典总数:vocab_num 输入时: input_ids : [batch_size,seq_len] input_mask: [batch_size,seq_len] targ 阅读全文
posted @ 2025-03-09 23:22 xiezhengcai 阅读(77) 评论(0) 推荐(0)
摘要: # 假设 logits 形状 [1,3,5], logits = torch.randn(1, 3, 5) targets = torch.tensor([[1, 2, 1, 1, 2]]) # 形状为 [1,5] loss_fn = nn.CrossEntropyLoss() loss = los 阅读全文
posted @ 2025-03-09 11:48 xiezhengcai 阅读(13) 评论(0) 推荐(0)