cs388: natural language processing lecture 14: seman

37
CS388: Natural Language Processing Greg Durre8 Lecture 14: Seman<cs I

Upload: others

Post on 15-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS388: Natural Language Processing Lecture 14: Seman

CS388:NaturalLanguageProcessing

GregDurre8

Lecture14:Seman<csI

Page 2: CS388: Natural Language Processing Lecture 14: Seman

Recall:Dependencies

DT NNTOVBDDT NNthe housetoranthe dog

‣ Dependencysyntax:syntac<cstructureisdefinedbydependencies‣ Head(parent,governor)connectedtodependent(child,modifier)‣ EachwordhasexactlyoneparentexceptfortheROOTsymbol‣ Dependenciesmustformadirectedacyclicgraph

ROOT

Page 3: CS388: Natural Language Processing Lecture 14: Seman

Recall:ShiR-ReduceParsing

IatesomespagheTbolognese

ROOT

‣ State:Stack:[ROOTIate]Buffer:[somespagheTbolognese]

‣ LeR-arc(reduceopera<on):Letdenotethestack�‣ “Poptwoelements,addanarc,putthembackonthestack”

�|w�2, w�1 ! �|w�1 w�1w�2 isnowachildof,

‣ Trainaclassifiertomakethesedecisionssequen<ally—thatclassifiercanparsesentencesforyou

Page 4: CS388: Natural Language Processing Lecture 14: Seman

Wherearewenow?

‣ Earlyintheclass:bagsofword(classifiers)=>sequencesofwords(sequencemodeling)

‣Whyisthisuseful?Whatdoesthisallowustodo?

‣ Nowwecanunderstandsentencesintermsoftreestructuresaswell

‣We’regoingtoseehowparsingcanbeasteppingstonetowardsmoreformalrepresenta<onsoflanguagemeaning

Page 5: CS388: Natural Language Processing Lecture 14: Seman

Today

‣Modeltheore<cseman<cs

‣ CCGparsingfordatabasequeries

‣ Composi<onalseman<cswithfirst-orderlogic

‣ Lambda-DCSforques<onanswering

‣Montagueseman<cs:

Page 6: CS388: Natural Language Processing Lecture 14: Seman

ModelTheore<cSeman<cs

Page 7: CS388: Natural Language Processing Lecture 14: Seman

ModelTheore<cSeman<cs‣ Keyidea:cangroundoutnaturallanguageexpressionsinset-theore<cexpressionscalledmodelsofthosesentences

‣ NaturallanguagestatementS=>interpreta<onofSthatmodelsit

‣ Entailment(statementAimpliesstatementB)reducesto:inallworldswhereAistrue,Bistrue

Shelikesgoingtothatrestaurant

‣ Interpreta<on:defineswhosheandthatrestaurantare,makeitabletobeconcretelyevaluatedwithrespecttoaworld

‣ Ourmodelinglanguageisfirst-orderlogic

Page 8: CS388: Natural Language Processing Lecture 14: Seman

First-orderLogic

‣ singsisapredicate(withoneargument),func<onf:en<ty→true/false

‣ Powerfullogicformalismincludingthingslikeen<<es,rela<ons,andquan<fica<ons

‣ [[sings]]=denota7on,setofen<<eswhichsing(foundbyexecu<ngthispredicateontheworld—we’llcomebacktothis)

LadyGagasings

‣ sings(LadyGaga)=trueorfalse,havetoexecutethisagainstsomedatabase(world)

Page 9: CS388: Natural Language Processing Lecture 14: Seman

Quan<fica<on

‣ ∀xsings(x)∨dances(x)→performs(x)

‣ ∃y∀xfriend(x,y)

‣ Universalquan<fica<on:“forall”operator

‣ Existen<alquan<fica<on:“thereexists”operator

‣ ∀x∃yfriend(x,y)

‣ Sourceofambiguity!“Everyoneisfriendswithsomeone”

“Everyonewhosingsordancesperforms”

“Someonesings”‣ ∃xsings(x)

Page 10: CS388: Natural Language Processing Lecture 14: Seman

LogicinNLP‣ Ques<onanswering:

‣ Informa<onextrac<on: LadyGagaandEminemarebothmusicians

∀xmusician(x)=>performer(x)

musician(LadyGaga)∧musician(Eminem)

Then:performer(LadyGaga)∧performer(Eminem)

WhoarealltheAmericansingersnamedAmy?

λx.na<onality(x,USA)∧sings(x)∧firstName(x,Amy)

