= PositionalEncoding(1000, 512).detach().cpu().numpy()
pe ='viridis')
plt.pcolormesh(pe, cmap'PositionalEncoding')
plt.title(
plt.colorbar()
plt.show()min(), pe.max(), pe.shape pe.mean(), pe.std(), pe.
Positional encoders
This includes some variations of positional encoders used with Transformers.
Imports
Positional encoders
PositionalEncoding
PositionalEncoding (q_len, d_model, normalize=True)
Coord2dPosEncoding
Coord2dPosEncoding (q_len, d_model, exponential=False, normalize=True, eps=0.001, verbose=False)
= Coord2dPosEncoding(1000, 512, exponential=True, normalize=True).cpu().numpy()
cpe ='viridis')
plt.pcolormesh(cpe, cmap'Coord2dPosEncoding')
plt.title(
plt.colorbar()
plt.show()0))
plt.plot(cpe.mean(
plt.show()1))
plt.plot(cpe.mean(
plt.show()min(), cpe.max() cpe.mean(), cpe.std(), cpe.
Coord1dPosEncoding
Coord1dPosEncoding (q_len, exponential=False, normalize=True)
= Coord1dPosEncoding(1000, exponential=True, normalize=True).detach().cpu().numpy()
cpe ='viridis')
plt.pcolormesh(cpe, cmap'Coord1dPosEncoding')
plt.title(
plt.colorbar()
plt.show()1))
plt.plot(cpe.mean(
plt.show()min(), cpe.max(), cpe.shape cpe.mean(), cpe.std(), cpe.
= Coord1dPosEncoding(1000, exponential=True, normalize=True).detach().cpu().numpy()
cpe ='viridis')
plt.pcolormesh(cpe, cmap'Coord1dPosEncoding')
plt.title(
plt.colorbar()
plt.show()1))
plt.plot(cpe.mean(
plt.show()min(), cpe.max() cpe.mean(), cpe.std(), cpe.