(q_len, exponential=False, normalize=True)
| 87 | return cpe |
| 88 | |
| 89 | def Coord1dPosEncoding(q_len, exponential=False, normalize=True): |
| 90 | cpe = (2 * (torch.linspace(0, 1, q_len).reshape(-1, 1)**(.5 if exponential else 1)) - 1) |
| 91 | if normalize: |
| 92 | cpe = cpe - cpe.mean() |
| 93 | cpe = cpe / (cpe.std() * 10) |
| 94 | return cpe |
| 95 | |
| 96 | def positional_encoding(pe, learn_pe, q_len, d_model): |
| 97 | # Positional encoding |
no outgoing calls
no test coverage detected