Statistical NLP for the Web Log Linear Models, MEMM, Conditional Random Fields

Similar documents
Graphical models for part of speech tagging

Conditional Random Fields and beyond DANIEL KHASHABI CS 546 UIUC, 2013

Sequence labeling. Taking collective a set of interrelated instances x 1,, x T and jointly labeling them

Statistical Methods for NLP

Sequence Modelling with Features: Linear-Chain Conditional Random Fields. COMP-599 Oct 6, 2015

Sequential Supervised Learning

Intelligent Systems (AI-2)

Lecture 13: Structured Prediction

Probabilistic Models for Sequence Labeling

Statistical Methods for NLP

Intelligent Systems (AI-2)

Conditional Random Field

Log-Linear Models, MEMMs, and CRFs

Undirected Graphical Models

10 : HMM and CRF. 1 Case Study: Supervised Part-of-Speech Tagging

Statistical Methods for NLP

Conditional Random Fields for Sequential Supervised Learning

MACHINE LEARNING FOR NATURAL LANGUAGE PROCESSING

Probabilistic Graphical Models: MRFs and CRFs. CSE628: Natural Language Processing Guest Lecturer: Veselin Stoyanov

Statistical Machine Learning Theory. From Multi-class Classification to Structured Output Prediction. Hisashi Kashima.

Hidden Markov Models

Statistical Machine Learning Theory. From Multi-class Classification to Structured Output Prediction. Hisashi Kashima.

STA 414/2104: Machine Learning

Machine Learning for Structured Prediction

Lecture 13: Discriminative Sequence Models (MEMM and Struct. Perceptron)

ACS Introduction to NLP Lecture 2: Part of Speech (POS) Tagging

Hidden Markov Models

Logistic Regression: Online, Lazy, Kernelized, Sequential, etc.

Hidden Markov Models in Language Processing

What s an HMM? Extraction with Finite State Machines e.g. Hidden Markov Models (HMMs) Hidden Markov Models (HMMs) for Information Extraction

A brief introduction to Conditional Random Fields

STA 4273H: Statistical Machine Learning

Natural Language Processing

Lecture 6: Graphical Models

Midterm sample questions

Conditional Random Fields: An Introduction

Part of Speech Tagging: Viterbi, Forward, Backward, Forward- Backward, Baum-Welch. COMP-599 Oct 1, 2015

CSCI 5832 Natural Language Processing. Today 2/19. Statistical Sequence Classification. Lecture 9

Partially Directed Graphs and Conditional Random Fields. Sargur Srihari

Hidden Markov Models

Conditional Random Fields

CMSC 723: Computational Linguistics I Session #5 Hidden Markov Models. The ischool University of Maryland. Wednesday, September 30, 2009

Probabilistic Graphical Models & Applications

Predicting Sequences: Structured Perceptron. CS 6355: Structured Prediction

A.I. in health informatics lecture 8 structured learning. kevin small & byron wallace

Lecture 5 Neural models for NLP

lecture 6: modeling sequences (final part)

Statistical NLP for the Web

6.047 / Computational Biology: Genomes, Networks, Evolution Fall 2008

Machine Learning for natural language processing

with Local Dependencies

Basic Text Analysis. Hidden Markov Models. Joakim Nivre. Uppsala University Department of Linguistics and Philology

Machine Learning Basics Lecture 7: Multiclass Classification. Princeton University COS 495 Instructor: Yingyu Liang

Advanced Data Science

Statistical Methods for NLP

Lecture 7: Sequence Labeling

Maxent Models and Discriminative Estimation

Machine Learning for natural language processing

Lecture 9: PGM Learning

Lecture 12: Algorithms for HMMs

Generative Clustering, Topic Modeling, & Bayesian Inference

CS 188: Artificial Intelligence Fall 2011

Machine Learning for NLP

Log-Linear Models with Structured Outputs

ECE521 Lectures 9 Fully Connected Neural Networks

Lecture 3: ASR: HMMs, Forward, Viterbi

Structured Output Prediction: Generative Models

Logistic Regression Review Fall 2012 Recitation. September 25, 2012 TA: Selen Uguroglu

Part 4: Conditional Random Fields

Probability and Structure in Natural Language Processing

COMP90051 Statistical Machine Learning

Linear Classifiers IV

Lecture 12: Algorithms for HMMs

Directed Probabilistic Graphical Models CMSC 678 UMBC

Probabilistic Graphical Models

Probabilistic Graphical Models

Information Extraction from Text

Maximum Entropy Markov Models

Computational Genomics and Molecular Biology, Fall

Brief Introduction of Machine Learning Techniques for Content Analysis

COMS 4771 Probabilistic Reasoning via Graphical Models. Nakul Verma

Text Mining. March 3, March 3, / 49

