text stringlengths 1 7.76k | source stringlengths 17 81 |
|---|---|
Natural Language Processing Jacob Eisenstein November 13, 2018 | nlp_Page_1_Chunk1 |
Contents Contents 1 Preface i Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i How to use this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii 1 Introduction 1 1.1 Natural language processing and its neighbors . . . . . . . . . . . . . . . . . 1 1.2 Three th... | nlp_Page_3_Chunk2 |
. . . 35 1 | nlp_Page_3_Chunk3 |
2 CONTENTS 2.5.1 Regularization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 2.5.2 Gradients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.6 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 2.6.1 Batch optimization . . . . . . . . .... | nlp_Page_4_Chunk4 |
. . . . . 62 4 Linguistic applications of classification 69 4.1 Sentiment and opinion analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 69 4.1.1 Related problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 4.1.2 Alternative approaches to sentiment analysis . . . . . . . . . . . . . . 72 4.2... | nlp_Page_4_Chunk5 |
CONTENTS 3 4.5.1 Metadata as labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 4.5.2 Labeling data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 5 Learning without supervision 95 5.1 Unsupervised learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 5.1.1 K-mea... | nlp_Page_5_Chunk6 |
. . . . . . . . . . . . . . . 129 6.2.1 Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.2.2 Discounting and backoff . . . . . . . . . . . . . . . . . . . . . . . . . . 130 6.2.3 *Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 6.2.4 *Kneser-Ney smoot... | nlp_Page_5_Chunk7 |
4 CONTENTS 7 Sequence labeling 145 7.1 Sequence labeling as classification . . . . . . . . . . . . . . . . . . . . . . . . 145 7.2 Sequence labeling as structure prediction . . . . . . . . . . . . . . . . . . . . 147 7.3 The Viterbi algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 7.3.1 Exam... | nlp_Page_6_Chunk8 |
. . . . . . . . . . . . . 180 8.2 Morphosyntactic Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 8.3 Named Entity Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 8.4 Tokenization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 8.5 Code swit... | nlp_Page_6_Chunk9 |
CONTENTS 5 9.2.2 Natural language syntax as a context-free language . . . . . . . . . . 211 9.2.3 A phrase-structure grammar for English . . . . . . . . . . . . . . . . 213 9.2.4 Grammatical ambiguity . . . . . . . . . . . . . . . . . . . . . . . . . . 218 9.3 *Mildly context-sensitive languages . . . . . . . . . . . .... | nlp_Page_7_Chunk10 |
. . . . . . . . . . 244 10.5.3 *Refinement grammars . . . . . . . . . . . . . . . . . . . . . . . . . . 248 10.6 Beyond context-free parsing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 10.6.1 Reranking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 10.6.2 Transition-based parsing... | nlp_Page_7_Chunk11 |
6 CONTENTS 11.3 Transition-based dependency parsing . . . . . . . . . . . . . . . . . . . . . . 268 11.3.1 Transition systems for dependency parsing . . . . . . . . . . . . . . . 269 11.3.2 Scoring functions for transition-based parsers . . . . . . . . . . . . . 273 11.3.3 Learning to parse . . . . . . . . . . . . . . ... | nlp_Page_8_Chunk12 |
. . . . . . 312 13.2.1 Semantic role labeling as classification . . . . . . . . . . . . . . . . . . 312 13.2.2 Semantic role labeling as constrained optimization . . . . . . . . . . 315 13.2.3 Neural semantic role labeling . . . . . . . . . . . . . . . . . . . . . . . 317 13.3 Abstract Meaning Representation . . . . . .... | nlp_Page_8_Chunk13 |
CONTENTS 7 14.4 Brown clusters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 14.5 Neural word embeddings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334 14.5.1 Continuous bag-of-words (CBOW) . . . . . . . . . . . . . . . . . . . . 334 14.5.2 Skipgrams . . . . . . . . . . . . ... | nlp_Page_9_Chunk14 |
. . . 358 15.2.1 Mention-pair models . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 15.2.2 Mention-ranking models . . . . . . . . . . . . . . . . . . . . . . . . . 360 15.2.3 Transitive closure in mention-based models . . . . . . . . . . . . . . . 361 15.2.4 Entity-based models . . . . . . . . . . . . . . ... | nlp_Page_9_Chunk15 |
8 CONTENTS 16.2.3 *Formal semantics beyond the sentence level . . . . . . . . . . . . . . 384 16.3 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 16.3.1 Shallow discourse relations . . . . . . . . . . . . . . . . . . . . . . . . 385 16.3.2 Hierarchical discourse relations . ... | nlp_Page_10_Chunk16 |
. . . . . . . . . . . . . . . . . . . 433 18.1.2 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435 18.2 Statistical machine translation . . . . . . . . . . . . . . . . . . . . . . . . . . . 436 18.2.1 Statistical translation modeling . . . . . . . . . . . . . . . . . . . . . . 437 18.2.... | nlp_Page_10_Chunk17 |
CONTENTS 9 19 Text generation 457 19.1 Data-to-text generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 19.1.1 Latent data-to-text alignment . . . . . . . . . . . . . . . . . . . . . . . 459 19.1.2 Neural data-to-text generation . . . . . . . . . . . . . . . . . . . . . . 460 19.2 Text-to-text ... | nlp_Page_11_Chunk18 |
Preface The goal of this text is focus on a core subset of the natural language processing, unified by the concepts of learning and search. A remarkable number of problems in natural language processing can be solved by a compact set of methods: Search. Viterbi, CKY, minimum spanning tree, shift-reduce, integer linear p... | nlp_Page_13_Chunk19 |
ii PREFACE a more advanced and comprehensive discussion of the same material, the classic reference is Hastie et al. (2009). Linguistics. This book assumes no formal training in linguistics, aside from elementary concepts likes nouns and verbs, which you have probably encountered in the study of English grammar. Ideas ... | nlp_Page_14_Chunk20 |
iii translation, and text generation. Each of these applications merits a textbook length treatment of its own (Koehn, 2009; Grishman, 2012; Reiter and Dale, 2000); the chap- ters here explain some of the most well known systems using the formalisms and methods built up earlier in the book, while introducing methods su... | nlp_Page_15_Chunk21 |
iv PREFACE These include: Parminder Bhatia, Kimberly Caras, Jiahao Cai, Justin Chen, Rodolfo Del- monte, Murtaza Dhuliawala, Yantao Du, Barbara Eisenstein, Luiz C. F. Ribeiro, Chris Gu, Joshua Killingsworth, Jonathan May, Taha Merghani, Gus Monod, Raghavendra Murali, Nidish Nair, Brendan O’Connor, Dan Oneata, Brandon P... | nlp_Page_16_Chunk22 |
Notation As a general rule, words, word counts, and other types of observations are indicated with Roman letters (a, b, c); parameters are indicated with Greek letters (α, β, θ). Vectors are indicated with bold script for both random variables x and parameters θ. Other useful notations are indicated in the table below.... | nlp_Page_17_Chunk23 |
vi PREFACE Text datasets wm word token at position m N number of training instances M length of a sequence (of words or tags) V number of words in vocabulary y(i) the true label for instance i ˆy a predicted label Y the set of all possible labels K number of possible labels K = |Y| □ the start token ■ the stop token y(... | nlp_Page_18_Chunk24 |
Chapter 1 Introduction Natural language processing is the set of methods for making human language accessi- ble to computers. In the past decade, natural language processing has become embedded in our daily lives: automatic machine translation is ubiquitous on the web and in so- cial media; text classification keeps our... | nlp_Page_19_Chunk25 |
2 CHAPTER 1. INTRODUCTION natural language processing is focused on the design and analysis of computational al- gorithms and representations for processing natural human language. The goal of natu- ral language processing is to provide new computational capabilities around human lan- guage: for example, extracting inf... | nlp_Page_20_Chunk26 |
1.1. NATURAL LANGUAGE PROCESSING AND ITS NEIGHBORS 3 phrase, which is conjoined with the prepositional phrase of the bigness of a human head. The interpretation would be different if instead, huge globular pieces were con- joined with the prepositional phrase of the whale of the bigness of a human head — implying a dis... | nlp_Page_21_Chunk27 |
4 CHAPTER 1. INTRODUCTION difficult for anyone to maintain expertise across the entire field. Still, recent work has demonstrated interesting connections between natural language processing and other ar- eas of AI, including computer vision (e.g., Antol et al., 2015) and game playing (e.g., Branavan et al., 2009). The do... | nlp_Page_22_Chunk28 |
1.1. NATURAL LANGUAGE PROCESSING AND ITS NEIGHBORS 5 has been the purview of computer scientists. For this reason, the extent of interaction between these two disciplines is less than it might otherwise be. Ethics As machine learning and artificial intelligence become increasingly ubiquitous, it is crucial to understand... | nlp_Page_23_Chunk29 |
6 CHAPTER 1. INTRODUCTION 1.2 Three themes in natural language processing Natural language processing covers a diverse range of tasks, methods, and linguistic phe- nomena. But despite the apparent incommensurability between, say, the summarization of scientific articles (§ 16.3.4) and the identification of suffix patterns... | nlp_Page_24_Chunk30 |
1.2. THREE THEMES IN NATURAL LANGUAGE PROCESSING 7 learning. For example, in a task like search, it may be useful to identify each word’s stem, so that a system can more easily generalize across related terms such as whale, whales, whalers, and whaling. (This issue is relatively benign in English, as compared to the ma... | nlp_Page_25_Chunk31 |
8 CHAPTER 1. INTRODUCTION • Ψ is a scoring function (also called the model), which maps from the set X × Y to the real numbers; • θ is a vector of parameters for Ψ; • ˆy is the predicted output, which is chosen to maximize the scoring function. This basic structure can be applied to a huge range of problems. For exampl... | nlp_Page_26_Chunk32 |
1.2. THREE THEMES IN NATURAL LANGUAGE PROCESSING 9 When a model is capable of making subtle linguistic distinctions, it is said to be ex- pressive. Expressiveness is often traded off against efficiency of search and learning. For example, a word-to-word translation model makes search and learning easy, but it is not exp... | nlp_Page_27_Chunk33 |
10 CHAPTER 1. INTRODUCTION Difficulties in ontology construction have led some linguists to argue that there is no task- independent way to partition up word meanings (Kilgarriff, 1997). Some problems are easier. Each member in a group of journalists is a journalist: the -s suffix distinguishes the plural meaning from th... | nlp_Page_28_Chunk34 |
Part I Learning 11 | nlp_Page_29_Chunk35 |
Chapter 2 Linear text classification We begin with the problem of text classification: given a text document, assign it a dis- crete label y ∈Y, where Y is the set of possible labels. Text classification has many ap- plications, from spam filtering to the analysis of electronic health records. This chapter describes some o... | nlp_Page_31_Chunk36 |
14 CHAPTER 2. LINEAR TEXT CLASSIFICATION To predict a label from a bag-of-words, we can assign a score to each word in the vo- cabulary, measuring the compatibility with the label. For example, for the label FICTION, we might assign a positive score to the word whale, and a negative score to the word molybdenum. These ... | nlp_Page_32_Chunk37 |
2.1. THE BAG OF WORDS 15 vector that is mostly zeros, with a column vector of word counts x inserted in a location that depends on the specific label y. This arrangement is shown in Figure 2.1. The notation may seem awkward at first, but it generalizes to an impressive range of learning settings, particularly structure p... | nlp_Page_33_Chunk38 |
16 CHAPTER 2. LINEAR TEXT CLASSIFICATION It was the best of times, it was the worst of times... x it was the best worst times 1 2 of 2 2 2 2 1 0 ... 0 0 ... 0 ... 0 ... 0 ... 0 ... 0 ... 0 ... 0 1 x 0 0 0 f(x ,y=News) y=Fiction y=News y=Gossip y=Sports Bag of words Feature vector Original text <OFFSET> aardvark zyxt Fi... | nlp_Page_34_Chunk39 |
2.2. NA¨IVE BAYES 17 2.2 Na¨ıve Bayes The joint probability of a bag of words x and its true label y is written p(x, y). Suppose we have a dataset of N labeled instances, {(x(i), y(i))}N i=1, which we assume are indepen- dent and identically distributed (IID) (see § A.3). Then the joint probability of the entire datase... | nlp_Page_35_Chunk40 |
18 CHAPTER 2. LINEAR TEXT CLASSIFICATION Algorithm 1 Generative process for the Na¨ıve Bayes classification model for Instance i ∈{1, 2, . . . , N} do: Draw the label y(i) ∼Categorical(µ); Draw the word counts x(i) | y(i) ∼Multinomial(φy(i)). distributions over the label y(i) and the text x(i) (conditioned on y(i)) are ... | nlp_Page_36_Chunk41 |
2.2. NA¨IVE BAYES 19 As in the categorical distribution, the parameter φj can be interpreted as a probabil- ity: specifically, the probability that any given token in the document is the word j. The multinomial distribution involves a product over words, with each term in the product equal to the probability φj, exponen... | nlp_Page_37_Chunk42 |
20 CHAPTER 2. LINEAR TEXT CLASSIFICATION Algorithm 2 Alternative generative process for the Na¨ıve Bayes classification model for Instance i ∈{1, 2, . . . , N} do: Draw the label y(i) ∼Categorical(µ); for Token m ∈{1, 2, . . . , Mi} do: Draw the token w(i) m | y(i) ∼Categorical(φy(i)). Sometimes it is useful to think of... | nlp_Page_38_Chunk43 |
2.2. NA¨IVE BAYES 21 2.2.3 Estimation The parameters of the categorical and multinomial distributions have a simple interpre- tation: they are vectors of expected frequencies for each possible event. Based on this interpretation, it is tempting to set the parameters empirically, φy,j = count(y, j) PV j′=1 count(y, j′) ... | nlp_Page_39_Chunk44 |
22 CHAPTER 2. LINEAR TEXT CLASSIFICATION The solution is obtained by setting each element in this vector of derivatives equal to zero, λφy,j = X i:y(i)=y x(i) j [2.27] φy,j ∝ X i:y(i)=y x(i) j = N X i=1 δ y(i) = y x(i) j = count(y, j), [2.28] where δ | nlp_Page_40_Chunk45 |
2.2. NA¨IVE BAYES 23 Smoothing reduces variance, but moves us away from the maximum likelihood esti- mate: it imposes a bias. In this case, the bias points towards uniform probabilities. Ma- chine learning theory shows that errors on heldout data can be attributed to the sum of bias and variance (Mohri et al., 2012). I... | nlp_Page_41_Chunk46 |
24 CHAPTER 2. LINEAR TEXT CLASSIFICATION the classifier design, and test set accuracy will diverge from accuracy on truly unseen data. Because annotated data is expensive, this ideal can be hard to follow in practice, and many test sets have been used for decades. But in some high-impact applications like machine transl... | nlp_Page_42_Chunk47 |
2.3. DISCRIMINATIVE LEARNING 25 To test the quality of the approximation, we can manipulate the left-hand side by applying the chain rule, Pr(word = unfit, prefix = un- | y) = Pr(prefix = un- | word = unfit, y) [2.31] × Pr(word = unfit | y) [2.32] But Pr(prefix = un- | word = unfit, y) = 1, since un- is guaranteed to be the p... | nlp_Page_43_Chunk48 |
26 CHAPTER 2. LINEAR TEXT CLASSIFICATION Algorithm 3 Perceptron learning algorithm 1: procedure PERCEPTRON(x(1:N), y(1:N)) 2: t ←0 3: θ(0) ←0 4: repeat 5: t ←t + 1 6: Select an instance i 7: ˆy ←argmaxy θ(t−1) · f(x(i), y) 8: if ˆy ̸= y(i) then 9: θ(t) ←θ(t−1) + f(x(i), y(i)) −f(x(i), ˆy) 10: else 11: θ(t) ←θ(t−1) 12: ... | nlp_Page_44_Chunk49 |
2.4. LOSS FUNCTIONS AND LARGE-MARGIN CLASSIFICATION 27 features. For these problems, it is very likely that the training data is indeed separable. And even if the dataset is not separable, it is still possible to place an upper bound on the number of errors that the perceptron algorithm will make (Freund and Schapire, ... | nlp_Page_45_Chunk50 |
28 CHAPTER 2. LINEAR TEXT CLASSIFICATION Algorithm 4 Averaged perceptron learning algorithm 1: procedure AVG-PERCEPTRON(x(1:N), y(1:N)) 2: t ←0 3: θ(0) ←0 4: repeat 5: t ←t + 1 6: Select an instance i 7: ˆy ←argmaxy θ(t−1) · f(x(i), y) 8: if ˆy ̸= y(i) then 9: θ(t) ←θ(t−1) + f(x(i), y(i)) −f(x(i), ˆy) 10: else 11: θ(t)... | nlp_Page_46_Chunk51 |
2.4. LOSS FUNCTIONS AND LARGE-MARGIN CLASSIFICATION 29 The zero-one loss is zero if the instance is correctly classified, and one otherwise. The sum of zero-one losses is proportional to the error rate of the classifier on the training data. Since a low error rate is often the ultimate goal of classification, this may see... | nlp_Page_47_Chunk52 |
30 CHAPTER 2. LINEAR TEXT CLASSIFICATION a subgradient of the function g at u0 iff g(u) −g(u0) ≥v · (u −u0) for all u. Graphically, this defines the set of hyperplanes that include g(u0) and do not intersect g at any other point. As we approach the hinge point from the left, the gradient is f(x, ˆy)−f(x, y); as we appro... | nlp_Page_48_Chunk53 |
2.4. LOSS FUNCTIONS AND LARGE-MARGIN CLASSIFICATION 31 −2 −1 0 1 2 θ · f(x(i), y(i)) −θ · f(x(i), ˆy) 0 1 2 3 loss 0/1 loss margin loss logistic loss Figure 2.2: Margin, zero-one, and logistic loss functions. into a loss function, ℓMARGIN(θ; x(i), y(i)) = ( 0, γ(θ; x(i), y(i)) ≥1, 1 −γ(θ; x(i), y(i)), otherwise [2.44] ... | nlp_Page_49_Chunk54 |
32 CHAPTER 2. LINEAR TEXT CLASSIFICATION following classification rule: ˆy = argmax y∈Y θ · f(x(i), y) + c(y(i), y) [2.47] θ(t) ←(1 −λ)θ(t−1) + f(x(i), y(i)) −f(x(i), ˆy) [2.48] This update is similar in form to the perceptron, with two key differences. • Rather than selecting the label ˆy that maximizes the score of th... | nlp_Page_50_Chunk55 |
2.4. LOSS FUNCTIONS AND LARGE-MARGIN CLASSIFICATION 33 functional margin geometric margin Figure 2.3: Functional and geometric margins for a binary classification problem. All separators that satisfy the margin constraint are shown. The separator with the largest geometric margin is shown in bold. to the constraint that... | nlp_Page_51_Chunk56 |
34 CHAPTER 2. LINEAR TEXT CLASSIFICATION lem: min θ . 1 2||θ||2 2 s.t. γ(θ; x(i), y(i)) ≥1, ∀i. [2.50] This problem is a quadratic program: the objective is a quadratic function of the pa- rameters, and the constraints are all linear inequalities. One solution to this problem is to incorporate the constraints through L... | nlp_Page_52_Chunk57 |
2.5. LOGISTIC REGRESSION 35 where each ξi has been substituted by the right-hand side of Equation 2.52, and the factor of C on the slack variables has been replaced by an equivalent factor of λ = 1 C on the norm of the weights. Equation 2.53 can be rewritten by expanding the margin, min θ λ 2 ||θ||2 2 + N X i=1 max y... | nlp_Page_53_Chunk58 |
36 CHAPTER 2. LINEAR TEXT CLASSIFICATION Given a dataset D = {(x(i), y(i))}N i=1, the weights θ are estimated by maximum condi- tional likelihood, log p(y(1:N) | x(1:N); θ) = N X i=1 log p(y(i) | x(i); θ) [2.57] = N X i=1 θ · f(x(i), y(i)) −log X y′∈Y exp θ · f(x(i), y′) . [2.58] The final line is obtained by pluggi... | nlp_Page_54_Chunk59 |
2.6. OPTIMIZATION 37 2.5.2 Gradients Logistic loss is minimized by optimization along the gradient. Specific algorithms are de- scribed in the next section, but first let’s compute the gradient with respect to the logistic loss of a single example: ℓLOGREG = −θ · f(x(i), y(i)) + log X y′∈Y exp θ · f(x(i), y′) [2.61] ... | nlp_Page_55_Chunk60 |
38 CHAPTER 2. LINEAR TEXT CLASSIFICATION • In the support vector machine, the objective is the regularized margin loss, LSVM = λ 2 ||θ||2 2 + N X i=1 (max y∈Y (θ · f(x(i), y) + c(y(i), y)) −θ · f(x(i), y(i)))+, [2.68] There is no closed-form solution, but the objective is convex. The perceptron algo- rithm minimizes a ... | nlp_Page_56_Chunk61 |
2.6. OPTIMIZATION 39 In practice, gradient descent can be slow to converge, as the gradient can become infinitesimally small. Faster convergence can be obtained by second-order Newton opti- mization, which incorporates the inverse of the Hessian matrix, Hi,j = ∂2L ∂θi∂θj [2.71] The size of the Hessian matrix is quadrati... | nlp_Page_57_Chunk62 |
40 CHAPTER 2. LINEAR TEXT CLASSIFICATION Algorithm 5 Generalized gradient descent. The function BATCHER partitions the train- ing set into B batches such that each instance appears in exactly one batch. In gradient descent, B = 1; in stochastic gradient descent, B = N; in minibatch stochastic gradient descent, 1 < B < ... | nlp_Page_58_Chunk63 |
2.7. *ADDITIONAL TOPICS IN CLASSIFICATION 41 2.7 *Additional topics in classification This section presents some additional topics in classification that are particularly relevant for natural language processing, especially for understanding the research literature. 2.7.1 Feature selection by regularization In logistic r... | nlp_Page_59_Chunk64 |
42 CHAPTER 2. LINEAR TEXT CLASSIFICATION inner product through a logistic function, σ(a) ≜ exp(a) 1 + exp(a) = (1 + exp(−a))−1 [2.75] p(y | x; θ) =σ(θ · x). [2.76] This is the origin of the name “logistic regression.” Logistic regression can be viewed as part of a larger family of generalized linear models (GLMs), in w... | nlp_Page_60_Chunk65 |
2.8. SUMMARY OF LEARNING ALGORITHMS 43 2.8 Summary of learning algorithms It is natural to ask which learning algorithm is best, but the answer depends on what characteristics are important to the problem you are trying to solve. Na¨ıve Bayes Pros: easy to implement; estimation is fast, requiring only a single pass ove... | nlp_Page_61_Chunk66 |
44 CHAPTER 2. LINEAR TEXT CLASSIFICATION Exercises There will be exercises at the end of each chapter. In this chapter, the exercises are mostly mathematical, matching the subject material. In other chapters, the exercises will empha- size linguistics or programming. 1. Let x be a bag-of-words vector such that PV j=1 x... | nlp_Page_62_Chunk67 |
2.8. SUMMARY OF LEARNING ALGORITHMS 45 • Let θ(2) be the unregularized LR coefficients (same model) from training on dataset D2. • Let θ∗be the unregularized LR coefficients from training on the combined dataset D1 ∪D2. Under these conditions, prove that for any feature j, θ∗ j ≥min(θ(1) j , θ(2) j ) θ∗ j ≤max(θ(1) j , θ... | nlp_Page_63_Chunk68 |
46 CHAPTER 2. LINEAR TEXT CLASSIFICATION 10. If a function f is m-strongly convex, then for some m > 0, the following inequality holds for all x and x′ on the domain of the function: f(x′) ≤f(x) + (∇xf) · (x′ −x) + m 2 ||x′ −x||2 2. [2.85] Let f(x) = L(θ(t)), representing the loss of the classifier at iteration t of gra... | nlp_Page_64_Chunk69 |
Chapter 3 Nonlinear classification Linear classification may seem like all we need for natural language processing. The bag- of-words representation is inherently high dimensional, and the number of features is often larger than the number of labeled training instances. This means that it is usually possible to find a lin... | nlp_Page_65_Chunk70 |
48 CHAPTER 3. NONLINEAR CLASSIFICATION This chapter focuses on neural networks, which are the dominant approach for non- linear classification in natural language processing today.1 Historically, a few other non- linear learning methods have been applied to language data. • Kernel methods are generalizations of the near... | nlp_Page_66_Chunk71 |
3.1. FEEDFORWARD NEURAL NETWORKS 49 . . . . . . x z y Figure 3.1: A feedforward neural network. Shaded circles indicate observed features, usually words; squares indicate nodes in the computation graph, which are computed from the information carried over the incoming arrows. If we assume that each zk is binary, zk ∈{0... | nlp_Page_67_Chunk72 |
50 CHAPTER 3. NONLINEAR CLASSIFICATION 3 2 1 0 1 2 3 1 0 1 2 3 values sigmoid tanh ReLU 3 2 1 0 1 2 3 0.0 0.2 0.4 0.6 0.8 1.0 derivatives Figure 3.2: The sigmoid, tanh, and ReLU activation functions where the function σ is now applied elementwise to the vector of inner products, σ(Θ(x→z)x) = [σ(θ(x→z) 1 · x), σ(θ(x→z) ... | nlp_Page_68_Chunk73 |
3.2. DESIGNING NEURAL NETWORKS 51 • The range of the sigmoid function is (0, 1). The bounded range ensures that a cas- cade of sigmoid functions will not “blow up” to a huge output, and this is impor- tant for deep networks with several hidden layers. The derivative of the sigmoid is ∂ ∂aσ(a) = σ(a)(1 −σ(a)). This deri... | nlp_Page_69_Chunk74 |
52 CHAPTER 3. NONLINEAR CLASSIFICATION It is also possible to “short circuit” a hidden layer, by propagating information directly from the input to the next higher level of the network. This is the idea behind residual net- works, which propagate information directly from the input to the subsequent layer (He et al., 2... | nlp_Page_70_Chunk75 |
3.3. LEARNING NEURAL NETWORKS 53 where ey(i) is a one-hot vector of zeros with a value of 1 at position y(i). The inner product between ey(i) and log ˜y is also called the multinomial cross-entropy, and this terminology is preferred in many neural networks papers and software packages. It is also possible to train neur... | nlp_Page_71_Chunk76 |
54 CHAPTER 3. NONLINEAR CLASSIFICATION where f is an elementwise activation function, such as σ or ReLU, and ℓ(i) is the loss at instance i. The parameters Θ(x→z), Θ(z→y), and b can be estimated using online gradient- based optimization. The simplest such algorithm is stochastic gradient descent, which was discussed in... | nlp_Page_72_Chunk77 |
3.3. LEARNING NEURAL NETWORKS 55 θ(x→z) k · x. For example, if f is the sigmoid function, then the derivative is, ∂ℓ(i) ∂θ(x→z) n,k =∂ℓ(i) ∂zk × σ(θ(x→z) k · x) × (1 −σ(θ(x→z) k · x)) × xn [3.33] =∂ℓ(i) ∂zk × zk × (1 −zk) × xn. [3.34] For intuition, consider each of the terms in the product. • If the negative log-likel... | nlp_Page_73_Chunk78 |
56 CHAPTER 3. NONLINEAR CLASSIFICATION Algorithm 6 General backpropagation algorithm. In the computation graph G, every node contains a function ft and a set of parent nodes πt; the inputs to the graph are x(i). 1: procedure BACKPROP(G = {ft, πt}T t=1}, x(i)) 2: vt(n) ←x(i) n for all n and associated computation nodes ... | nlp_Page_74_Chunk79 |
3.3. LEARNING NEURAL NETWORKS 57 x(i) z ˆy ℓ(i) y(i) Θ vx vz vˆy vΘ gˆy gℓ gz gz vy vΘ gℓ gˆy Figure 3.3: A computation graph for the feedforward neural network shown in Figure 3.1. tation graphs, such as TORCH (Collobert et al., 2011), TENSORFLOW (Abadi et al., 2016), and DYNET (Neubig et al., 2017). One important dis... | nlp_Page_75_Chunk80 |
58 CHAPTER 3. NONLINEAR CLASSIFICATION set each input xn and each hidden layer node zk to zero. Srivastava et al. (2014) recom- mend ρ = 0.5 for hidden units, and ρ = 0.2 for input units. Dropout is also incorporated in the gradient computation, so if node zk is dropped, then none of the weights θ(x→z) k will be update... | nlp_Page_76_Chunk81 |
3.3. LEARNING NEURAL NETWORKS 59 than local minima or maxima (Dauphin et al., 2014). Saddle points can pose problems for gradient-based optimization, since learning will slow to a crawl as the gradient goes to zero. However, the noise introduced by stochastic gradient descent, and by feature noising techniques such as ... | nlp_Page_77_Chunk82 |
60 CHAPTER 3. NONLINEAR CLASSIFICATION following uniform distribution (Glorot and Bengio, 2010), θi,j ∼U " − √ 6 p din(n) + dout(n) , √ 6 p din(n) + dout(n) # , [3.36] [3.37] For the weights leading to a ReLU activation function, He et al. (2015) use similar argu- mentation to justify sampling from a zero-mean Gaussian... | nlp_Page_78_Chunk83 |
3.3. LEARNING NEURAL NETWORKS 61 • In batch normalization (Ioffe and Szegedy, 2015), the inputs to each computation node are recentered by their mean and variance across all of the instances in the minibatch B (see § 2.6.2). For example, in a feedforward network with one hidden layer, batch normalization would tranform... | nlp_Page_79_Chunk84 |
62 CHAPTER 3. NONLINEAR CLASSIFICATION Practical advice The bag of tricks for training neural networks continues to grow, and it is likely that there will be several new ones by the time you read this. Today, it is standard practice to use gradient clipping, early stopping, and a sensible initialization of parameters t... | nlp_Page_80_Chunk85 |
3.4. CONVOLUTIONAL NEURAL NETWORKS 63 X(0) C C * X(1) z convolution pooling prediction M Ke Kf Kf Figure 3.4: A convolutional neural network for text classification A simple filter might compute a weighted average over nearby words, C(k) = 0.5 1 0.5 0.5 1 0.5 . . . . . . . . . 0.5 1 0.5 , [3.54] thereby repres... | nlp_Page_81_Chunk86 |
64 CHAPTER 3. NONLINEAR CLASSIFICATION Figure 3.5: A dilated convolutional neural network captures progressively larger context through recursive application of the convolutional operator such as max-pooling (Collobert et al., 2011) or average-pooling, z = MaxPool(X(D)) =⇒ zk = max x(D) k,1 , x(D) k,2 , . . . x(D) k,... | nlp_Page_82_Chunk87 |
3.4. CONVOLUTIONAL NEURAL NETWORKS 65 Additional resources The deep learning textbook by Goodfellow et al. (2016) covers many of the topics in this chapter in more detail. For a comprehensive review of neural networks in natural lan- guage processing, see Goldberg (2017b). A seminal work on deep learning in natural lan... | nlp_Page_83_Chunk88 |
66 CHAPTER 3. NONLINEAR CLASSIFICATION questions consider the gradient with respect to an element of the input, x(0) m,k, and they assume that all parameters are independently distributed. a) First consider a minimal network, with z = MaxPool(X(0)). What is the prob- ability that the gradient ∂ℓ ∂x(0) m,k is non-zero? ... | nlp_Page_84_Chunk89 |
3.4. CONVOLUTIONAL NEURAL NETWORKS 67 • Show how the probability of a small initial gradient on any weight, ∂zk ∂θj,k < α, depends on the size of the input M. Hint: use the lower bound, Pr(σ(θk · x) × (1 −σ(θk · x)) < α) ≥ 2 Pr(σ(θk · x) < α), [3.60] and relate this probability to the variance V [θk · x]. • Design an a... | nlp_Page_85_Chunk90 |
Chapter 4 Linguistic applications of classification Having covered several techniques for classification, this chapter shifts the focus from mathematics to linguistic applications. Later in the chapter, we will consider the design decisions involved in text classification, as well as best practices for evaluation. 4.1 Sen... | nlp_Page_87_Chunk91 |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 2