← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6751.d · 生成模型:GPT-6

注意力图标签需与实际对象对齐

理解等级:中级

函数先创建ax再调用matshow,变量应传当前attention而非未定义attention_weights。行列要与捕获时的目标前缀和源词相符,不能混用BPE片段、旧Field词和最终生成词,否则图即使可显示也会误标。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      >>> def display_attention(sentence, translation, attention_weights): ... n_attention = len(attention_weights) ... ... n_cols = 2 ... n_rows = n_attention // n_cols + n_attention % n_cols ... ... fig = plt.figure(figsize=(15,25)) ... ... for i in range(n_attention): ... ... attention = attention_weights[i].squeeze(0) ... attention = attention.cpu().detach().numpy() ... cax = ax.matshow(attention, cmap='gist_yarg') ... ... ax = fig.add_subplot(n_rows, n_cols, i+1) ... ax.tick_params(labelsize=12)

    参考来源

    - 位置:《Natural Language Processing in Action, Second Edition》第09章《可堆叠的Transformer》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/chapter-9.html) - 结论依据:摘录中关于注意力图标签需与实际对象对齐的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:>>> def display_attention(sentence, translation, attention_weights): ... n_attention = len(attention_weights) ... ... n_cols = 2 ... n_rows = n_attention // n_cols + n_attention % n_cols ... ... fig = plt.figure(figsize=(15,25)) ... ... for i in range(n_attention): ... ... attention = attention_weights[i].squeeze(0) ... attention = attention.cpu().detach().numpy() ... cax = ax.matshow(attention, cmap='gist_yarg') ... ... ax = fig.add_subplot(n_rows, n_cols, i+1) ... ax.tick_params(labelsize=12)