‣ Func<onthatmapsfromxtotrue/false,likefilter.Executethisontheworldtoanswertheques<on

‣ Cannowdoreasoning.Maybeknow:

‣ Lambdacalculus:powerfulsystemforexpressingthesefunc<ons

Page 11: CS388: Natural Language Processing Lecture 14: Seman

Composi<onalSeman<cswithFirst-OrderLogic

Page 12: CS388: Natural Language Processing Lecture 14: Seman

MontagueSeman<cs

Id Name Alias Birthdate Sings?e470 StefaniGermano8a LadyGaga 3/28/1986 Te728 MarshallMathers Eminem 10/17/1972 T

‣ Databasecontainingen<<es,predicates,etc.

‣ Sentenceexpressessomethingabouttheworldwhichiseithertrueorfalse

NP VP

NNP NNP

S

VBPLadyGaga sings

‣ Denota<on:evalua<onofsomeexpressionagainstthisdatabase

‣[[LadyGaga]] = e470

denota<onofthisstringisanen<ty

‣[[sings(e470)]] = True

denota<onofthisexpressionisT/F

Page 13: CS388: Natural Language Processing Lecture 14: Seman

MontagueSeman<cs

NP VP

NNP NNP

S

VBPLadyGaga sings

e470

λy. sings(y)takesoneargument(y,theen<ty)andreturnsalogicalformsings(y)

λy. sings(y)

sings(e470)

‣Wecanusethesyntac<cparseasabridgetothelambda-calculusrepresenta<on,buildupalogicalform(ourmodel)composi7onally

func<onapplica<on:applythistoe470ID

Page 14: CS388: Natural Language Processing Lecture 14: Seman

ParsestoLogicalForms

NP

VPNNP NNP

S

VBPLadyGaga

sings

e470

λy. sings(y)

sings(e470) ∧ dances(e470)

VP

CC VP

VBPdancesλy. dances(y)

and

VP:λy.a(y)∧b(y)->VP:λy.a(y)CCVP:λy.b(y)

λy. sings(y) ∧ dances(y)

‣ Generalrules:S:f(x)->NP:xVP:f

Page 15: CS388: Natural Language Processing Lecture 14: Seman

ParsestoLogicalForms

NP

NNP NNP

S

VBDLadyGaga was

e470

λx.λy. born(y,x)

born(e470,3/28/1986)

VP

NP

March28,1986born

λy. born(y, 3/28/1986)

VBN

VP

λy. born(y, 3/28/1986)

‣ Howtohandletense:shouldweindicatethatthishappenedinthepast?‣ Func<ontakestwoarguments:firstx(date),theny(en<ty)

3/28/1986

Page 16: CS388: Natural Language Processing Lecture 14: Seman

Trickythings‣ Adverbs/temporality:LadyGagasangwellyesterday

∃e. type(e,sing) ∧ agent(e,e470) ∧ manner(e,well) ∧ time(e,…)‣ “Neo-Davidsonian”viewofevents:thingswithmanyproper<es:

‣ Quan<fica<on:Everyoneisfriendswithsomeone

‣ Generic:Catseatmice(allcatseatmice?mostcats?somecats?)

∀x ∃y friend(x,y)∃y ∀x friend(x,y)(differentfriends)(onefriend)

‣ Samesyntac<cparseforboth!Sosyntaxdoesn'tresolveallambigui<es

sings(Lady Gaga, time=yesterday, manner=well)

‣ Indefinite:Amyateawaffle ∃w. waffle(w) ∧ ate(Amy,w)

Page 17: CS388: Natural Language Processing Lecture 14: Seman

Seman<cParsing

‣ Forques<onanswering,syntac<cparsingdoesn’ttellyoueverythingyouwanttoknow,butindicatestherightstructure

‣ Solu<on:seman7cparsing:manyformsofthistaskdependingonseman<cformalisms

‣ Twotoday:CCG(lookslikewhatwe’vebeendoing)andlambda-DCS

‣ Applica<ons:databasequerying/ques<onanswer:producelambda-calculusexpressionsthatcanbeexecutedinthesecontexts

Page 18: CS388: Natural Language Processing Lecture 14: Seman

CCGParsing

Page 19: CS388: Natural Language Processing Lecture 14: Seman

CombinatoryCategorialGrammar‣ Steedman+Szabolcsi(1980s):formalismbridgingsyntaxandseman<cs

‣ Syntac<ccategories(forthislecture):S,NP,“slash”categories

