Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Created August 10, 2023 13:19
Show Gist options
  • Select an option

  • Save pythonlessons/9ce3b86715db76e24658c1faac324577 to your computer and use it in GitHub Desktop.

Select an option

Save pythonlessons/9ce3b86715db76e24658c1faac324577 to your computer and use it in GitHub Desktop.
transformers_introduction
pos_encoding /= tf.norm(pos_encoding, axis=1, keepdims=True)
p = pos_encoding[1000]
dots = tf.einsum('pd,d->p', pos_encoding, p).numpy()
plt.subplot(2, 1, 1)
plt.plot(dots)
plt.ylim([0, 1])
plt.plot([950, 950, float('nan'), 1050, 1050], [0, 1, float('nan'), 0, 1], color='k', label='Zoom')
plt.legend()
plt.subplot(2, 1, 2)
plt.plot(range(len(dots)), dots)
plt.xlim([950, 1050])
plt.ylim([0, 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment