Introduction to Natural Language Processing (aka, Computational Linguistics)

81
1 Introduction to Natural Language Processing (aka, Computational Linguistics) Slides by me, Martha Palmer, Eleni Miltsakaki, Dan Jurafsky, Tarkan Kacmaz, and others

description

Introduction to Natural Language Processing (aka, Computational Linguistics). Slides by me, Martha Palmer, Eleni Miltsakaki, Dan Jurafsky, Tarkan Kacmaz, and others. Overview. NLP without linguistics (4-5 weeks) Information Retrieval (search) Text Classification - PowerPoint PPT Presentation

Transcript of Introduction to Natural Language Processing (aka, Computational Linguistics)

Page 1: Introduction to Natural Language Processing  (aka, Computational Linguistics)

1

Introduction to Natural Language Processing

(aka, Computational Linguistics)

Slides by me, Martha Palmer, Eleni Miltsakaki, Dan Jurafsky,

Tarkan Kacmaz, and others

Page 2: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Overview• NLP without linguistics (4-5 weeks)

– Information Retrieval (search)

– Text Classification

– Pattern Matching and Information Extraction

• NLP with sequence structure (~3 weeks)– HMMs, CRFs

– Sequence labeling tasks

• NLP with more structure (~3 weeks)– Grammars and parsing

– Learning grammars

– Semantic role labeling

• Selected topics (~2 weeks)– Learning representations and domain adaptation

– Knowledge-based language processing

2

Page 3: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Practical Matters

• Prereqs: General understanding of probability and statistics

• Grading: • 20% quizzes and in-class participation• 25% Midterm• 20% Project• 35% Final

• I will supply some ideas for projects later– Projects to start after the midterm.– You’re welcome and encouraged to suggest your own

project ideas.3

Page 4: Introduction to Natural Language Processing  (aka, Computational Linguistics)

WHAT IS LANGUAGE?

Page 5: Introduction to Natural Language Processing  (aka, Computational Linguistics)

When we study human language, we are approaching what some

might call the “human essence”, the distinctive qualities of mind

that are, so far as we know, unique to man.

Noam Chomsky

Page 6: Introduction to Natural Language Processing  (aka, Computational Linguistics)

WHAT IS LANGUAGE?• Definition with respect to form:

Language is a system of speech symbols. It is realized acoustically (sound waves), visually-spatially (sign language) and in written form.

• Definition with respect to function:

Language is the most important means of human communication. It is used to convey and exchange information (informative function)

• Multiplicity of languages:

We know of about 7000 languages, which is estimated to be about 1% of all the languages that ever existed.

Page 7: Introduction to Natural Language Processing  (aka, Computational Linguistics)

LANGUAGE AND THE BRAIN

Page 8: Introduction to Natural Language Processing  (aka, Computational Linguistics)

LANGUAGE AND THE BRAIN

Page 9: Introduction to Natural Language Processing  (aka, Computational Linguistics)

THEORIES OF LANGUAGE

• Noam Chomsky claims that language is innate.

• B. F. Skinner claims that language is learned; it is basically a stimulus-response mechanism.

Page 10: Introduction to Natural Language Processing  (aka, Computational Linguistics)

WHAT IS GRAMMAR?• When we learn a language we also learn the rules that govern how language elements, such as words, are combined to produce meaningful language.

• These elements and rules constitute the Grammar of a language.

• The Grammar is “what we know”

• Grammar represents our linguistic competence.

Page 11: Introduction to Natural Language Processing  (aka, Computational Linguistics)

DESCRIPTIVE vs PRESCRIPTIVEGRAMMAR

Prescriptive

(should be)

Descriptive

(is)

Page 12: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Areas of Linguistics• phonetics - the study of speech sounds• phonology - the study of sound systems• morphology- the rules of word formation• syntax - the rules of sentence formation• semantics - the study of word meanings• pragmatics – the study of discourse meanings• sociolinguistics - the study of language in society• applied linguistics –the application of the methods and results of linguistics to such areas as language teaching, national language policies, lexicography, translation, language in politics etc.

Page 13: Introduction to Natural Language Processing  (aka, Computational Linguistics)

What is phonetics?

• Phonetics is the science of speech.

• We all speak.

• But how many of us know how we speak?

• Or what speech is like?

• Phonetics seeks to answer those questions.

Page 14: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Orthography and Sounds

• The English language is not phonetic.

• Words are not spelled as they are pronounced

• There is no one-to-one correspondence between the letters and the sounds or phonemes.

Page 15: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Orthography and Sounds

• Did he believe that Caesar could see the people seize the seas.

• The silly amoeba stole the key to the machine

Page 16: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Articulatory Phonetics

• The production of any speech sound involves the movement of an air stream.

• Most speech sounds are produced by pushing the air out of the lungs through the mouth (oral) and sometimes through the nose (nasal).

Page 17: Introduction to Natural Language Processing  (aka, Computational Linguistics)

SPEECH ORGANSSPEECH ORGANS

Page 18: Introduction to Natural Language Processing  (aka, Computational Linguistics)
Page 19: Introduction to Natural Language Processing  (aka, Computational Linguistics)
Page 20: Introduction to Natural Language Processing  (aka, Computational Linguistics)
Page 21: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Phonology

• Phonology deals with the system and pattern of speech sounds in a language.

• Phonology of a language is the system and pattern of speech sounds.

Page 22: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Phonology

Phonological knowledge permits us to: • produce sounds which form meaningful utterances,

• to recognize a “foreign” accent,

• to make up new words,

• To know what is or is not a sound in one’s language

• to know what different sound strings may represent

Page 23: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Phonetics vs Phonology

Phonetics

The study of speech sounds.

Phonology

The study of the way speech sounds form patterns.

Page 24: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Sequences of Phonemes

b l ı k I b k ı

k l ı b ı l b k

b ı l k b k ı l

k ı l b ı b l k

k k b b l l ı ı

possible impossible

•“I just bought a beautiful new blick” What is a blick?•“I just bought a beautiful new bkli” WHAT!!

Page 25: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Sequences of Phonemes

• Your knowledge of English “tells” you that certain strings of phonemes are permissible and others are not.

• That’s why /bkli/ does not sound like an English word.

• It violates the restrictions on the sequencing of phonemes; i.e. it violates the phonological rules of English.

Page 26: Introduction to Natural Language Processing  (aka, Computational Linguistics)

• Delete a word-final /b/ when it occurs after a /m/as in: But not!

Rules of Phonology

bomb crumb lamb tomb

bombardcrumblelimbertumble

Page 27: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Morphology & Syntax

• Morphology deals with the combination of morphemes into words.

• Syntax deals with the combination of words into sentences.

Page 28: Introduction to Natural Language Processing  (aka, Computational Linguistics)

What is the meaning of ‘meaning’?

• Learning a language includes learning the “agreed upon” meanings of certain strings of sounds and,

• Learning how to combine these meaningful units into larger units which also convey meaning.

Page 29: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Morphemes

• Morpheme is the smallest linguistic unit that has meaning.

• Morpheme is a grammatical unit in which there is an arbitrary union of sound and a meaning and,

• which cannot be further analysed (broken down into parts that have meaning).

Page 30: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Morphemes

• A morpheme may be represented by a single sound:

• e.g. the plural morpheme [s] in cat+s

• A morpheme may be represented by a syllable (monosyllabic):

• e.g. child+ish

Page 31: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Morphemes

A morpheme may be represented by more than one syllable (polysyllabic):

• e.g. lady, water

or three syllables:• e.g. crocodile

or four syllables:• e.g. salamander

Page 32: Introduction to Natural Language Processing  (aka, Computational Linguistics)

32

Words

• Two basic ways to form words

– Inflectional (e.g. English verbs)• Open + ed = opened• Open + ing = opening

– Derivational (e.g. adverbs from adjectives, nouns from adjectives)

• Happy happily• Happy happiness (nouns from adjectives)

Page 33: Introduction to Natural Language Processing  (aka, Computational Linguistics)

33

Syntax

The study of classes of words

and the rules that govern how the words can combine to make phrases and sentences.

Page 34: Introduction to Natural Language Processing  (aka, Computational Linguistics)

34

Basic classes of words

• Classes of words aka parts of speech (POS)– Nouns– Verbs– Adjectives– Adverbs

• The above classes of word belong to the type open class words

• We also have closed class words– Articles, pronouns, prepositions, particles, quantifiers,

conjunctions

Page 35: Introduction to Natural Language Processing  (aka, Computational Linguistics)

35

Basic phrases

• A word from an open class can be used to form the basis of a phrase

• The basis of a phrase is called the head

Page 36: Introduction to Natural Language Processing  (aka, Computational Linguistics)

36

Examples of phrases

• Noun phrases– The manager of the institute– Her worry to pass the exams– Several students from the English Department

• Adjective phrases– easy to understand– mad as a dog– glad that he passed the exam

Page 37: Introduction to Natural Language Processing  (aka, Computational Linguistics)

37

Examples of phrases

• Adverb phrases– fast like the wind– outside the building

• Verb phrases– ate her sandwich– went to the doctor– believed what I told him

Page 38: Introduction to Natural Language Processing  (aka, Computational Linguistics)

38

“Complements”

• Notice that to be meaningful the verb “go”, for example requires a phrase for “location”– *John went– John went home

• Such phrases “complete” the meaning of the verb (or other type of head) and are called complements

Page 39: Introduction to Natural Language Processing  (aka, Computational Linguistics)

39

Inside the noun phrase

• NPs are used to refer to things: objects, places, concepts, events, qualities, etc

• NPs may consist of:– A single pronoun (he, she, etc)– A name or proper noun (John, Athens, etc)– A specifier and a noun– A qualifier and a noun– A specifier and a qualifier and a noun (e.g., the first

three winners)

Page 40: Introduction to Natural Language Processing  (aka, Computational Linguistics)

40

Specifiers

• Specifiers indicate how many objects are described and also how these objects relate to the speaker

• Basis types of specifiers– Ordinals (e.g., first, second)– Cardinals (e.g., one, two)– Determiners (see next slide)

Page 41: Introduction to Natural Language Processing  (aka, Computational Linguistics)

41

Determiners

• Basic types of determiners– Articles (the, a, an)– Demonstratives (this, that, these, those)– Possessives (‘s, her, my, whose, etc)– Wh-determiners (which, what –in questions)– Quantifying determiners (some, every, most,

no, any, etc.)

Page 42: Introduction to Natural Language Processing  (aka, Computational Linguistics)

42

Qualifiers

• Basic types of qualifiers– Adjectives

• Happy cat• Angry feelings

– Noun modifiers • Cook book• University hospitals

Page 43: Introduction to Natural Language Processing  (aka, Computational Linguistics)

43

Inside the verb phrase

• A simple VP– Adverbial modifier + head verb +

complements

• Types of verbs– Auxiliary (be, do, have)– Modal (will, can, could)– Main (eat, work, think)

Page 44: Introduction to Natural Language Processing  (aka, Computational Linguistics)

44

Types of verb complements

• Intransitive verbs do not require complements

• Transitive verbs require an object as a complement (e.g. find a key)

• Transitive verbs allow passive forms (e.g. a key was found)

• Ditransitive verbs require one direct and on indirect object (e.g. give Mary a book)

Page 45: Introduction to Natural Language Processing  (aka, Computational Linguistics)

45

Other verb complements

• Clausal complements– Some verbs require clausal complements

• Mary knows that John left

• Prepositional phrase complements– Some verbs requires specific PP complements

• Mary gave the book to John

– Others require any PP complement• John put the book on the shelf/in the room/under the table

Page 46: Introduction to Natural Language Processing  (aka, Computational Linguistics)

46

Adjective phrases

• Simple– Angry, easy, etc

• Complex – Pleased with the prize– Angry at the committee– Willing to read the book

• Complex AdjP normally do not precede nouns, they are used as complements of verbs such as be or seem

Page 47: Introduction to Natural Language Processing  (aka, Computational Linguistics)

47

Adverbial phrases

• Indicators of – Degree– Location– Manner– The time of something (now, yesterday, etc)– Frequency– Duration

• Location in the sentence– Initial – Medial– Final

Page 48: Introduction to Natural Language Processing  (aka, Computational Linguistics)

48

Grammars and parsing

• What is syntactic parsing– Determining the syntactic structure of a

sentence

• Basic steps– Identify sentence boundaries– Identify what part of speech is each word– Identify syntactic relations

Page 49: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Context Free Grammar

• S -> NP VP

• NP -> det (adj) N

• NP -> Proper N

• NP -> N

• VP -> V, VP -> V PP

• VP -> V NP

• VP -> V NP PP, PP -> Prep NP

• VP -> V NP NP49

Page 50: Introduction to Natural Language Processing  (aka, Computational Linguistics)

50

Parses

V PP

VP

S

NP

the

the mat

satcat

onNPPrep

The cat sat on the mat

DetN

Det N

Page 51: Introduction to Natural Language Processing  (aka, Computational Linguistics)

51

Parses

VPP

VP

S

NP

time

an arrow

flies

likeNPPrep

Time flies like an arrow.

N

Det N

Page 52: Introduction to Natural Language Processing  (aka, Computational Linguistics)

52

Parses

V NP

VP

S

NP

flies like

an

NDet

Time flies like an arrow.

Ntime

arrow

N

