Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
戒酒的李白
2024-10-05 00:49:24 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ee739c3c811d699834c81cdd9e14ec80cf96cdc2
ee739c3c
1 parent
ba192296
Multi-head attention mechanism infrastructure and input dimension settings.
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
model_pro/MHA.py
model_pro/MHA.py
0 → 100644
View file @
ee739c3
import
torch
import
torch.nn
as
nn
class
MultiHeadAttentionLayer
(
nn
.
Module
):
def
__init__
(
self
,
embed_size
,
num_heads
):
super
(
MultiHeadAttentionLayer
,
self
)
.
__init__
()
self
.
embed_size
=
embed_size
self
.
num_heads
=
num_heads
self
.
head_dim
=
embed_size
//
num_heads
assert
(
self
.
head_dim
*
num_heads
==
embed_size
),
"Embedding size needs to be divisible by num_heads"
if
__name__
==
"__main__"
:
embed_size
=
512
num_heads
=
8
mha_layer
=
MultiHeadAttentionLayer
(
embed_size
,
num_heads
)
print
(
"Model initialized successfully."
)
...
...
Please
register
or
login
to post a comment