Logistic Regression and Text Classification
Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4
6 cards in “4.14 Regularization” · whole deck
4.14 Regularization
- What is overfitting in logistic regression?Weights fit the training data too perfectly, e.g. huge weights for features that happen to occur in only one class, modeling noise that accidentally correlates with the class, so the model generalizes poorly.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4, §4.14, p. 121
- How does regularization prevent overfitting?It adds a penalty term \(R(\theta)\) for large weights: \(\hat{\theta} = \arg\max_\theta \sum_i \log P(y^{(i)} \mid x^{(i)}) - \alpha R(\theta)\). A solution using smaller weights is preferred over one that fits slightly better with large weights; \(\alpha\) sets the strength.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4, §4.14, pp. 121–122
- Is the bias term regularized?Normally not: it acts as a threshold that handles uncentered data and class priors.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4, §4.14, p. 122
- What are L2 and L1 regularization?L2 (ridge): \(R(\theta) = \|\theta\|_2^2 = \sum_j \theta_j^2\), the squared Euclidean norm. L1 (lasso): \(R(\theta) = \|\theta\|_1 = \sum_j |\theta_j|\), the Manhattan distance.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4, §4.14, p. 122
- How do the solutions preferred by L1 and L2 regularization differ, and which is easier to optimize?L2 prefers many small weights and is easier to optimize (derivative \(2\theta\)). L1 prefers sparse solutions with many weights exactly zero (fewer features) but its derivative is discontinuous at 0.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4, §4.14, p. 122
- What are the Bayesian interpretations of L1 and L2 regularization?L1 corresponds to a Laplace prior on the weights; L2 to a Gaussian prior with mean 0, i.e. a preference for weights near 0.
- Jurafsky & Martin, Speech and Language Processing, 3rd ed. draft, ch. 4, §4.14, p. 123
Source
- Daniel Jurafsky and James H. Martin. Speech and Language Processing. 3rd edition (draft). https://web.stanford.edu/~jurafsky/slp3/