ML4NLP Multiclass Classification

Similar documents
Multiclass Classification-1

Administration. Registration Hw3 is out. Lecture Captioning (Extra-Credit) Scribing lectures. Questions. Due on Thursday 10/6

Lecture 5 Neural models for NLP

From Binary to Multiclass Classification. CS 6961: Structured Prediction Spring 2018

Lecture 3: Multiclass Classification

Lecture Support Vector Machine (SVM) Classifiers

Natural Language Processing (CSEP 517): Text Classification

Midterms. PAC Learning SVM Kernels+Boost Decision Trees. MultiClass CS446 Spring 17

CSC321 Lecture 4: Learning a Classifier

CS 446: Machine Learning Lecture 4, Part 2: On-Line Learning

Linear models: the perceptron and closest centroid algorithms. D = {(x i,y i )} n i=1. x i 2 R d 9/3/13. Preliminaries. Chapter 1, 7.

Course 395: Machine Learning - Lectures

AN INTRODUCTION TO NEURAL NETWORKS. Scott Kuindersma November 12, 2009

CSC 411 Lecture 17: Support Vector Machine

Machine Learning for NLP

Support vector machines Lecture 4

Warm up: risk prediction with logistic regression

CSC321 Lecture 4: Learning a Classifier

Discriminative Models

Introduction to Logistic Regression and Support Vector Machine

Kernelized Perceptron Support Vector Machines

PAC-learning, VC Dimension and Margin-based Bounds

Neural Networks: Introduction

Machine Learning for NLP

Support Vector Machines: Training with Stochastic Gradient Descent. Machine Learning Fall 2017

Discriminative Models

Multilayer Neural Networks. (sometimes called Multilayer Perceptrons or MLPs)

Natural Language Processing. Classification. Features. Some Definitions. Classification. Feature Vectors. Classification I. Dan Klein UC Berkeley

Lecture 12. Neural Networks Bastian Leibe RWTH Aachen

Multi-class SVMs. Lecture 17: Aykut Erdem April 2016 Hacettepe University

COMP 875 Announcements

Deep Learning for Computer Vision

Gaussian and Linear Discriminant Analysis; Multiclass Classification

Introduction to Support Vector Machines

Multilayer Neural Networks. (sometimes called Multilayer Perceptrons or MLPs)

From perceptrons to word embeddings. Simon Šuster University of Groningen

Machine learning comes from Bayesian decision theory in statistics. There we want to minimize the expected value of the loss function.

Online Videos FERPA. Sign waiver or sit on the sides or in the back. Off camera question time before and after lecture. Questions?

Linear & nonlinear classifiers

Neural networks and support vector machines

Machine Learning for Structured Prediction

Machine Learning Lecture 5

18.9 SUPPORT VECTOR MACHINES

SGD and Deep Learning

Machine Learning. Neural Networks. (slides from Domingos, Pardo, others)

Neural Networks: Backpropagation

Lecture 4: Training a Classifier

Neural Networks biological neuron artificial neuron 1

Machine Learning and Data Mining. Linear classification. Kalev Kask

Day 4: Classification, support vector machines

Nonlinear Classification

Statistical NLP Spring A Discriminative Approach

Support Vector and Kernel Methods

Apprentissage, réseaux de neurones et modèles graphiques (RCP209) Neural Networks and Deep Learning

COMS 4771 Introduction to Machine Learning. Nakul Verma

Machine Learning Lecture 7

CSCI567 Machine Learning (Fall 2018)

Support Vector Machine. Industrial AI Lab.

Machine Learning. Support Vector Machines. Fabio Vandin November 20, 2017

10-701/ Machine Learning - Midterm Exam, Fall 2010

Pattern Recognition Prof. P. S. Sastry Department of Electronics and Communication Engineering Indian Institute of Science, Bangalore

Logistic Regression. Machine Learning Fall 2018

Foundation of Intelligent Systems, Part I. SVM s & Kernel Methods