‣ S\NP:“ifIcombinewithanNPonmyleRside,Iformasentence”—verb

NP S\NP

Eminem singse728 λy. sings(y)

Ssings(e728)

‣ Parallelderiva<onsofsyntac<cparseandlambdacalculusexpression

‣Whenyouapplythis,therehastobeaparallelinstanceoffunc<onapplica<onontheseman<csside

Page 20: CS388: Natural Language Processing Lecture 14: Seman

CombinatoryCategorialGrammar‣ Steedman+Szabolcsi1980s:formalismbridgingsyntaxandseman<cs

‣ Syntac<ccategories(forthislecture):S,NP,“slash”categories‣ S\NP:“ifIcombinewithanNPonmyleRside,Iformasentence”—verb

‣ (S\NP)/NP:“IneedanNPonmyrightandthenonmyleR”—verbwithadirectobject

NP S\NP

Eminem singse728 λy. sings(y)

Ssings(e728)

NP (S\NP)/NP

Oklahoma borderse101

Texase89NP

λx.λy borders(y,x)

S\NPλy borders(y,e89)

Sborders(e101,e89)

Page 21: CS388: Natural Language Processing Lecture 14: Seman

CCGParsing

Ze8lemoyerandCollins(2005)

‣ “What”isaverycomplextype:needsanounandneedsaS\NPtoformasentence.S\NPisbasicallyaverbphrase(borderTexas)

Page 22: CS388: Natural Language Processing Lecture 14: Seman

CCGParsing

Ze8lemoyerandCollins(2005)

‣ “What”isaverycomplextype:needsanounandneedsaS\NPtoformasentence.S\NPisbasicallyaverbphrase(borderTexas)

‣ Lexiconishighlyambiguous—allthechallengeofCCGparsingisinpickingtherightlexiconentries

Page 23: CS388: Natural Language Processing Lecture 14: Seman

CCGParsing

Slidecredit:DanKlein

‣ “to”needsanNP(des<na<on)andN(parent)

Page 24: CS388: Natural Language Processing Lecture 14: Seman

CCGParsing

Ze8lemoyerandCollins(2005)

‣Manywaystobuildtheseparsers

‣ Oneapproach:runa“supertagger”(tagsthesentencewithcomplexlabels),thenruntheparser

‣ Parsingiseasyonceyouhavethetags,sowe’vereducedittoa(hard)taggingproblem

Page 25: CS388: Natural Language Processing Lecture 14: Seman

BuildingCCGParsers

Ze8lemoyerandCollins(2005)

‣Model:log-linearmodeloverderiva<onswithfeaturesonrules:

P (d|x) / expw>

X

r2d

f(r, x)

!

‣ CanparsewithavariantofCKYEminem sings

NP S\NPe728 λy. sings(y)

Ssings(e728)

f

f

f =Indicator(S\NP->sings)

=Indicator(S->NPS\NP)

Page 26: CS388: Natural Language Processing Lecture 14: Seman

BuildingCCGParsers

Ze8lemoyerandCollins(2005)

‣ Trainingdatalookslikepairsofsentencesandlogicalforms

WhatstatesborderTexas λx. state(x) ∧ borders(x, e89)

‣ TexascorrespondstoNP|e89inthelogicalform(easytofigureout)

(S/(S\NP))/N|λf.λg.λx. f(x) ∧ g(x)‣Whatcorrespondsto

‣ Howdoweinferthatwithoutbeingtoldit?

‣ Problem:wedon’tknowthederiva<on

Page 27: CS388: Natural Language Processing Lecture 14: Seman

Lexicon

WhatstatesborderTexas λx. state(x) ∧ borders(x, e89)

‣ Anysubstringcanparsetoanyoftheseinthelexicon

‣ Chunksinferredfromthelogicformbasedonrules:

‣ GENLEX:takessentenceSandlogicalformL.BreakuplogicalformintochunksC(L),assumeanysubstringofSmightmaptoanychunk

‣ Texas->NP:e89iscorrect‣ borderTexas->NP:e89‣WhatstatesborderTexas->NP:e89… Ze8lemoyerandCollins(2005)

‣ NP:e89 ‣ (S\NP)/NP:λx.λy. borders(x,y)

Page 28: CS388: Natural Language Processing Lecture 14: Seman

GENLEX

‣ Verycomplexandhand-engineeredwayoftakinglambdacalculusexpressionsand“backsolving”forthederiva<on

Ze8lemoyerandCollins(2005)