Expectation Maximization (EM)

Introduction to Logistic Regression and Support Vector Machine

Generalized Linear Classifiers in NLP

Multiclass Classification

Algorithms for NLP. Language Modeling III. Taylor Berg-Kirkpatrick CMU Slides: Dan Klein UC Berkeley

Lecture 17: Neural Networks and Deep Learning

Statistical Methods for NLP

Bayesian Networks Introduction to Machine Learning. Matt Gormley Lecture 24 April 9, 2018

Hidden Markov Models

Sequence Labeling: HMMs & Structured Perceptron

More on HMMs and other sequence models. Intro to NLP - ETHZ - 18/03/2013

HOMEWORK #4: LOGISTIC REGRESSION

A gentle introduction to Hidden Markov Models

Introduction to Machine Learning Midterm, Tues April 8

HOMEWORK #4: LOGISTIC REGRESSION

Logistic Regression & Neural Networks

Intelligent Systems (AI-2)

Pattern Recognition and Machine Learning

Transcription:

Statistical NLP for the Web Log Linear Models, MEMM, Conditional Random Fields Sameer Maskey Week 13, Nov 28, 2012 1

Announcements Next lecture is the last lecture Wrap up of the semester 2

Final Project Final Project Presentation Day December 12 th, 10:00 AM to 2pm Wednesday Each team 8 min talk 2 min for Q&A CS Conference room 3

Final Project Grading Final Project : Report+Presentation+Demo 65% of 55 = 35.75 points Final Project Report (30%) Demo (15%) Final Presentation (20%) 4

Final Project Report Same length as your Intermediate report Similar to your Intermediate Report I The final report instructions will be available through the course website 5

HW3 Due Nov 30 th (11:59pm) Q1 : implementing simple example from the class is ok as well Q2 : Look at previous slides, Python code is already in one of the slides Modify to do n-gram counts Compute bigram probabilities 6

Topics for Today Log-linear Models Maximum Entropy Markov Models Conditional Random Fields Applications of CRF for NLP 7

Naïve Bayes vs. Conditional Random Field Naïve Bayes Model CRF Model Trained by maximizing conditional Trained by maximizing likelihood likelihood of classes of data and class Features are assumed independent Feature weights set independently Dependency on features taken account by feature weights Feature weights are set mutually Good for sequence prediction 8

Max Ent Model vs. CRF Model Both are types of log-linear models Max Ent variation called Max Ent Markov Model is more similar to CRF Model addresses some deficiencies with MEMM Training method is different normalization is over all possible state sequence and labels This makes the training bit more complicated Can train both models with Iterative Scaling, though stochastic gradient method and other numerical optimization methods are preferred 9

HMM vs. CRF Both have efficient inference algorithms to find the best sequence Some differences: HMM CRF maximizing p(x,y) Models p(x) as well Limited on types of features that can be used Per State Normalization maximizing p(y x) No need to model p(x) Allows much more set of features to be used Normalization over the whole sequence 10

Relating CRF with Other Models Figure from [1] 11

Relating CRF with Other Models Figure from [1] 12

Applications of Conditional Random Fields Many uses in NLP Noun phrase segmentation [Sha and Pereira, 2003] Named Entity Recognition [McCallum and Li, 2003] Semantic Roles [Roth and Yih, 2005] RNA structure alignment [Liu et. al, 2005] Protein structure [Liu et. al, 2005] 13

Log-linear Models Log-linear Models Logistic Regression /Max Ent Maximum Entropy Markov Models Conditional Random Fields All of these models are a type of log-linear models, there are more of them 14

Log-Linear Model If x is any data point and y is the label, general loglinear linear model can be described as follows Weight for Given feature functions Normalization Term (Partition Function) Feature Functions 15

Understanding the Equation Form Linear combination of features and weights Can be any real value Numerator always positive (exponential of any number is +ve) Denominator normalizes the output making it valid probability between 0 and 1 Ranking of output same as ranking of linear values i.e. exponentials magnify the ranking difference but ranking still stay the same Why is it called log-linear? Remember the logistic regression derivation? 16

Inference in Log-Linear Model Best labels for the data given the model Basically saying we can find the best predicted label by doing linear combination of features and their weights and searching over the all label space 17

Inference in Log-Linear Model Best labels for the data given the model Basically saying we can find the best predicted label by doing linear combination of features and their weights and searching over the all label space 18

Feature Functions Feature function can take account of relations between both data and label space Can be any real value Often feature functions are indicator functions such that they are 0 or 1 depending on absence or presence of the feature Weight of feature function captures how closely the given feature function is related with the given label f 1 (c,d) = { c=nn Λ curword(d)=book Λ prevword(d)=to} f 3 (c,d) = { c=vb Λ curword(d)=book Λ prevclass(d)=adj} 19