Kernel Methods and Support Vector Machines

Midterm: CS 6375 Spring 2015 Solutions

Name (NetID): (1 Point)

Logistic Regression & Neural Networks

MIRA, SVM, k-nn. Lirong Xia

Algorithms for NLP. Classification II. Taylor Berg-Kirkpatrick CMU Slides: Dan Klein UC Berkeley

SVMs: Non-Separable Data, Convex Surrogate Loss, Multi-Class Classification, Kernels

Machine Learning. Neural Networks. (slides from Domingos, Pardo, others)

Neural networks and optimization

Linear classifiers Lecture 3

Vote. Vote on timing for night section: Option 1 (what we have now) Option 2. Lecture, 6:10-7:50 25 minute dinner break Tutorial, 8:15-9

Day 3: Classification, logistic regression

CPSC 340: Machine Learning and Data Mining. MLE and MAP Fall 2017

Structured Prediction

Jeff Howbert Introduction to Machine Learning Winter

Machine Learning for Large-Scale Data Analysis and Decision Making A. Neural Networks Week #6

Support Vector Machines for Classification: A Statistical Portrait

CS 188: Artificial Intelligence Spring Announcements

Machine Learning Basics Lecture 2: Linear Classification. Princeton University COS 495 Instructor: Yingyu Liang

Lecture 9: Large Margin Classifiers. Linear Support Vector Machines

Natural Language Processing with Deep Learning CS224N/Ling284

SUPPORT VECTOR MACHINE

Binary Classification / Perceptron

Non-Bayesian Classifiers Part II: Linear Discriminants and Support Vector Machines

Machine Learning. Neural Networks. (slides from Domingos, Pardo, others)

Support Vector Machines. Machine Learning Fall 2017

9 Classification. 9.1 Linear Classifiers

ARTIFICIAL INTELLIGENCE. Artificial Neural Networks

Support Vector Machines

Comments. Assignment 3 code released. Thought questions 3 due this week. Mini-project: hopefully you have started. implement classification algorithms

Neural Networks. Nicholas Ruozzi University of Texas at Dallas

Machine Learning. Neural Networks

1 Machine Learning Concepts (16 points)

Optimization and Gradient Descent

Reducing Multiclass to Binary: A Unifying Approach for Margin Classifiers

Loss Functions, Decision Theory, and Linear Models

Transcription:

ML4NLP Multiclass Classification CS 590NLP Dan Goldwasser Purdue University dgoldwas@purdue.edu

Social NLP Last week we discussed the speed-dates paper. Interesting perspective on NLP problems- Can we use NLP methods in social science research? Key idea: Find a problem in the real world that you can about. DEFINE THE PROBLEM FORMALLY Identify relevant NLP tools that can measure what you are interested in. Evaluate whether they actually do. Use NLP tools to process large amounts of data and say something meaningful about the world that you couldn't before.

Some (free!) pointers for further reading Linguistic Structure Prediction. Noah Smith. http://www.morganclaypool.com/doi/abs/10.2200/s003 61ED1V01Y201105HLT013 Structured Learning and Prediction in Computer Vision. Nowozin and Lampert http://www.nowozin.net/sebastian/papers/nowozin201 1structured-tutorial.pdf Speech and Language Processing. Jurafsky and Martin https://web.stanford.edu/~jurafsky/slp3/

Classification A fundamental machine learning tool Widely applicable in NLP Supervised learning: Learner is given a collection of labeled documents Emails: Spam/not spam; Reviews: Pos/Neg Build a function mapping documents to labels Key property: Generalization function should work well on new data

Learning as Optimization Discriminative Linear classifiers So far we looked perceptron Combines model (linear representation) with algorithm (update rule) Let s try to abstract we want to find a linear function performing best on the data What are good properties of this classifier? Want to explicitly control for error + simplicity How can we discuss these terms separately from a specific algorithm? Search space of all possible linear functions Find a specific function that has certain properties..

