MCPcopy Create free account
hub / github.com/geekcomputers/Python / __init__

Method __init__

ML/src/python/neuralforge/nn/attention.py:8–19  ·  view source on GitHub ↗
(self, embed_dim, num_heads, dropout=0.1, bias=True)

Source from the content-addressed store, hash-verified

6
7class MultiHeadAttention(nn.Module):
8 def __init__(self, embed_dim, num_heads, dropout=0.1, bias=True):
9 super().__init__()
10 assert embed_dim % num_heads == 0
11
12 self.embed_dim = embed_dim
13 self.num_heads = num_heads
14 self.head_dim = embed_dim // num_heads
15 self.scale = self.head_dim ** -0.5
16
17 self.qkv = nn.Linear(embed_dim, embed_dim * 3, bias=bias)
18 self.proj = nn.Linear(embed_dim, embed_dim, bias=bias)
19 self.dropout = nn.Dropout(dropout)
20
21 def forward(self, x, mask=None):
22 B, N, C = x.shape

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected