<jupyter_start><jupyter_text>作業 * 請參閱範例中的 hidden Layer 寫法, 完成 output Layer 的程式<jupyter_code>loss_arr = np.array([])
for i in range(epochs):
    # forward pass
    z1 = X.dot(input_hidden_weight) + input_hidden_bias
    hidden_output = sigmoid(z1)

    z2 = hidden_output.dot(hidden_output_weight) + hidden_output_bias
    output_value = sigmoid(z2)
    
    # backword pass
    loss = (2/X_sample_size)*np.sum(np.abs(y - output_value)) # parital loss respect y
    loss_arr = np.append(loss_arr, loss)

    partial_output_respect_z2 = derivatives_sigmoid(output_value) # Calculate parital output value respect z2
    partial_hidden_output_respect_z1 = derivatives_sigmoid(hidden_output) # Calculate parital hidden output respect z1

    partial_loss_respect_z2 = partial_output_respect_z2 * loss 

    partial_loss_respect_hidden_output = partial_loss_respect_z2.dot(hidden_output_weight.T)
    partial_loss_respect_z1 = partial_loss_respect_hidden_output * partial_hidden_output_respect_z1

    input_hidden_weight_gradient = X.T.dot(partial_loss_respect_z1)
    hidden_output_weight_gradient = hidden_output.T.dot(partial_loss_respect_z2)

    input_hidden_weight += input_hidden_weight_gradient * lr
    input_hidden_bias += np.sum(partial_loss_respect_z1, axis=0, keepdims=True)

    hidden_output_weight += hidden_output_weight_gradient *lr
    hidden_output_bias += np.sum(partial_loss_respect_z2, axis=0, keepdims=True)
    
    if i % 100 == 0:
        print('epochs: {}, loss: {}'.format(i, loss))
plt.plot(list(range(epochs)), loss_arr)
plt.xlabel('Number of epochs')
plt.ylabel('Loss')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09040928527794746, 'fraction_numerical': 0.014660965180207697, 'mean_word_length': 5.423529411764706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '294348', 'license': 'MIT', 'n_tokens_mistral': 604, 'n_tokens_neox': 582, 'n_words': 95, 'path': 'Day_63_HW.ipynb', 'repo_name': 'hengbinxu/ML100-Days', 'size': '1637'}