Method
__init__
(
self,
embed_dim: int,
n_head: int,
model_embed_dim: int,
dropout: float,
)
Source from the content-addressed store, hash-verified
| 26 | dropout: float |
| 27 | |
| 28 | def __init__( |
| 29 | self, |
| 30 | embed_dim: int, |
| 31 | n_head: int, |
| 32 | model_embed_dim: int, |
| 33 | dropout: float, |
| 34 | ): |
| 35 | super().__init__() |
| 36 | self.query = nn.Parameter(torch.randn(1, 1, embed_dim)) |
| 37 | self.multihead_attn = nn.MultiheadAttention( |
| 38 | embed_dim=embed_dim, |
| 39 | num_heads=n_head, |
| 40 | batch_first=True, |
| 41 | kdim=model_embed_dim, |
| 42 | vdim=model_embed_dim, |
| 43 | ) |
| 44 | self.layernorm = nn.LayerNorm(embed_dim) |
| 45 | self.dropout = nn.Dropout(dropout) |
| 46 | |
| 47 | def forward(self, x: torch.tensor): |
| 48 | batch_size = x.shape[0] |
Callers
nothing calls this directly
Tested by
no test coverage detected