<jupyter_start><jupyter_text>Lab 01 : Linear module -- exercise Inspecting a linear module<jupyter_code>import torch
import torch.nn as nn<jupyter_output><empty_output><jupyter_text>Make a linear module  WITHOUT bias that takes input of size 2 and return output of size 3.<jupyter_code>mod = nn.Linear(2, 3, bias=False)    # complete here
print(mod)<jupyter_output>Linear(in_features=2, out_features=3, bias=False)<jupyter_text>Print the internal parameters of the module. Try to print the bias and double check that it return you "None"<jupyter_code>print(mod.weight)
print(mod.bias)<jupyter_output>Parameter containing:
tensor([[-0.3444,  0.3183],
        [ 0.6996, -0.1079],
        [ 0.2405,  0.3568]], requires_grad=True)
None<jupyter_text>Make a vector $x=\begin{bmatrix}1\\1 \end{bmatrix}$ and feed it to your linear module. What is the output?<jupyter_code>x= torch.Tensor([1, 1]) # complete here  
print(x)
y= mod(x) # complete here  
print(y)<jupyter_output>tensor([1., 1.])
tensor([-0.0262,  0.5917,  0.5973], grad_fn=<SqueezeBackward3>)<jupyter_text>Change the internal parameters of your module so that the weights become $W=\begin{bmatrix}1&2 \\ 3&4 \\ 5&6\end{bmatrix}$. You need to write 6 lines, one per entry to be changed.<jupyter_code>with torch.no_grad():
    # complete here  
    mod.weight[0, 0] = 1
    # complete here  
    mod.weight[0, 1] = 2
    # complete here  
    mod.weight[1, 0] = 3
    # complete here  
    mod.weight[1, 1] = 4
    # complete here  
    mod.weight[2, 0] = 5
    # complete here  
    mod.weight[2, 1] = 6
    print(mod.weight)<jupyter_output>Parameter containing:
tensor([[1., 2.],
        [3., 4.],
        [5., 6.]], requires_grad=True)<jupyter_text>Feed the vector x to your module with updated parameters. What is the output?<jupyter_code>y= mod(x) # complete here  
print(y)<jupyter_output>tensor([ 3.,  7., 11.], grad_fn=<SqueezeBackward3>)
{'fraction_non_alphanumeric': 0.1336842105263158, 'fraction_numerical': 0.05052631578947368, 'mean_word_length': 4.096514745308311, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '415306', 'license': 'MIT', 'n_tokens_mistral': 745, 'n_tokens_neox': 684, 'n_words': 185, 'path': 'codes/labs_lecture03/lab01_linear_module/linear_module_exercise.ipynb', 'repo_name': 'HolmesJJ/CS4243_2022', 'size': '1900'}