-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
27 lines (21 loc) · 696 Bytes
/
model.py
File metadata and controls
27 lines (21 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Skipgram model definition
"""
from layers import Linear, Softmax
class Skipgram:
def __init__(self, params):
self.l1 = Linear(in_dim=params["l1"]["in_dim"], out_dim=params["l1"]["out_dim"])
self.l2 = Linear(in_dim=params["l2"]["in_dim"], out_dim=params["l2"]["out_dim"])
self.softmax = Softmax()
def forward(self, x):
x = self.l1.forward(x)
x = self.l2.forward(x)
x = self.softmax.forward(x)
return x
def backward(self, dx):
# dx = self.softmax.backward(dx)
dx = self.l2.backward(dx)
dx = self.l1.backward(dx)
def update(self, lr):
self.l1.sgd_step(lr)
self.l2.sgd_step(lr)