Loading...
Implement a transformer feed-forward network (FFN).
The FFN applies two linear transformations with a ReLU activation in between: FFN(x)=ReLU(xW1+b1)W2+b2
For simplicity, use no biases (b1=0, b2=0). Use numpy seed 42 to generate W1 and W2.
Input:
Output: Output vector of dimension d, rounded to 4 decimal places.
Generate weights: np.random.seed(42), W1 = np.random.randn(d, d_ff) * 0.1, W2 = np.random.randn(d_ff, d) * 0.1
2 4 1.0 -1.0
0.0107 -0.0510
np.random.seed(42), with W1=np.random.randn(2,4)∗0.1 and W2=np.random.randn(4,2)∗0.1.