Implementation of Log Softmax Function

Neural Units & Activations DS practice problem on Onlearn.

Difficulty: easy.

Topics: Understanding Implementation of Log Softmax Function, Log-Sum-Exp Trick, Softmax Normalization, Numerical Underflow Prevention, Broadcasting Rules, Negative Log-Likelihood, Numerical Analysis, Probability Theory, Deep Learning Foundations, Computational Linear Algebra, Optimization Theory, Activation Functions, Floating Point Arithmetic, Vectorized Operations, Loss Function Formulation, Log-Space Computation.

In machine learning and statistics, the softmax function is a generalization of the logistic function that converts a vector of scores into probabilities. The log softmax function is the logarithm of the softmax function, and it is often used for numerical stability when computing the softmax of large numbers. Given a 1D numpy array of scores, implement a Python function to compute the log softmax of the array.