From d17e47421b26e8fb3c25334e3ccabd9e2f93e62e Mon Sep 17 00:00:00 2001 From: udlbook <110402648+udlbook@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:01:38 -0400 Subject: [PATCH] Improved implementation of softmax_cols() --- Notebooks/Chap12/12_2_Multihead_Self_Attention.ipynb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Notebooks/Chap12/12_2_Multihead_Self_Attention.ipynb b/Notebooks/Chap12/12_2_Multihead_Self_Attention.ipynb index 7e9b0b3..ebbeb68 100644 --- a/Notebooks/Chap12/12_2_Multihead_Self_Attention.ipynb +++ b/Notebooks/Chap12/12_2_Multihead_Self_Attention.ipynb @@ -4,7 +4,6 @@ "metadata": { "colab": { "provenance": [], - "authorship_tag": "ABX9TyMSk8qTqDYqFnRJVZKlsue0", "include_colab_link": true }, "kernelspec": { @@ -147,9 +146,7 @@ " exp_values = np.exp(data_in) ;\n", " # Sum over columns\n", " denom = np.sum(exp_values, axis = 0);\n", - " # Replicate denominator to N rows\n", - " denom = np.matmul(np.ones((data_in.shape[0],1)), denom[np.newaxis,:])\n", - " # Compute softmax\n", + " # Compute softmax (numpy broadcasts denominator to all rows automatically)\n", " softmax = exp_values / denom\n", " # return the answer\n", " return softmax"