So far: Classification General optimization framework for learning Minimize regularized loss function min w = n loss(y n, w n )+ λ 2 w 2 Gradient descent is an all purpose tool Computed the gradient of the square loss function 6

Surrogate Loss functions Surrogate loss function: smooth approximation to the 0-1 loss Upper bound to 0-1 loss 7

Convex Error Surfaces Convex functions have a single minimum point Local minimum = global minimum Easier to optimize (Empirical) Error Convex error functions have no local minima Global Minimum Hypothesis space 8

Gradient Descent Intuition (3) We also need to determine the step size (aka learning rate). What happens if we overshoot? (1) The derivative of the function at w 1 is the slope of the tangent line à Positive slope (increasing) Which direction should we move to decrease the value of Err(w)? w 3 w 4 w 2 What is the gradient of Error(w) at this point? w 1 (2) The gradient determines the direction of steepest increase of Err(w) (go in the opposite direction) 9

Maximal Margin Classification Motivation for the notion of maximal margin Defined w.r.t. a dataset S :

Some Definitions Margin: distance of the closest point from a hyperplane This is known as the geometric margin, the numerator is known as the functional margin γ =min x i,y i y i (w T x i + b) w Our new objective function Learning is essentially solving: max w γ

Maximal Margin We want to find max w Observation: we don t care about the magnitude of w! Set the functional margin to 1, and minimize W max γ w is equivalent to min w w in this setting To make life easy: let s minimize min w w 2 γ x 1 + x 2 = 0 10x 1 + 10x 2 = 0 100x 1 + 100x 2 =0 12

Hard vs. Soft SVM Minimize: ½ w 2 Subject to: (x,y) S: y w T x 1 Minimize: ½ w 2 + c Σ ι ξ i Subject to: (x,y) S: y i w T x i 1-ξ i ; ξ i >0, i=1 m 13

Objective Function for Soft SVM The relaxation of the constraint: y i w it x i 1 can be done by introducing a slack variable ξ (per example) and requiring: y i w it x i 1 - ξ i ; (ξ i ) Now, we want to solve: Min ½ w 2 + c Σ ξ i (subject to ξ i 0) Which can be written as: Min ½ w 2 + c Σ max(0, 1 y i w T x i ). What is the interpretation of this? This is the Hinge loss function 14

Generalization into Multiclass problems

Multiclass classification Tasks So far, our discussion was limited to binary predictions Well, almost (?) What happens if our decision is not over binary labels? Many interesting classification problems are not! POS: Noun,verb, determiner,.. Document classification: sports, finance, politics Sentiment: Positive, negative, objective How can we approach these problems? Can the problem be reduced into a binary classification problem? Hint: What is the computer science solution to: I can solve problem A, but now I have problem B, so 16

Multiclass classification We will look into two approaches: Combining multiple binary classifiers One-vs-All All-vs-All Training a single classifier Extending SVM to the multiclass case

One-Vs-All Assumption: Each class can be separated from the rest using a binary classifier Learning: Decomposed to learning k independent binary classifiers, one corresponding to each class An example (x,y) is considered positive for class y and negative to all others. Assume m examples, k class labels (assume m/k in each) Classifier f i : m/k (positive) and (k-1)m/k (negative) Decision: Winner Takes All: f(x) = argmax i f i (x) = argmax i (v i x) Q: Why do we need the assumption above? 18

sd Example: One-vs-All

Solving Multi-Class with binary learning Multi-Class classifier Function f : x à {1,2,3,...,k} Decompose into binary problems Not always possible to learn 20

Learning via One-Versus-All Find v r,v b,v g,v y R n such that v r x > 0 iff y = red L v b x > 0 iff y = blue J v g x > 0 iff y = green J v y x > 0 iff y = yellow J H = R kn Real Problem Classification: f(x) = argmax i (v i x)

