soiz1 commited on
Commit
b5bc778
·
verified ·
1 Parent(s): d20a356

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -1,3 +1,10 @@
 
 
 
 
 
 
 
1
 
2
 
3
  import spaces
 
1
+ from torch.nn.functional import softmax
2
+
3
+ def simple_attention(query, key, value):
4
+ # Scaled dot-product attention
5
+ scores = query @ key.transpose(-2, -1) / (query.size(-1) ** 0.5)
6
+ attn_weights = softmax(scores, dim=-1)
7
+ return attn_weights @ value
8
 
9
 
10
  import spaces