NLP - Sequence Models for NLPWhich Python code snippet correctly computes attention weights using the dot product of query Q and keys K before applying softmax?Ascores = np.dot(K, Q) weights = np.exp(scores) * np.sum(np.exp(scores))Bscores = np.dot(Q.T, K) weights = np.sum(np.exp(scores))Cscores = np.dot(Q, K.T) weights = np.exp(scores) / np.sum(np.exp(scores))Dscores = np.dot(Q, K) weights = np.exp(scores) / np.exp(np.sum(scores))Check Answer
Step-by-Step SolutionSolution:Step 1: Compute dot productAttention scores are computed as Q multiplied by K transposed.Step 2: Apply softmaxSoftmax normalizes exponentiated scores by dividing by their sum.Final Answer:scores = np.dot(Q, K.T)\nweights = np.exp(scores) / np.sum(np.exp(scores)) -> Option CQuick Check:Dot product with K.T then softmax [OK]Quick Trick: Dot Q with K.T then softmax normalize [OK]Common Mistakes:MISTAKESNot transposing K before dot productIncorrect normalization in softmaxUsing multiplication instead of division for softmax
Master "Sequence Models for NLP" in NLP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepModelTryChallengeExperimentRecallMetrics
More NLP Quizzes Sentiment Analysis Advanced - Aspect-based sentiment analysis - Quiz 5medium Sequence Models for NLP - Embedding layer usage - Quiz 13medium Sequence Models for NLP - GRU for text - Quiz 2easy Sequence Models for NLP - Padding and sequence length - Quiz 7medium Text Similarity and Search - Semantic similarity with embeddings - Quiz 8hard Text Similarity and Search - Semantic similarity with embeddings - Quiz 11easy Topic Modeling - Choosing number of topics - Quiz 10hard Topic Modeling - LDA with scikit-learn - Quiz 8hard Word Embeddings - Pre-trained embedding usage - Quiz 11easy Word Embeddings - GloVe embeddings - Quiz 13medium