All-vs-All Assumption: There is a separation between every pair of classes using a binary classifier in the hypothesis space. Learning: Decomposed to learning [k choose 2] ~ k 2 independent binary classifiers, separating between every two classes Assume m examples, k class labels. For simplicity, say, m/k in each. Classifier f ij : m/k (positive) and m/k (negative) Decision: Winner Decision procedure is more involved since output of binary classifier may not cohere (transitivity no ensured) : Majority: classify example x to label i if i wins on it more often that j (j=1, k) Tournament: start with n/2 pairs; continue with winners

s All-vs-All

Multiclass by reduction to Binary Decompose the multiclass learning problem into multiple binary learning problems Prediction: combine binary classifiers Learning: optimize local correctness No global view Separation between learning and prediction procedures We can train the classifier to meet the REAL objective Real objective: final performance, not local metric

Multiclass SVM Single classifier optimizing a global objective Extend the SVM framework to the multiclass settings Binary SVM: Minimize W such that the closest points to the hyperplane have a score of +/- 1 Multiclass SVM Each label has a different weight vector Maximize multiclass margin

Margin in the Multiclass case Revise the definition for the multiclass case: The difference between the score of the correct label and the scores of competing labels margin Colors indicate different labels SVM Objective: Minimize total norm of weights s.t. the 26 true label is scored at least 1 more than the second best.

Hard Multiclass SVM Regularization The score of the true label has to be higher than 1, for any label

Soft Multiclass SVM asd Regularizer Slack Variables The score of the true label should have a margin of 1-ξ i Relax hard constraints using slack variables Positive slack Introduction to Machine Learning. Fall 2015 28 K. Crammer, Y. Singer: On the Algorithmic Implementation of Multiclass Kernel-based Vector Machines, JMLR, 2001

Alternative Notation For examples with label i we want: w it x > w jt x Alternative notation: Stack all weight vectors Define features jointly over the input and output is equivalent to w it x > w jt x

Multiclass classification so far Learning: Prediction 30

Cost Sensitive Multiclass Classification Sometime we are willing to tolerate some mistakes more than others 31

Cost Sensitive Multiclass Classification We can think about it as a hierarchy: Define a distance metric: Δ(y,y ) = tree distance between y and y We would like to incorporate that into our learning model Introduction to Machine Learning. Fall 2015 32

Cost Sensitive Multiclass Classification We can think about it as a hierarchy: Define a distance metric: Δ(y,y ) = tree distance between y and y We would like to incorporate that into our learning model Introduction to Machine Learning. Fall 2015 33

Cost Sensitive Multiclass Classification Instead we can have an unconstrained version - l(w;(x n,y n )) l(w;(x n,y n )) = max y Y (y, y ) w,φ(x n,y n ) + w,φ(x n,y ) Introduction to Machine Learning. Fall 2015 34

Reminder: Subgradient descent asdas Slides by Sebastian Nowozinand Christoph H. Lampert structured models in computer vision tutorial CVPR 2011 Introduction to Machine Learning. Fall 2015 35

Reminder: Subgradient descent Slides by Sebastian Nowozinand Christoph H. Lampert structured models in computer vision tutorial CVPR 2011 36

Reminder: Subgradient descent Slides by Sebastian Nowozinand Christoph H. Lampert structured models in computer vision tutorial CVPR 2011 37

Reminder: Subgradient descent Slides by Sebastian Nowozinand Christoph H. Lampert structured models in computer vision tutorial CVPR 2011 38

Subgradient for the MC case 39

Subgradient for the MC case 40

Subgradient for the MC case 41

Subgradient for the MC case 42

Subgradient for the MC case 43

Subgradient descent for the MC case Introduction to Machine Learning. Fall 2015 44

Subgradient descent for the MC case asd Question: What is the difference between this algorithm and the perceptron variant for multiclass classification? Introduction to Machine Learning. Fall 2015 45

