<jupyter_start><jupyter_text>Why you need a good init<jupyter_code>x = torch.randn(512)
w = torch.randn(512,512)
for i in range(100): x = w @ x
x.mean(), x.std()
x = torch.randn(512)
w = torch.randn(512, 512)
for i in range(100):
    x = w @ x
    if x.std() != x.std(): break
i
x = torch.randn(512)
w = torch.randn(512, 512) * 0.01
for i in range(100):
    x = w @ x
    if x.std() == 0: break
i<jupyter_output><empty_output><jupyter_text>the magic number for scaling<jupyter_code>import math
x = torch.randn(512)
w = torch.randn(512,512) / math.sqrt(512)
for i in range(100): x = w @ x
x.mean(), x.std()
1 / math.sqrt(512)
x = torch.randn(512)
x.mean(), x.std()
mean, sqr = 0.,0.
for i in range(100):
    x = torch.randn(512)
    w = torch.randn(512,512)
    y = w @ x
    mean += y.mean().item()
    sqr += y.pow(2).mean().item()
mean/100, sqr/100
y.mean(), y.std()
mean, sqr= 0., 0.
for i in range(10000):
    x = torch.randn(1)
    w = torch.randn(1)
    y = w @ x
    mean += y.item()
    sqr += y.pow(2).item()
mean / 10000, sqr / 10000<jupyter_output><empty_output><jupyter_text>adding ReLU in the mix<jupyter_code>mean, sqr = 0.,0.
for i in range(10000):
    x = torch.randn(1)
    w = torch.randn(1)
    y = w @ x
    y = 0 if y < 0 else y.item()
    mean += y
    sqr += y ** 2
mean / 10000, sqr / 10000
mean ,sqr = 0., 0.
for i in range(100):
    x = torch.randn(512)
    w = torch.randn(512, 512)
    y = w @ x
    y = y.clamp(min=0)
    mean += y.mean().item()
    sqr += y.pow(2).mean().item()
mean / 100, sqr / 100
mean, sqr = 0., 0.
for i in range(100):
    x = torch.randn(512)
    w = torch.randn(512,512) * math.sqrt(2/512)
    y = w @ x
    y = y.clamp(min=0)
    mean += y.mean().item()
    sqr += y.pow(2).mean().item()
mean / 100, sqr / 100<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19119286510590858, 'fraction_numerical': 0.09643255295429208, 'mean_word_length': 2.708677685950413, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '516949', 'license': 'Apache-2.0', 'n_tokens_mistral': 915, 'n_tokens_neox': 788, 'n_words': 208, 'path': 'nbs/dl2/selfmade/02b_initializing.ipynb', 'repo_name': 'Hustens0hn/fastai-course-v3', 'size': '1794'}