Natural Language Processing · TEE · papers

Q1d · Sentiment with logistic regression

2022-11-22 · final · recovered AI paper

Previous examination · complete worked answers

Question. Explain sentiment analysis using logistic regression with an example. [5 marks]

Answer

Binary logistic regression maps text features x to a probability:

z=w^Tx+b,\qquad P(y=1\mid x)=\sigma(z)=\frac{1}{1+e^{-z}}LaTeX: z=w^Tx+b,\qquad P(y=1\mid x)=\sigma(z)=\frac{1}{1+e^{-z}}

Use positive-word count and negative-word count as an illustrative feature vector. With x=(2,1), w=(1,−1), b=0: z=1×2+(−1)×1=1; P(positive)=1/(1+e⁻¹)=0.731059. A declared 0.5 threshold predicts positive. Fit weights from labelled reviews by minimizing cross-entropy; the hand-chosen weights here only illustrate the computation.

Labelled reviews → Tokenize / vectorize → Fit logistic weights → Probability → Threshold / class