Page 29: CS388: Natural Language Processing Lecture 14: Seman

Learning

Ze8lemoyerandCollins(2005)

‣ Itera<veprocedureliketheEMalgorithm:es<mate“best”parsesthatderiveeachlogicalform,retraintheparserusingtheseparseswithsupervisedlearning

‣We’lltalkaboutasimplerformofthisinafewslides

Page 30: CS388: Natural Language Processing Lecture 14: Seman

Applica<ons

‣ GeoQuery:answeringques<onsaboutstates(~80%accuracy)

‣ Jobs:answeringques<onsaboutjobpos<ngs(~80%accuracy)

‣ ATIS:flightsearch

‣ CandowellonallofthesetasksifyouhandcraRsystemsanduseplentyoftrainingdata:thesedomainsaren’tthatrich

‣WhataboutbroaderQA?

Page 31: CS388: Natural Language Processing Lecture 14: Seman

Lambda-DCS

Page 32: CS388: Natural Language Processing Lecture 14: Seman

Lambda-DCS

Liangetal.(2011),Liang(2013)

‣ Dependency-basedcomposi<onalseman<cs—originalversionwaslesspowerfulthanlambdacalculus,lambda-DCSisaspowerful

‣ DesignedinthecontextofbuildingaQAsystemfromFreebase

‣ Freebase:setofen<<esandrela<ons

AliceSmith

BobCooper

Sea8le

March15,1961 WashingtonDateOfBirth

PlaceOfBirth

PlaceOfBirth

CapitalOf

‣ [[PlaceOfBirth]]=setofpairsof(person,loca<on)

Page 33: CS388: Natural Language Processing Lecture 14: Seman

Lambda-DCS

Liangetal.(2011),Liang(2013)

Lambda-DCS Lambdacalculus

Seattle λx. x = SeattlePlaceOfBirth λx.λy. PlaceOfBirth(x,y)

PlaceOfBirth.Seattle λx. PlaceOfBirth(x,Seattle)

‣ LookslikeatreefragmentoverFreebase

Sea8lePlaceOfBirth???

Profession.Scientist ∧ PlaceOfBirth.Seattle

λx. Profession(x,Scientist) ∧ PlaceOfBirth(x,Seattle)

Page 34: CS388: Natural Language Processing Lecture 14: Seman

Lambda-DCS

Liangetal.(2011),Liang(2013)

AliceSmith

BobCooper

Sea8le

March15,1961 WashingtonDateOfBirth

PlaceOfBirth

PlaceOfBirth

CapitalOf

Profession

Scien<st

Profession.Scientist ∧ PlaceOfBirth.Seattle“listofscien<stsborninSea8le”

‣ ExecutethisfragmentagainstFreebase,returnsAliceSmith(andothers)

???

Sea8lePlaceOfBirthProfession

Scien<st

Page 35: CS388: Natural Language Processing Lecture 14: Seman

ParsingintoLambda-DCS

Berantetal.(2013)

‣ Buildingthelexicon:moresophis<catedprocessthanGENLEX,butcanhandlethousandsofpredicates

‣ Log-linearmodelwithfeaturesonrules: P (d|x) / expw>

X

r2d

f(r, x)

!

‣ Deriva<ondonsentencex:

‣ SimilartoCRFparsers

‣ Nomoreexplicitsyntax inthesederiva<ons likewehadinCCG

Page 36: CS388: Natural Language Processing Lecture 14: Seman

ParsingwithLambda-DCS

Berantetal.(2013)

‣ Learnjustfromques<on-answerpairs:maximizethelikelihoodoftherightdenota<onywiththederiva<ondmarginalizedout

Foreachexample:Runbeamsearchtogetasetofderiva<ons

Letd*=highest-scoringderiva<oninthebeamwithcorrectdenota7onDoastructuredperceptronupdatetowardsd*awayfromd

Letd=highest-scoringderiva<oninthebeam

sumoverderiva<onsdsuchthatthedenota<onofdonknowledgebaseKisyi

Page 37: CS388: Natural Language Processing Lecture 14: Seman

Takeaways

‣ Canrepresentmeaningwithfirstorderlogicandlambdacalculus

‣ Usefulforqueryingdatabases,ques<onanswering,etc.

‣ Canbridgesyntaxandseman<csandcreateseman<cparsersthatcaninterpretlanguageintolambda-calculusexpressions

‣ Next<me:neuralnetmethodsfordoingthisthatrelylessonhavingexplicitgrammars