← 返回卡片

原书出处

Natural Language Processing in Action, Second Edition

Second Edition · 核验版本的摘录快照 · 导入于 2026-11-14T20:22:29.266Z

... tgt2, attention_weights = self.multihead_attn( ... tgt, memory, memory, #1 ... attn_mask=memory_mask, ... key_padding_mask=mem_key_padding_mask, ... need_weights=True) ... tgt = tgt + self.dropout2(tgt2) ... tgt = self.norm2(tgt) ... tgt2 = self.linear2( ... self.dropout(self.activation(self.linear1(tgt)))) ... tgt = tgt + self.dropout3(tgt2) ... tgt = self.norm3(tgt) ... return tgt, attention_weights #2 #1 Saves the weights from the mulithead_ attn layer #2 In addition to target outputs, returns attention weights

此预览只包含定位所需的摘录和上下文。

原书定位详情

来源:a19c7933-4eda-4176-aebd-30fe7e1ad292

正文位置:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-9.html

EPUB SHA-256:0e9a35e49ca446e322e5524e53f39fb6bee5b2b23d9cda10ef052aca770b0b36