Page 53: Introduction to Natural Language Processing  (aka, Computational Linguistics)

53

Features

• C for Case, Subjective/Objective– She visited her.

• P for Person agreement, (1st, 2nd, 3rd)– I like him, You like him, He likes him,

• N for Number agreement, Subject/Verb– He likes him, They like him.

• G for Gender agreement, Subject/Verb– English, reflexive pronouns He washed himself.– Romance languages, det/noun

• T for Tense, – auxiliaries, sentential complements, etc. – * will finished is bad

Page 54: Introduction to Natural Language Processing  (aka, Computational Linguistics)

54

Semantics and Pragmatics

High-level Linguistics (the good stuff!)

Semantics: the study of meaning that can be determined from a sentence, phrase or word.

Pragmatics: the study of meaning, as it depends on context (speaker, situation)

Page 55: Introduction to Natural Language Processing  (aka, Computational Linguistics)

55

Language to Logic

• John went to the book store. John store1, go(John, store1)

• John bought a book. buy(John,book1)

• John gave the book to Mary. give(John,book1,Mary)

• Mary put the book on the table. put(Mary,book1,table1)

Page 56: Introduction to Natural Language Processing  (aka, Computational Linguistics)

56

SemanticsSame event - different sentences

  John broke the window with a hammer.

  John broke the window with the crack.

  The hammer broke the window.

  The window broke.

Page 57: Introduction to Natural Language Processing  (aka, Computational Linguistics)

57

Same event - different syntactic frames

  John broke the window with a hammer.  SUBJ VERB OBJ MODIFIER

  John broke the window with the crack.  SUBJ VERB OBJ MODIFIER

  The hammer broke the window.  SUBJ VERB OBJ

  The window broke.  SUBJ VERB

Page 58: Introduction to Natural Language Processing  (aka, Computational Linguistics)

58

Semantics -predicate arguments

  break(AGENT, INSTRUMENT, PATIENT)

  AGENT PATIENT INSTRUMENT  John broke the window with a hammer.

  INSTRUMENT PATIENT  The hammer broke the window.

  PATIENT  The window broke.

  Fillmore 68 - The case for case

Page 59: Introduction to Natural Language Processing  (aka, Computational Linguistics)

59

    AGENT PATIENT INSTRUMENT

  John broke the window with a hammer.  SUBJ OBJ MODIFIER

  INSTRUMENT PATIENT

  The hammer broke the window.  SUBJ OBJ

  PATIENT

  The window broke.  SUBJ

Page 60: Introduction to Natural Language Processing  (aka, Computational Linguistics)

60

Headlines

• Police Begin Campaign To Run Down Jaywalkers

• Iraqi Head Seeks Arms

• Teacher Strikes Idle Kids

• Miners Refuse To Work After Death

• Juvenile Court To Try Shooting Defendant

Page 61: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Language Families

Page 62: Introduction to Natural Language Processing  (aka, Computational Linguistics)

62

NLP tends to focus on:

• Syntax– Grammars, parsers, parse trees,

dependency structures

• Semantics– Subcategorization frames, semantic

classes, ontologies, formal semantics

• Pragmatics– Pronouns, reference resolution, discourse

models

Page 63: Introduction to Natural Language Processing  (aka, Computational Linguistics)

63

Natural Language Processing Applications and Tasks

• Machine Translation

• Question-Answering

• Information Retrieval

• Information Extraction

Page 64: Introduction to Natural Language Processing  (aka, Computational Linguistics)

64

Machine Translation

• One of the first applications for computers– bilingual dictionary > word-word translation

• Good translation requires understanding!– War and Peace, The Sound and The Fury?

• What can we do? Sublanguages.– technical domains, static vocabulary– Meteo in Canada, Caterpillar Tractor Manuals,

Botanical descriptions, Military Messages

Page 65: Introduction to Natural Language Processing  (aka, Computational Linguistics)

65

Example translation

Page 66: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Machine Translation

• Chinese gloss: Dai-yu alone on bed top think-of-with-gratitude Bao-chai again listen to window outside bamboo tip plantain leaf of on-top rain sound sigh drop clear cold penetrate curtain not feeling again fall down tears come

• Hawkes translation: As she lay there alone, Dai-yu’s thoughts turned to Bao-chai… Then she listened to the insistent rustle of the rain on the bamboos and plantains outside her window. The coldness penetrated the curtains of her bed. Almost without noticing it she had begun to cry.

Page 67: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Machine Translation

• The Story of the Stone – =The Dream of the Red Chamber (Cao Xueqin 1792)

