text stringlengths 1 7.76k | source stringlengths 17 81 |
|---|---|
4.3. DESIGN DECISIONS FOR TEXT CLASSIFICATION 79 0 10000 20000 30000 40000 Vocabulary size 0.5 1.0 Token coverage Pang and Lee Movie Reviews (English) (a) Movie review data in English 0 10000 20000 30000 40000 50000 60000 70000 Vocabulary size 0.5 1.0 Token coverage MAC-Morpho Corpus (Brazilian Portuguese) (b) News art... | nlp_Page_97_Chunk101 |
80 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION in Figure 4.3a, the most frequent 4000 word types cover 90% of all tokens, offering an order-of-magnitude reduction in the model size. Such ratios are language-specific: in for example, in the Brazilian Portuguese Mac-Morpho corpus (Alu´ısio et al., 2003), attain- ... | nlp_Page_98_Chunk102 |
4.4. EVALUATING CLASSIFIERS 81 classifier. Using this data more than once would cause the estimated accuracy to be overly optimistic, because the classifier would be customized to this data, and would not perform as well as on unseen data in the future. It is usually necessary to set hyperparameters or perform feature se... | nlp_Page_99_Chunk103 |
82 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION Classifiers that make a lot of false positives have low precision: they predict the label even when it isn’t there. Classifiers that make a lot of false negatives have low recall: they fail to predict the label, even when it is there. These metrics distinguish these... | nlp_Page_100_Chunk104 |
4.4. EVALUATING CLASSIFIERS 83 0.0 0.2 0.4 0.6 0.8 1.0 False positive rate 0.0 0.2 0.4 0.6 0.8 1.0 True positive rate AUC=0.89 AUC=0.73 AUC=0.5 Figure 4.4: ROC curves for three classifiers of varying discriminative power, measured by AUC (area under the curve) In multi-class problems with unbalanced class distributions,... | nlp_Page_101_Chunk105 |
84 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION selected negative example. A perfect classifier has AUC = 1 (all positive examples score higher than all negative examples); a non-discriminative classifier has AUC = 0.5 (given a randomly selected positive and negative example, either could score higher with equal ... | nlp_Page_102_Chunk106 |
4.4. EVALUATING CLASSIFIERS 85 0 5 10 15 20 25 30 Instances where c1 is right and c2 is wrong 0.00 0.05 0.10 0.15 p(k N = 30, = 0.5) Figure 4.5: Probability mass function for the binomial distribution. The pink highlighted areas represent the cumulative probability for a significance test on an observation of k = 10 and... | nlp_Page_103_Chunk107 |
86 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION because it is computed from the area under the binomial probability mass function from 0 to k, as shown in the left tail of Figure 4.5. This cumulative probability is computed as a sum over all values i ≤k, Pr Binom count(ˆy(i) 2 = y(i) ̸= ˆy(i) 1 ) ≤k; N, θ = 1... | nlp_Page_104_Chunk108 |
4.4. EVALUATING CLASSIFIERS 87 Algorithm 7 Bootstrap sampling for classifier evaluation. The original test set is {x(1:N), y(1:N)}, the metric is δ(·), and the number of samples is M. procedure BOOTSTRAP-SAMPLE(x(1:N), y(1:N), δ(·), M) for t ∈{1, 2, . . . , M} do for i ∈{1, 2, . . . , N} do j ∼UniformInteger(1, N) ˜x(i)... | nlp_Page_105_Chunk109 |
88 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION 4.5 Building datasets Sometimes, if you want to build a classifier, you must first build a dataset of your own. This includes selecting a set of documents or instances to annotate, and then performing the annotations. The scope of the dataset may be determined by th... | nlp_Page_106_Chunk110 |
4.5. BUILDING DATASETS 89 another annotator or team of annotators would produce very similar annotations if given the same data; and they should be scalable, so that they can be produced relatively quickly. Hovy and Lavid (2010) propose a structured procedure for obtaining annotations that meet these criteria, which is... | nlp_Page_107_Chunk111 |
90 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION privacy. In these cases, one solution is to publicly release stand-off annotations, which contain links to document identifiers. The documents themselves can be re- leased under the terms of a licensing agreement, which can impose conditions on how the data is used... | nlp_Page_108_Chunk112 |
4.5. BUILDING DATASETS 91 Crowdsourcing Crowdsourcing is often used to rapidly obtain annotations for classification problems. For example, Amazon Mechanical Turk makes it possible to define “human intelligence tasks (hits)”, such as labeling data. The researcher sets a price for each set of annotations and a list of min... | nlp_Page_109_Chunk113 |
92 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION 4. Suppose that binary classifiers c1 and c2 disagree on N = 30 cases, and that c1 is correct in k = 10 of those cases. • Write a program that uses primitive functions such as exp and factorial to com- pute the two-tailed p-value — you may use an implementation of ... | nlp_Page_110_Chunk114 |
4.5. BUILDING DATASETS 93 The remaining problems will require you to build a classifier and test its properties. Pick a multi-class text classification dataset that is not already tokenized. One example is a dataset of New York Times headlines and topics (Boydstun, 2013).14 Divide your data into training (60%), developme... | nlp_Page_111_Chunk115 |
94 CHAPTER 4. LINGUISTIC APPLICATIONS OF CLASSIFICATION Use the bootstrap test with M = 104 to determine whether your best-performing system achieves significantly higher macro-F -MEASURE. Jacob Eisenstein. Draft of November 13, 2018. | nlp_Page_112_Chunk116 |
Chapter 5 Learning without supervision So far, we have assumed the following setup: • a training set where you get observations x and labels y; • a test set where you only get observations x. Without labeled data, is it possible to learn anything? This scenario is known as unsu- pervised learning, and we will see that ... | nlp_Page_113_Chunk117 |
96 CHAPTER 5. LEARNING WITHOUT SUPERVISION 0 10 20 30 40 density of word group 1 0 20 40 density of word group 2 Figure 5.1: Counts of words from two different context groups bank, the immediate context might typically include words from one of the following two groups: 1. financial, deposits, credit, lending, capital, ... | nlp_Page_114_Chunk118 |
5.1. UNSUPERVISED LEARNING 97 Algorithm 8 K-means clustering algorithm 1: procedure K-MEANS(x1:N, K) 2: for i ∈1 . . . N do ▷initialize cluster memberships 3: z(i) ←RANDOMINT(1, K) 4: repeat 5: for k ∈1 . . . K do ▷recompute cluster centers 6: νk ← 1 δ(z(i)=k) PN i=1 δ(z(i) = k)x(i) 7: for i ∈1 . . . N do ▷reassign ins... | nlp_Page_115_Chunk119 |
98 CHAPTER 5. LEARNING WITHOUT SUPERVISION 5.1.2 Expectation-Maximization (EM) Expectation-maximization combines the idea of soft K-means with Na¨ıve Bayes classifi- cation. To review, Na¨ıve Bayes defines a probability distribution over the data, log p(x, y; φ, µ) = N X i=1 log p(x(i) | y(i); φ) × p(y(i); µ) [5.2] N... | nlp_Page_116_Chunk120 |
5.1. UNSUPERVISED LEARNING 99 the ratio q(i)(z) q(i)(z) = 1, log p(x; φ, µ) = N X i=1 log K X z=1 p(x(i) | z; φ) × p(z; µ) × q(i)(z) q(i)(z) [5.6] = N X i=1 log K X z=1 q(i)(z) × p(x(i) | z; φ) × p(z; µ) × 1 q(i)(z) [5.7] = N X i=1 log Eq(i) " p(x(i) | z; φ)p(z; µ) q(i)(z) # , [5.8] where Eq(i) [f(z)] = PK z=1 q(i)(z) ... | nlp_Page_117_Chunk121 |
100 CHAPTER 5. LEARNING WITHOUT SUPERVISION expectation in the lower bound as a sum, J = N X i=1 K X z=1 q(i)(z) h log p(x(i) | z; φ) + log p(z; µ) −log q(i)(z) i . [5.12] When optimizing this bound, we must also respect a set of “sum-to-one” constraints, PK z=1 q(i)(z) = 1 for all i. Just as in Na¨ıve Bayes, this cons... | nlp_Page_118_Chunk122 |
5.1. UNSUPERVISED LEARNING 101 constraint, we introduce a set of Lagrange multiplers {λz}K z=1, and from the Lagrangian, Jφ = N X i=1 K X z=1 q(i)(z) log p(x(i) | z; φ) + log p(z; µ) −log q(i)(z) + K X z=1 λz(1 − V X j=1 φz,j). [5.19] The term log p(x(i) | z; φ) is the conditional log-likelihood for the multinomial... | nlp_Page_119_Chunk123 |
102 CHAPTER 5. LEARNING WITHOUT SUPERVISION 0 2 4 6 8 iteration 430000 440000 450000 negative log-likelihood bound Figure 5.2: Sensitivity of expectation-maximization to initialization. Each line shows the progress of optimization from a different random initialization. 5.1.3 EM as an optimization algorithm Algorithms ... | nlp_Page_120_Chunk124 |
5.1. UNSUPERVISED LEARNING 103 2000; Capp´e and Moulines, 2009), and is especially useful when there is no closed-form optimum for the likelihood p(x | z), and in online settings where new data is constantly streamed in (see Liang and Klein, 2009, for a comparison for online EM variants). 5.1.4 How many clusters? So fa... | nlp_Page_121_Chunk125 |
104 CHAPTER 5. LEARNING WITHOUT SUPERVISION 10 20 30 40 50 Number of clusters 220000 240000 260000 Negative log-likelihood bound AIC 10 20 30 40 50 Number of clusters 75000 80000 85000 Out-of-sample negative log likelihood Figure 5.3: The negative log-likelihood and AIC for several runs of expectation- maximization, on... | nlp_Page_122_Chunk126 |
5.2. APPLICATIONS OF EXPECTATION-MAXIMIZATION 105 the matrix C as a product of three matrices, U, S, V, under the constraint that U and V are orthonormal, and S is diagonal: min U,S,V||C −USV⊤||F [5.25] s.t.U ∈RV ×K, UU⊤= I S = Diag(s1, s2, . . . , sK) V⊤∈RNp×K, VV⊤= I, where || · ||F is the Frobenius norm, ||X||F = qP... | nlp_Page_123_Chunk127 |
106 CHAPTER 5. LEARNING WITHOUT SUPERVISION Algorithm 9 Generative process for the Na¨ıve Bayes classifier with hidden components for Instance i ∈{1, 2, . . . , N} do: Draw the label y(i) ∼Categorical(µ); Draw the component z(i) ∼Categorical(βy(i)); Draw the word counts x(i) | y(i), z(i) ∼Multinomial(φz(i)). The left su... | nlp_Page_124_Chunk128 |
5.3. SEMI-SUPERVISED LEARNING 107 (5.1) , Villeneuve a bel et bien r´eussi son pari de changer de perspectives tout en assurant une coh´erence `a la franchise.2 (5.2) / Il est ´egalement trop long et bancal dans sa narration, ti`ede dans ses intentions, et tiraill´e entre deux personnages et directions qui ne parvienne... | nlp_Page_125_Chunk129 |
108 CHAPTER 5. LEARNING WITHOUT SUPERVISION ble 5.1, there are two labeled examples, one positive and one negative. From this data, a learner could conclude that r´eussi is positive and long is negative. This isn’t much! How- ever, we can propagate this information to the unlabeled data, and potentially learn more. • I... | nlp_Page_126_Chunk130 |
5.3. SEMI-SUPERVISED LEARNING 109 x(1) x(2) y 1. Peachtree Street located on LOC 2. Dr. Walker said PER 3. Zanzibar located in ? →LOC 4. Zanzibar flew to ? →LOC 5. Dr. Robert recommended ? →PER 6. Oprah recommended ? →PER Table 5.2: Example of multiview learning for named entity classification Co-training is an iterative... | nlp_Page_127_Chunk131 |
110 CHAPTER 5. LEARNING WITHOUT SUPERVISION In label propagation, this is done through a series of matrix operations (Zhu et al., 2003). Let Q be a matrix of size N × K, in which each row q(i) describes the labeling of instance i. When ground truth labels are available, then q(i) is an indicator vector, with q(i) y(i) ... | nlp_Page_128_Chunk132 |
5.4. DOMAIN ADAPTATION 111 disappointing will apply across both movies and appliances; but others, like terrifying, may have meanings that are domain-specific. As a result, direct transfer performs poorly: for example, an out-of-domain classifier (trained on book reviews) suffers twice the error rate of an in-domain clas... | nlp_Page_129_Chunk133 |
112 CHAPTER 5. LEARNING WITHOUT SUPERVISION An effective and “frustratingly simple” alternative is EASYADAPT (Daum´e III, 2007), which creates copies of each feature: one for each domain and one for the cross-domain setting. For example, a negative review of the film Wonder Woman begins, As boring and flavorless as a thr... | nlp_Page_130_Chunk134 |
5.4. DOMAIN ADAPTATION 113 The projection matrix U can be learned in a number of different ways, but many ap- proaches focus on compressing and reconstructing the base features (Ando and Zhang, 2005). For example, we can define a set of pivot features, which are typically chosen be- cause they appear in both domains: in... | nlp_Page_131_Chunk135 |
114 CHAPTER 5. LEARNING WITHOUT SUPERVISION ℓd ℓy d(i) y(i) x g(x) Figure 5.4: A schematic view of adversarial domain adaptation. The loss ℓy is computed only for instances from the source domain, where labels y(i) are available. to learn a representation that makes this classifier perform poorly. At the same time, we w... | nlp_Page_132_Chunk136 |
5.5. *OTHER APPROACHES TO LEARNING WITH LATENT VARIABLES 115 5.5.1 Sampling In EM clustering, there is a distribution q(i) for the missing data related to each instance. The M-step consists of updating the parameters of this distribution. An alternative is to draw samples of the latent variables. If the sampling distri... | nlp_Page_133_Chunk137 |
116 CHAPTER 5. LEARNING WITHOUT SUPERVISION generate vectors that are nearly uniform; when α is small, it tends to generate vectors that assign most of their probability mass to a few entries. Given prior distributions over φ and µ, we can now include them in Gibbs sampling, drawing values for these parameters from pos... | nlp_Page_134_Chunk138 |
5.5. *OTHER APPROACHES TO LEARNING WITH LATENT VARIABLES 117 5.5.2 Spectral learning Another approach to learning with latent variables is based on the method of moments, which makes it possible to avoid the problem of non-convex log-likelihood. Write x(i) for the normalized vector of word counts in document i, so that... | nlp_Page_135_Chunk139 |
118 CHAPTER 5. LEARNING WITHOUT SUPERVISION Spectral learning yields provably good solutions without regard to initialization, and can be quite fast in practice. However, it is more difficult to apply to a broad family of genera- tive models than EM and Gibbs Sampling. For more on applying spectral learning across a ran... | nlp_Page_136_Chunk140 |
5.5. *OTHER APPROACHES TO LEARNING WITH LATENT VARIABLES 119 2. Derive the E-step and M-step updates for the following generative model. You may assume that the labels y(i) are observed, but z(i) m is not. • For each instance i, – Draw label y(i) ∼Categorical(µ) – For each token m ∈{1, 2, . . . , M(i)} ∗Draw z(i) m ∼Ca... | nlp_Page_137_Chunk141 |
120 CHAPTER 5. LEARNING WITHOUT SUPERVISION • Compute the frequency with which each cluster includes instances of SAY.V.01 and SAY.V.02. In the remaining exercises, you will try out some approaches for semisupervised learn- ing and domain adaptation. You will need datasets in multiple domains. You can obtain product re... | nlp_Page_138_Chunk142 |
5.5. *OTHER APPROACHES TO LEARNING WITH LATENT VARIABLES 121 7. Using only 5% of the target domain training data (and all of the source domain train- ing data), implement one of the supervised domain adaptation baselines in § 5.4.1. See if this improves on the “direct transfer” baseline from the previous problem 8. Imp... | nlp_Page_139_Chunk143 |
Part II Sequences and trees 123 | nlp_Page_141_Chunk144 |
Chapter 6 Language models In probabilistic classification, the problem is to compute the probability of a label, condi- tioned on the text. Let’s now consider the inverse problem: computing the probability of text itself. Specifically, we will consider models that assign probability to a sequence of word tokens, p(w1, w2... | nlp_Page_143_Chunk145 |
126 CHAPTER 6. LANGUAGE MODELS A good language model of English will tell us that the probability of this translation is low, in comparison with more grammatical alternatives, p(The coffee black me pleases much) < p(I love dark coffee). [6.2] How can we use this fact? Warren Weaver, one of the early leaders in machine ... | nlp_Page_144_Chunk146 |
6.1. N-GRAM LANGUAGE MODELS 127 This estimator is unbiased: in the theoretical limit of infinite data, the estimate will be correct. But in practice, we are asking for accurate counts over an infinite number of events, since sequences of words can be arbitrarily long. Even with an aggressive upper bound of, say, M = 20 t... | nlp_Page_145_Chunk147 |
128 CHAPTER 6. LANGUAGE MODELS This means that the probability of a sentence w can be approximated as p(w1, . . . , wM) ≈ M Y m=1 p(wm | wm−1, . . . , wm−n+1) [6.10] To compute the probability of an entire sentence, it is convenient to pad the beginning and end with special symbols □and ■. Then the bigram (n = 2) appro... | nlp_Page_146_Chunk148 |
6.2. SMOOTHING AND DISCOUNTING 129 These two problems point to another bias-variance tradeoff (see § 2.2.4). A small n- gram size introduces high bias, and a large n-gram size introduces high variance. We can even have both problems at the same time! Language is full of long-range dependen- cies that we cannot capture ... | nlp_Page_147_Chunk149 |
130 CHAPTER 6. LANGUAGE MODELS Lidstone smoothing, α = 0.1 Discounting, d = 0.1 counts unsmoothed probability effective counts smoothed probability effective counts smoothed probability impropriety 8 0.4 7.826 0.391 7.9 0.395 offense 5 0.25 4.928 0.246 4.9 0.245 damage 4 0.2 3.961 0.198 3.9 0.195 deficiencies 2 0.1 2.02... | nlp_Page_148_Chunk150 |
6.2. SMOOTHING AND DISCOUNTING 131 case of backing off from bigrams to unigrams, the bigram probabilities are, c∗(i, j) =c(i, j) −d [6.15] pKatz(i | j) = c∗(i,j) c(j) if c(i, j) > 0 α(j) × punigram(i) P i′:c(i′,j)=0 punigram(i′) if c(i, j) = 0. [6.16] The term α(j) indicates the amount of probability mass that ha... | nlp_Page_149_Chunk151 |
132 CHAPTER 6. LANGUAGE MODELS If the missing data {Zm} were known, then λ could be estimated as the relative fre- quency, λz =count(Zm = z) M [6.17] ∝ M X m=1 δ(Zm = z). [6.18] But since we do not know the values of the latent variables Zm, we impute a distribution qm in the E-step, which represents the degree of beli... | nlp_Page_150_Chunk152 |
6.3. RECURRENT NEURAL NETWORK LANGUAGE MODELS 133 6.2.4 *Kneser-Ney smoothing Kneser-Ney smoothing is based on absolute discounting, but it redistributes the result- ing probability mass in a different way from Katz backoff. Empirical evidence points to Kneser-Ney smoothing as the state-of-art for n-gram language model... | nlp_Page_151_Chunk153 |
134 CHAPTER 6. LANGUAGE MODELS h0 h1 h2 h3 · · · x1 x2 x3 · · · w1 w2 w3 · · · Figure 6.1: The recurrent neural network language model, viewed as an “unrolled” com- putation graph. Solid lines indicate direct computation, dotted blue lines indicate proba- bilistic dependencies, circles indicate random variables, and sq... | nlp_Page_152_Chunk154 |
6.3. RECURRENT NEURAL NETWORK LANGUAGE MODELS 135 in the sequence. RNN language models are defined, xm ≜φwm [6.27] hm =RNN(xm, hm−1) [6.28] p(wm+1 | w1, w2, . . . , wm) = exp(βwm+1 · hm) P w′∈V exp(βw′ · hm), [6.29] where φ is a matrix of word embeddings, and xm denotes the embedding for word wm. The conversion of wm to... | nlp_Page_153_Chunk155 |
136 CHAPTER 6. LANGUAGE MODELS 6.3.1 Backpropagation through time The recurrent neural network language model has the following parameters: • φi ∈RK, the “input” word vectors (these are sometimes called word embeddings, since each word is embedded in a K-dimensional space; see chapter 14); • βi ∈RK, the “output” word v... | nlp_Page_154_Chunk156 |
6.3. RECURRENT NEURAL NETWORK LANGUAGE MODELS 137 derivatives automatically, and cache them for future use. An important distinction from the feedforward neural networks considered in chapter 3 is that the size of the computa- tion graph is not fixed, but varies with the length of the input. This poses difficulties for t... | nlp_Page_155_Chunk157 |
138 CHAPTER 6. LANGUAGE MODELS hm hm+1 om om+1 cm fm+1 cm+1 im im+1 ˜cm ˜cm+1 xm xm+1 Figure 6.2: The long short-term memory (LSTM) architecture. Gates are shown in boxes with dotted edges. In an LSTM language model, each hm would be used to predict the next word wm+1. The gates are functions of the input and previous ... | nlp_Page_156_Chunk158 |
6.4. EVALUATING LANGUAGE MODELS 139 the input sequence up to position m, and can be used for any labeling task on a sequence of tokens, as we will see in the next chapter. There are several LSTM variants, of which the Gated Recurrent Unit (Cho et al., 2014) is one of the more well known. Many software packages implemen... | nlp_Page_157_Chunk159 |
140 CHAPTER 6. LANGUAGE MODELS 6.4.2 Perplexity Held-out likelihood is usually presented as perplexity, which is a deterministic transfor- mation of the log-likelihood into an information-theoretic quantity, Perplex(w) = 2−ℓ(w) M , [6.42] where M is the total number of tokens in the held-out corpus. Lower perplexities ... | nlp_Page_158_Chunk160 |
6.5. OUT-OF-VOCABULARY WORDS 141 6.5 Out-of-vocabulary words So far, we have assumed a closed-vocabulary setting — the vocabulary V is assumed to be a finite set. In realistic application scenarios, this assumption may not hold. Consider, for example, the problem of translating newspaper articles. The following sentence... | nlp_Page_159_Chunk161 |
142 CHAPTER 6. LANGUAGE MODELS (2014) induce vector representations for morphemes, which they build into a log-bilinear language model; Bhatia et al. (2016) incorporate morpheme vectors into an LSTM. Additional resources A variety of neural network architectures have been applied to language modeling. No- table earlier... | nlp_Page_160_Chunk162 |
6.5. OUT-OF-VOCABULARY WORDS 143 Given a corpus of size M, what is the expectation of the fraction of all possible bigrams that have zero count? You may assume V is large enough that 1 V ≈ 1 V −1. 5. Continuing the previous problem, determine the value of M such that the fraction of bigrams with zero count is at most ϵ... | nlp_Page_161_Chunk163 |
Chapter 7 Sequence labeling The goal of sequence labeling is to assign tags to words, or more generally, to assign discrete labels to discrete elements in a sequence. There are many applications of se- quence labeling in natural language processing, and chapter 8 presents an overview. For now, we’ll focus on the classi... | nlp_Page_163_Chunk164 |
146 CHAPTER 7. SEQUENCE LABELING is applied. This simple feature function then returns a single feature: a tuple including the word to be tagged and the tag that has been proposed. If the vocabulary size is V and the number of tags is K, then there are V × K features. Each of these features must be assigned a weight. T... | nlp_Page_164_Chunk165 |
7.2. SEQUENCE LABELING AS STRUCTURE PREDICTION 147 follow a noun,1 and it is particularly unlikely that the entire sentence would lack a verb. The only possible verb in (7.2) is the word man, which can refer to the act of maintaining and piloting something — often boats. But if man is tagged as a verb, then old is seat... | nlp_Page_165_Chunk166 |
148 CHAPTER 7. SEQUENCE LABELING In a linear model, local scoring function can be defined as a dot product of weights and features, ψ(w1:M, ym, ym−1, m) = θ · f(w, ym, ym−1, m). [7.9] The feature vector f can consider the entire input w, and can look at pairs of adjacent tags. This is a step up from per-token classificat... | nlp_Page_166_Chunk167 |
7.3. THE VITERBI ALGORITHM 149 7.3 The Viterbi algorithm By decomposing the scoring function into a sum of local parts, it is possible to rewrite the tagging problem as follows: ˆy = argmax y∈Y(w) Ψ(w, y) [7.13] = argmax y1:M M+1 X m=1 ψ(w, ym, ym−1, m) [7.14] = argmax y1:M M+1 X m=1 sm(ym, ym−1), [7.15] where the final... | nlp_Page_167_Chunk168 |
150 CHAPTER 7. SEQUENCE LABELING Algorithm 11 The Viterbi algorithm. Each sm(k, k′) is a local score for tag ym = k and ym−1 = k′. for k ∈{0, . . . K} do v1(k) = s1(k, ♦) for m ∈{2, . . . , M} do for k ∈{0, . . . , K} do vm(k) = maxk′ sm(k, k′) + vm−1(k′) bm(k) = argmaxk′ sm(k, k′) + vm−1(k′) yM = argmaxk sM+1(♦, k) + ... | nlp_Page_168_Chunk169 |
7.3. THE VITERBI ALGORITHM 151 0 they can fish -10 N -3 -9 -9 V -12 -5 -11 Figure 7.1: The trellis representation of the Viterbi variables, for the example they can fish, using the weights shown in Table 7.1. The original goal was to find the best scoring sequence, not simply to compute its score. But by solving the auxil... | nlp_Page_169_Chunk170 |
152 CHAPTER 7. SEQUENCE LABELING they can fish N −2 −3 −3 V −10 −1 −3 (a) Weights for emission features. N V ♦ ♦ −1 −2 −∞ N −3 −1 −1 V −1 −3 −1 (b) Weights for transition features. The “from” tags are on the columns, and the “to” tags are on the rows. Table 7.1: Feature weights for the example trellis shown in Figure 7.... | nlp_Page_170_Chunk171 |
7.4. HIDDEN MARKOV MODELS 153 To compute the optimal tag sequence, we walk backwards from here, next checking b3(N) = V, and then b2(V) = N, and finally b1(N) = ♦. This yields y = (N, V, N), which corresponds to the linguistic interpretation of the fishes being put into cans. 7.3.2 Higher-order features The Viterbi algor... | nlp_Page_171_Chunk172 |
154 CHAPTER 7. SEQUENCE LABELING Algorithm 12 Generative process for the hidden Markov model y0 ←♦, m ←1 repeat ym ∼Categorical(λym−1) ▷sample the current tag wm ∼Categorical(φym) ▷sample the current word until ym = ♦ ▷terminate when the stop symbol is generated Na¨ıve Bayes was introduced as a generative model — a pro... | nlp_Page_172_Chunk173 |
7.4. HIDDEN MARKOV MODELS 155 y1 y2 · · · yM w1 w2 · · · wM Figure 7.2: Graphical representation of the hidden Markov model. Arrows indicate prob- abilistic dependencies. 7.4.1 Estimation The hidden Markov model has two groups of parameters: Emission probabilities. The probability pe(wm | ym; φ) is the emission probabi... | nlp_Page_173_Chunk174 |
156 CHAPTER 7. SEQUENCE LABELING problem can be reformulated as, ˆy = argmax y log p(y, w). [7.35] We can now apply the HMM independence assumptions: log p(y, w) = log p(y) + log p(w | y) [7.36] = M+1 X m=1 log pY (ym | ym−1) + log pW|Y (wm | ym) [7.37] = M+1 X m=1 log λym,ym−1 + log φym,wm [7.38] = M+1 X m=1 sm(ym, ym... | nlp_Page_174_Chunk175 |
7.5. DISCRIMINATIVE SEQUENCE LABELING WITH FEATURES 157 In words, the Viterbi variable vm(ym) is the log probability of the best tag sequence ending in ym, joint with the word sequence w1:m. The log probability of the best complete tag sequence is therefore, max y1:M log p(y1:M+1, w1:M+1) = vM+1(♦) [7.49] *Viterbi as a... | nlp_Page_175_Chunk176 |
158 CHAPTER 7. SEQUENCE LABELING The local decomposition of the scoring function Ψ is reflected in a corresponding de- composition of the feature function: Ψ(w, y) = M+1 X m=1 ψ(w, ym, ym−1, m) [7.55] = M+1 X m=1 θ · f(w, ym, ym−1, m) [7.56] =θ · M+1 X m=1 f(w, ym, ym−1, m) [7.57] =θ · f (global)(w, y1:M), [7.58] where ... | nlp_Page_176_Chunk177 |
7.5. DISCRIMINATIVE SEQUENCE LABELING WITH FEATURES 159 Fine-grained context. The hidden Markov model captures contextual information in the form of part-of-speech tag bigrams. But sometimes, the necessary contextual information is more specific. Consider the noun phrases this fish and these fish. Many part-of-speech tags... | nlp_Page_177_Chunk178 |
160 CHAPTER 7. SEQUENCE LABELING is how to estimate the weights on these features. § 2.3 presented three main types of discriminative classifiers: perceptron, support vector machine, and logistic regression. Each of these classifiers has a structured equivalent, enabling it to be trained from labeled sequences rather tha... | nlp_Page_178_Chunk179 |
7.5. DISCRIMINATIVE SEQUENCE LABELING WITH FEATURES 161 be applied to sequence labeling. A support vector machine in which the output is a struc- tured object, such as a sequence, is called a structured support vector machine (Tsochan- taridis et al., 2004).6 In classification, we formalized the large-margin constraint ... | nlp_Page_179_Chunk180 |
162 CHAPTER 7. SEQUENCE LABELING where in the second line we drop the term θ · f(w(i), y(i)), which is constant in y. We can now reformulate the margin constraint for sequence labeling, θ · f(w(i), y(i)) −max y∈Y(w) θ · f(w(i), y) + c(y(i), y) ≥0. [7.72] If the score for θ ·f(w(i), y(i)) is greater than the cost-au... | nlp_Page_180_Chunk181 |
7.5. DISCRIMINATIVE SEQUENCE LABELING WITH FEATURES 163 probability model is, p(y | w) = exp(Ψ(w, y)) P y′∈Y(w) exp(Ψ(w, y′)). [7.74] This is almost identical to logistic regression (§ 2.5), but because the label space is now sequences of tags, we require efficient algorithms for both decoding (searching for the best ta... | nlp_Page_181_Chunk182 |
164 CHAPTER 7. SEQUENCE LABELING where λ controls the amount of regularization. The final term in Equation 7.76 is a sum over all possible labelings. This term is the log of the denominator in Equation 7.74, some- times known as the partition function.9 There are |Y|M possible labelings of an input of size M, so we must... | nlp_Page_182_Chunk183 |
7.5. DISCRIMINATIVE SEQUENCE LABELING WITH FEATURES 165 The conditional log-likelihood can be rewritten, ℓ=λ 2 ||θ||2 − N X i=1 θ · f(w(i), y(i)) + log αM+1(♦). [7.84] Probabilistic programming environments, such as TORCH (Collobert et al., 2011) and DYNET (Neubig et al., 2017), can compute the gradient of this objecti... | nlp_Page_183_Chunk184 |
166 CHAPTER 7. SEQUENCE LABELING Ym−1 = k′ Ym = k αm−1(k′) exp sm(k, k′) βm(k) Figure 7.3: A schematic illustration of the computation of the marginal probability Pr(Ym−1 = k′, Ym = k), using the forward score αm−1(k′) and the backward score βm(k). transition (Ym−1 = k′) →(Ym = k); and the suffixes ym:M, beginning with ... | nlp_Page_184_Chunk185 |
7.6. NEURAL SEQUENCE LABELING 167 In practice, numerical stability demands that we work in the log domain, log αm(k) = log X k′∈Y exp | nlp_Page_185_Chunk186 |
168 CHAPTER 7. SEQUENCE LABELING Using this transformation, it is possible to train the tagger from the negative log-likelihood of the tags, as in a conditional random field. Alternatively, a hinge loss or margin loss objective can be constructed from the raw scores ψm(y). The hidden state hm accounts for information in... | nlp_Page_186_Chunk187 |
7.6. NEURAL SEQUENCE LABELING 169 ym−1 ym ym+1 ←− h m−1 ←− h m ←− h m+1 −→ h m−1 −→ h m −→ h m+1 xm−1 xm xm+1 Figure 7.4: Bidirectional LSTM for sequence labeling. The solid lines indicate computa- tion, the dashed lines indicate probabilistic dependency, and the dotted lines indicate the optional additional probabilis... | nlp_Page_187_Chunk188 |
170 CHAPTER 7. SEQUENCE LABELING [−→ h (w) Nw; ←− h (w) 0 ], where −→ h (w) Nw is the final state of the right-facing pass for word w, and Nw is the number of characters in the word. The character RNN model is trained by back- propagation from the tagging objective. On the test data, the trained RNN is applied to out-of... | nlp_Page_188_Chunk189 |
7.7. *UNSUPERVISED SEQUENCE LABELING 171 The expected counts are computed in the E-step, using the forward and backward recurrences. The local scores follow the usual definition for hidden Markov models, sm(k, k′) = log pE(wm | Ym = k; φ) + log pT (Ym = k | Ym−1 = k′; λ). [7.98] The expected transition counts for a sing... | nlp_Page_189_Chunk190 |
172 CHAPTER 7. SEQUENCE LABELING 7.7.1 Linear dynamical systems The forward-backward algorithm can be viewed as Bayesian state estimation in a discrete state space. In a continuous state space, ym ∈RK, the equivalent algorithm is the Kalman smoother. It also computes marginals p(ym | x1:M), using a similar two-step alg... | nlp_Page_190_Chunk191 |
7.7. *UNSUPERVISED SEQUENCE LABELING 173 Each recurrence that we have seen so far is a special case of this generalized Viterbi recurrence: • In the max-product Viterbi recurrence over probabilities, the ⊕operation corre- sponds to maximization, and the ⊗operation corresponds to multiplication. • In the forward recurre... | nlp_Page_191_Chunk192 |
174 CHAPTER 7. SEQUENCE LABELING 5. Using the weights in Table 7.1, explicitly compute the log-probabilities for all pos- sible taggings of the input fish can. Verify that the forward algorithm recovers the aggregate log probability. 6. Sketch out an algorithm for a variant of Viterbi that returns the top-n label se- qu... | nlp_Page_192_Chunk193 |
Chapter 8 Applications of sequence labeling Sequence labeling has applications throughout natural language processing. This chap- ter focuses on part-of-speech tagging, morpho-syntactic attribute tagging, named entity recognition, and tokenization. It also touches briefly on two applications to interactive settings: dia... | nlp_Page_193_Chunk194 |
176 CHAPTER 8. APPLICATIONS OF SEQUENCE LABELING (8.2) Teacher Strikes Idle Children can also be explained in terms of parts of speech: in the interpretation that was likely intended, strikes is a noun and idle is a verb; in the alternative explanation, strikes is a verb and idle is an adjective. Part-of-speech tagging... | nlp_Page_194_Chunk195 |
8.1. PART-OF-SPEECH TAGGING 177 (8.4) Toes are scarce among veteran blubber men. In English, nouns tend to follow determiners and adjectives, and can play the subject role in the sentence. They can be marked for the plural number by an -s suffix. • Proper nouns (PROPN) are tokens in names, which uniquely specify a given... | nlp_Page_195_Chunk196 |
178 CHAPTER 8. APPLICATIONS OF SEQUENCE LABELING Closed class tags Closed word classes rarely receive new members. They are sometimes referred to as function words — as opposed to content words — as they have little lexical meaning of their own, but rather, help to organize the components of the sentence. • Adpositions... | nlp_Page_196_Chunk197 |
8.1. PART-OF-SPEECH TAGGING 179 b. I try all things, I achieve what I can. The example includes the personal pronouns I and it, as well as the relative pronoun what. Other pronouns include myself, somebody, and nothing. • Determiners (DET) provide additional information about the nouns or noun phrases that they modify:... | nlp_Page_197_Chunk198 |
180 CHAPTER 8. APPLICATIONS OF SEQUENCE LABELING Other The remaining UD tags include punctuation (PUN) and symbols (SYM). Punc- tuation is purely structural — e.g., commas, periods, colons — while symbols can carry content of their own. Examples of symbols include dollar and percentage symbols, math- ematical operators... | nlp_Page_198_Chunk199 |
8.1. PART-OF-SPEECH TAGGING 181 Baselines A simple baseline for part-of-speech tagging is to choose the most common tag for each word. For example, in the Universal Dependencies treebank, the word talk appears 96 times, and 85 of those times it is labeled as a VERB: therefore, this baseline will always predict VERB for... | nlp_Page_199_Chunk200 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.