Can you define NER as a multiclass classification problem? Named entity recognition (NER) Identify mentions of named entity in text People (PER), places (LOC) and organizations (ORG) Begin p Barak Obama visited Mount Sinai hospital in New York PER ORG LOC Conceptually two considerations: Entity boundary (Begin, Inside,Outside) Entity type (PER,ORG,LOC) Given a sentence, are consecutive predictions independent of each other? Our Labels: Begin p,begin L,Begin o Inside p,inside L,Inside o Outside 46

Introduction to Deep Learning

Deep Learning in NLP So far we used linear models They work fine, but we made some assumptions The problems are linear, or we are willing to work in order to make them linear Feature engineering is a form of expressing domain knowledge We are fine working with very very high dimensional data It s easy to get there. Everything is mostly linear at that point. What could go wrong?

Deep Learning Architectures for NLP The key question we follow how can you build complex (compositional?) meaning representation, for larger units than words, to support advanced classification tasks? We will look at several popular architectures. We will build on a recently introduced model from the 70 s Maybe even before that.. NN made a come-back in the last 5 years.

Neural Networks Robust approach for approximating functions Functions can be real-valued, discrete or vector valued One of the most effective general purpose learning methods A lot of attention in the 90 s, making a comeback! Especially useful for complex problems, where the input data is hard to interpret Sensory data (speech, vision, etc) Many successful application domains Interesting spin: Learning input representation So far we thought about the feature representation as being fixed 50

Neural Network Simply put, NN s are functions f: XàY f is a non-linear function X is a vector of continuous or discrete variables Y is a vector of continuous or discrete variables Very expressive classifier In fact, NN can be used to represent any function The function f is represented using a network of logistic units Introduction to Machine Learning. Fall 2015 51

Multi Layer Neural Networks Multi-layer network were designed to overcome the computational (expressivity) limitation of a single threshold element. The idea is to stack several layers of threshold elements, each layer using the output of the previous layer as input Multi-layer networks can represent arbitrary functions, but building effective learning methods for such network was [thought to be] difficult. activation Output Hidden Input 52

Example: NN for speech vowel recognition Introduction to Machine Learning. Fall 2015 53

ALVINN: autonomous land vehicle in a NN Pomerleau 89 Introduction to Machine Learning. Fall 2015 54

ALVINN: autonomous land vehicle in a NN Introduction to Machine Learning. Fall 2015 55

Basic Units in Multi-Layer NN Basic element: linear unit But, we would like to represent nonlinear functions Multiple layers of linear functions are still linear functions Threshold units are not smooth (we would like to use gradient-based algorithms) activation Output Hidden Input Introduction to Machine Learning. Fall 2015 56

Basic Units in Multi-Layer NN Basic element: sigmoid unit Input to a unit j is defined as: Σw ij x i Output is defined as : σ (Σw ij x i ) σ is simply the logistic function: Note: similar to previous algorithms, We encode the bias/threshold, as a fake Feature that is always active Introduction to Machine Learning. Fall 2015 57

Basic Units in Multi-Layer NN Basic element: sigmoid unit You can also replace the logistic function with other smooth activation functions Introduction to Machine Learning. Fall 2015 58

Basic Units in Multi-Layer NN Key issue: limited expressivity! Minsky and Papert (1969) published an influential books showing what cannot be learned using perceptron These observation discouraged research on NN for several years But.. we really like linear functions! How did we deal with these issues so far? Introduction to Machine Learning. Fall 2015 59

Basic Units in Multi-Layer NN In fact, Rosenblatt (1959) asked: What pattern recognition problems can be transformed so as to become linearly separable Introduction to Machine Learning. Fall 2015 60

Multi Layer NN Another approach for increasing expressivity: Stacking multiple sigmoid units to form a network Compute the output of the network using a feedforward computation Learn the parameters of the network using the backpropagation algorithm Any Boolean function can be represented using a two layer network Any bounded continuous function can be approximated using a two layer network Introduction to Machine Learning. Fall 2015 61