• Issues: (“Language Divergences”)– Sentence segmentation– Zero-anaphora– Coding of tense/aspect

– Penetrate -> penetrated

– Stylistic differences across languages• Bamboo tip plaintain leaf -> bamboos and plantains

– Cultural knowledge• Curtain -> curtains of her bed

Page 68: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Question Answering

• What does “archaeopteryx” mean?• What year was Abraham Lincoln born?• How many states were in the United

States when Lincoln was born?• Was there a military draft during the

Hoover administration?• What do philosophers think about whether

human cloning should be legal?

Page 69: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Modern QA systems

• Still in infancy

• Simple factoid questions beginning to work OK

• Annual government-sponsored “bakeoff” called TREC

Page 70: Introduction to Natural Language Processing  (aka, Computational Linguistics)

70

Issues in NLP

• Ambiguity

• World Knowledge – it’s needed for understanding, but computers don’t have it

Page 71: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Ambiguity

• Computational linguists are obsessed with ambiguity

• Ambiguity is a fundamental problem of computational linguistics

• Resolving ambiguity is a crucial goal

Page 72: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Ambiguity

• Find at least 5 meanings of this sentence:– I made her duck

Page 73: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Ambiguity

• Find at least 5 meanings of this sentence:– I made her duck

• I cooked waterfowl for her benefit (to eat)• I cooked waterfowl belonging to her• I created the (plaster?) duck she owns• I caused her to quickly lower her head or body• I waved my magic wand and turned her into undifferentiated

waterfowl• At least one other meaning that’s inappropriate for gentle company.

Page 74: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Ambiguity is Pervasive

• I caused her to quickly lower her head or body– Lexical category: “duck” can be a N or V

• I cooked waterfowl belonging to her.– Lexical category: “her” can be a possessive (“of her”) or dative

(“for her”) pronoun

• I made the (plaster) duck statue she owns– Lexical Semantics: “make” can mean “create” or “cook”

Page 75: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Ambiguity is Pervasive

• Grammar: Make can be:– Transitive: (verb has a noun direct

object)• I cooked [waterfowl belonging to her]

– Ditransitive: (verb has 2 noun objects)• I made [her] (into) [undifferentiated waterfowl]

– Action-transitive (verb has a direct object and another verb)

– I caused [her] [to move her body]

Page 76: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Ambiguity is Pervasive

• Phonetics!– I mate or duck– I’m eight or duck– Eye maid; her duck– Aye mate, her duck– I maid her duck– I’m aid her duck– I mate her duck– I’m ate her duck– I’m ate or duck– I mate or duck

Page 77: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Kinds of knowledge needed?

• Consider the following interaction with HAL the computer from 2001: A Space Odyssey

• Dave: Open the pod bay doors, Hal.

• HAL: I’m sorry Dave, I’m afraid I can’t do that.

Page 78: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Knowledge needed to build HAL?

• Speech recognition and synthesis– Dictionaries (how words are pronounced)– Phonetics (how to recognize/produce each sound of

English)

• Natural language understanding– Knowledge of the English words involved

• What they mean• How they combine (what is a `pod bay door’?)

– Knowledge of syntactic structure• I’m I do, Sorry that afraid Dave I’m can’t

Page 79: Introduction to Natural Language Processing  (aka, Computational Linguistics)

What’s needed?

• Dialog and pragmatic knowledge– “open the door” is a REQUEST (as opposed

to a STATEMENT or information-question)– It is polite to respond, even if you’re planning

to kill someone.– It is polite to pretend to want to be cooperative

(I’m afraid I can’t…)– What is `that’ in `I can’t do that’?

• Even a system to book airline flights needs much of this kind of knowledge

Page 80: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Modern conversational agents

• Switchboard Receptionists– Implications: need to know how a native or non-native speaker

of English is likely to pronounce a random American name. Eek.

• Airline and other simple dialogue systems– Lots of fabulously fun pragmatic issues

• Grounding• Error handling

• In general– Now that there are commercial installations– Big incentive to use linguistic or any other kind of knowledge if it

actually improves performance

Page 81: Introduction to Natural Language Processing  (aka, Computational Linguistics)

Eliza: Weizenbaum (1966)

• User: You are like my father in some ways.• ELIZA: What resemblance do you see• User: You are not very aggressive but I think you don’t want me to

notice that.• ELIZA: What makes you think I am not aggressive• User: You don’t argue with me• ELIZA: Why do you think I don’t argue with you• User: You are afraid of me• ELIZA: Does it please you to believe I am afraid of you