Remember Maximum Entropy Model We predicted the class label given a set of features for the given data point Inference was just taking the trained weights, doing linear combination and finding the class with highest probability Find probability score for each class What if we have to predict a sequence of classes? Is this method optimal? p(c x) = exp( N i=0 λ cif i ) c C exp( N i=0 λ c i f i) 20

Thinking of Classification as Search in Label Space We can think of classification as searching the feature and label space to find the correct sequence of labels Think about binary classifier for finding the right segmentation of a word Can treat as a binary classifier for individual letter If we believe that there is dependency between labels then the output label is in fact vector sequence of 0 and 1 2^N possible label vectors Seg-men-tation or segment-ation? Cannot infer using brute force, need to search the label space given the features 21

HMM to Maximum Entropy Markov Model We have already seen a modeling technique which exploits markov assumption to search over label space : HMM Issue with HMM was restrictions on types of features We can marry the good things of both HMM and Maximum Entropy models Use Viterbi and Forward-Backward styled algorithm we learned in HMM But use the framework of Maximum Entropy for features and normalization Maximum Entropy Markov Models 22

HMM MEMM Figures from [2] 23

Maximum Entropy Markov Model ˆT =argmax T P(T W) MEMM Inference =argmax T i P(t i t i 1,w i ) ˆT =argmax T P(T W) HMM Inference ˆT =argmax T P(W T)P(T) =argmax T i P(w i t i )p(t i t i 1 ) 24

Transition Matrix Estimation ˆT =argmax T P(T W) MEMM Inference =argmax T i P(t i t i 1,w i ) Transition is dependent on the state and the feature These features do not have to be just word id, it can be any features functions If q are states and o are observations we get P(q i q i 1,o i )= 1 Z(o,q ) exp( i w if i (o,q)) 25

Viterbi in HMM vs. MEMM HMM decoding: v t (j)=max N i=1 v t 1(i)P(s j s i )P(o t s j )1 j N,1<t T MEMM decoding: v t (j)=max N i=1 v t 1(i)P(s j s i,o t )1 j N,1<t T This computed in maximum entropy framework but has markov assumption in states thus its name MEMM 26

Viterbi in MEMM Figure from [2] 27

Label Bias Problem in MEMM We saw that with markov assumption but with transitions conditioned on both state and observation where transitions are computed based on exponential model on state allowed us to do Viterbi Inference in MEMM There is a weakness in MEMM though Label Bias Problem Transitions from a given state are competing against each other only Per state normalization, i.e. sum of transition probability for any state has to sum to 1 Causes bias: states with fewer arcs are preferred What happens if there is only one outgoing arc? Does it matter what the observation is? 28

Label Bias Example In generative model we could have learned state 1 generates i lot more and state 4 generates o lot less thus preferring 1-2 path more Even if the training data may have seen a lot more ri example vs ro example state 1 and state 4 passes all probability mass to next state 29

MEMMs to Conditional Random Fields MEMM We have exponential model for each state to tell us the conditional probability of the next states CRF No per state normalization Per sequence normalization 30

CRF, MEMM, HMM y1 y2 y3 y1 y2 y3 X1 X2 X3 X1 X2 X3 CRF MEMM y1 y2 y3 y X1 X2 X3 X1 X2 X3 HMM Naïve Bayes 31

Conditional Random Field P(y x;w)= y Y Sum over all feature function exp( j exp( j w j F j (x,y)) w j F j (x,y ) Weight for given feature function Feature Functions Label Sequence Sum over all possible label sequence Observation sequence Model log linear on Feature functions 32

Feature Function F j (x,y) Entire sequence of observation and label are paired Each feature function Fj is sum along the sentence i = 1 to n where n is length of the sentence Assuming binary class labels and a training example of length n sequence y can be any of the 2^n possible sequence (state space huge) Computing denominator is worse as sum is across all 2^n state space How to address this? 33

Feature Function Wegetp(y x;w)= 1 Z(x,w) exp j w j F j (x,y) wherez(x,w)= y Y exp j w j F j (x,y ) Costly operation in CRF 34

Feature Function Markov Assumption LetF j (x,y)= i f j (y i 1,y i,x,i) Wegetp(y x;w)= 1 Z(x,w) exp j w j F j (x,y) wherez(x,w)= y Y exp j w j F j (x,y ) 35

Feature Function Markov Assumption LetF j (x,y)= i f j (y i 1,y i,x,i) Wegetp(y x;w)= 1 Z(x,w) exp( i j w j f j (y i 1,y i,x,i)) wherez(x,w)= y Y exp( i w j f j (y i 1,y i,x,i))) j 36

Conditional Random Field Length of sequence x P(y x;w)= y Y exp( Sum over all feature function i exp( i Weight for given feature function w j f j (y i 1,y i,x,i)) j w j f j (y i 1,y i,x,i)) j Feature Functions Sum over all possible label sequence Feature function can access all of observation Model log linear on Feature functions 37

Hyphenation Feature Function Example LetF j (x,y)= i f j (y i 1,y i,x,i) Sum of low level feature function becomes a real value f 18 (y i 1,y i,x,i)=y i 1,y i =00&x i 1 x i =th Example for hyphenation Two consecutive tags are not hyphens and letters are th If 0 means no hyphen after the letter, Positive weight means no hyphen after t and after h Can you look at multiple y beyond 2? How about adjacency on y? 38

3 Problems Inference y =argmax y p(y x;w) Need to compute normalization constant to compute probabilities Parameter Estimation 39

Inference Problem Inference y =argmax y p(y x;w) exp( w j f j (y i 1,y i,x,i)) P(y x;w)= i j exp( i y Y j w j f j (y i 1,y i,x,i)) 40

Inference in Linear Chain CRF We saw how to do inference in HMM and MEMM We can still do Viterbi dynamic programming based inference y =argmax y p(y x;w) =argmax y j w jf j (x,y) =argmax y j w j i f j(y i 1,y i,x,i) =argmax y i g i(y i 1,y i ) Denominator? whereg i (y i 1,y i )= j w jf j (y i 1,y i,x,i) What data structure to represent gi? g function is still dependent on y(i-1) and y(i) i as a subscript, specific g function for specific i Maximization for specific x and w, so dropped from notation 41

Score of Tag Sequence score(y 1,,y n )= n i g i(y i 1,y i ) Score of tag sequence of length n U(k) = score of best sequence y1.. Yk U(k,v) = score of best sequence y1.. Yk and yk= v 42

Recurrence Relation for CRF LetU(k,v)scoreofbestsequencefromtagsposition1toK Where tag number K needs to be v With this definition maximization of U(k,v) is maximization over k-1 tags because tag K is already fixed as v k 1 U(k,v)=max y1,y 2,...,y k 1 [ g i (y i 1,y i )+g k (y k 1,v)] i=1 U(k,v)= k 2 max y1,y 2,...,y k 2 [ g i (y i 1,y i )+g k 1 (y k 2,y k 1 )+g k (y k 1,v)] i=1 U(k,v)=max yk 1 [U(k 1,y k 1 )+g k (y k 1,v)] Runtime? What was runtime for HMM viterbi? 43

Inference in CRF Our inference algorithm is again based on Viterbi algorithm Output transition and observation probabilities are not modeled separately Output transition dependent on the state and the observation as one conditional probability Build lattice like we did before for decoding 44

Parameter Estimation for CRF Mostly supervised learning No EM like we have for HMM Introduction of hidden variable makes the problem very hard Can be interpreted in maximum entropy framework 45

Conditional Likelihood Given the data we want to maximize the conditional likelihood Like we have done previously we can set the derivative of the conditional likelihood function to zero p(y x;w)= 1 Z(x,w) exp j w j F j (x,y) L(w,D)=log( m k=1 p(yk x k,w)) 46

Taking the Gradient =F j (x,y) 1 Z(x,w) y w j exp j w j F j (x,y ) =F j (x,y) y F j (x,y )p(y x;w) =F j (x,y) E y p(y x;w)[f j (x,y )] Derivative w.r.t to the weight wi = ( value of feature function i for true y) (average value of feature function for all possible y ) 47

Maximum Entropy Interpretation F j (x,y) E y p(y x;w)[f j (x,y )] Empirical count Predicted count 48

Optimization: Stochastic Gradient Ascent For all training (x,y) For all j Compute E y p(y x;w)[f j (x,y )] w j :=w j +α(f j (x,y) E y p(y x;w)[f j (x,y )]) End For End For Most computationally expensive part 49

Optimization Methods Iterative Scaling Gradient Descent Newton s Method Many optimization packages are available that can treated as blackbox replacement Second order methods have shown to be faster 50

General CRF We just showed how to do inference and training of linear structure CRF But we can add varying level of dependencies across states Training more complicated if we add more dependencies We can use more general graphical model approximate algorithms such as belief propagation 51

General CRF y1 y2 y3 X1 X2 X3 Linear Chain CRF y1 y2 y3 X1 X2 X3 More General CRF CRF can be used trees, graphs, etc but can be expensive to train the model 52

CRF for Shallow Parsing [Sha and Pereira, 2004] NP chunking Used many overlapping features that took account of word interaction 53

References [1] Sutton, C and McCallum A An Introduction to Conditional Random Fields for Relational Learning [2] Jurafsky, D and Martin, J, Speech and Language Processing, 2009 [3] Elkan, C Log-linear Models and Conditional Random Fields CIKM Tutorial 2008 54