Prezentace se nahrává, počkejte prosím

Prezentace se nahrává, počkejte prosím

Dependency Parsing Daniel Zeman

Podobné prezentace


Prezentace na téma: "Dependency Parsing Daniel Zeman"— Transkript prezentace:

1 Dependency Parsing Daniel Zeman http://ufal.mff.cuni.cz/course/npfl094

2 9.12.2009http://ufal.mff.cuni.cz/course/npfl0942 Dependency Model of Syntax Summary of syntactic relations: Sentence divided to phrases (constituents). –Cornerstone of the phrase-based (constituent-based) model. Phrase head, dependency of other phrase members on the head. –Head = governing node (token), the other nodes are dependent. –Cornerstone of a dependency tree. We can talk of dependencies even if we work with constituent trees and vice versa.

3 9.12.2009http://ufal.mff.cuni.cz/course/npfl0943 Example of Dependency Tree [#,0] ([gave,2] ([Paul,1], [Peter,3], [pears,5] ([two,4])), [.,6]) Paul gave Peter two pears. #

4 9.12.2009http://ufal.mff.cuni.cz/course/npfl0944 Dependency Labels Paul / Sb gave / Pred Peter / Obj two / Atr pears / Obj. / AuxK # / AuxS

5 9.12.2009http://ufal.mff.cuni.cz/course/npfl0945 Phrase vs. Dependency Trees PaulgavePetertwopears. N V NCN Z NP VP S Paul gave Peter two pears. #

6 9.12.2009http://ufal.mff.cuni.cz/course/npfl0946 Phrase vs. Dependency Trees Phrase (constituent) trees –Show decomposition of sentence to phrases and label them. –Don’t stress what is head and which word depends on which. –Needn’t specify function, dependency type. Dependency trees –Show dependencies between words and label them. –Don’t capture similarity of construction of different sentence parts, recursion. –Don’t capture progress of sentence generation, proximity of dependent nodes to the head. –Don’t contain nonterminals, phrase types—these can be only estimated from parts of speech of the heads.

7 9.12.2009http://ufal.mff.cuni.cz/course/npfl0947 Differences between Phrase and Dependency Model We want to convert a phrase tree P to a dependency tree D or vice versa. Phrase tree does not tell what is the phrase head. –To convert P  D we need a selection function that for every grammar rule select a right-hand symbol to serve as the head. Dependency tree does not show how the sentence arose (recursion), nor does it necessarily cover the complete phrase decomposition. –It does not tell what has been added “sooner” and what “later”. –Several phrase structures may lead to the same dependency structure  back conversion (D  P) is ambiguous.

8 9.12.2009http://ufal.mff.cuni.cz/course/npfl0948 Example Several phrase trees lead to the same dependency tree. VP(bought) NP(John)NP(bike) S(bought) NP(John)VP(bought) S(bought) V(bought)NP(bike)V(bought) bought bikeJohn

9 9.12.2009http://ufal.mff.cuni.cz/course/npfl0949 Differences between Phrase and Dependency Model Dependency tree does not know phrase labels (nonterminals—because it does not even know what the phrases are, see previous slide). –We need a function that determines the label according to the phrase head. –Really we need it? To understand the meaning, one needs the relations and their type but not what has been generated sooner and what later. Phrase tree does not know the type of the relation between the head and the other members—function. (But cf. functional tags in Penn Treebank.) –We need a function that determines the dependency label for every non- head member of the phrase. (We can tell that while selecting the head.) A significant difference: phrase trees are tightly bound to the word order!

10 9.12.2009http://ufal.mff.cuni.cz/course/npfl09410 Discontinuous Phrases Classical context-free grammar cannot describe them! They cannot be represented by bracketing. (Soubor (se nepodařilo) otevřít). ( cs: File couldn’t be opened) N(soubor)T(se)V(nepodařilo)V inf (otevřít) VR(nepodařilo) VP(nepodařilo) VP inf (otevřít)

11 9.12.2009http://ufal.mff.cuni.cz/course/npfl09411 Nonprojectivity Dependency tree including word order (horizontal coordinate of nodes). Projection to the base: the vertical from the node crosses a dependency (nonprojective edge). Formally: –Dependency ([g,x g ],[d,x d ]). x w is the order of the word w in the sentence. –There exists a node [n,x n ] that x g < x n < x d or x d < x n < x g and [n,x n ] is not in subtree rooted by [g,x g ]. Informally: The string spanned by the subtree of the governing node is discontinuous, contains gaps.

12 9.12.2009http://ufal.mff.cuni.cz/course/npfl09412 Nonprojectivity: Can Be Handled by a Dependency Tree! soubor / Obj se / AuxT nepodařilo / Pred otevřít / Obj

13 9.12.2009http://ufal.mff.cuni.cz/course/npfl09413 Problem: Not Everything is Dependency Coordination and apposition. –Modifying coordination × modifying a coordination member. –Auxiliary nodes (punctuation etc.) bought Pred_Co today Adv yesterday Adv repaired Pred_Co now Adv sold Pred_Co car Obj, AuxX and / Coord

14 9.12.2009http://ufal.mff.cuni.cz/course/npfl09414 Prepositional Phrases, Nested Subjoined Clauses na AuxP zápraží Adv budu Pred na AuxP Pavla Adv od AuxP rozdíl AuxP ptáte Pred se AuxT zda AuxC vás Obj vidím Obj, AuxX

15 9.12.2009http://ufal.mff.cuni.cz/course/npfl09415 Nested Relative Clauses muž / man ??? kterého / whom Obj, AuxX jsem / I AuxV vám / to you Obj představil / introduced Atr

16 9.12.2009http://ufal.mff.cuni.cz/course/npfl09416 Phrases, Dependencies and Other Models Phrases (constituents, immediate constituents). –Originally more widespread, suitable for English. –Context-free grammars. Dependencies. –Originally popular e.g. in Czech (and also in Far East), now widespread. –Especially suitable for free-word-order languages. –Dependency grammars, grammars of dependency trees. Categorial grammars. Tree-adjoining grammars (TAGs). And many more…

17 9.12.2009http://ufal.mff.cuni.cz/course/npfl09417 Dependency Grammar In contrast to phrase model, relation to grammar is artificial (“dependency tree does not demonstrate how it was generated”). No implementation for Czech. Context-free grammar + head-selection function (only projective constructions). Grammar rules that rewrite a nonterminal to a whole subtree (grammar of dependency trees). Related to link grammars, tree-adjoining grammars, categorial grammars. HPSG, unification.

18 9.12.2009http://ufal.mff.cuni.cz/course/npfl09418 Dependency Parsing with a Statistical Model Manually annotated corpus (treebank) p(edge([ve], [dveřích])) = p 1 p(edge([v], [dveřích])) = p 2 p(edge([ve], [dveře])) = p 3 p(edge([ve], [dveřím])) = p 4 where perhaps: p 1 > p 2 > p 3 and p 4  0

19 Searching for tree M that represents the given sentence S with the highest possible probability. Formally: –Bayes rule: –p(S|M) is the probability that the sentence whose description is the tree M is S. –p(M) is the probability of the occurrence (existence) of the tree M. –p(S) is the probability of the occurrence of the sentence S. From the point of view of searching the most probable tree this is a mere constant that does not influence the result: 9.12.2009http://ufal.mff.cuni.cz/course/npfl09419 Base Idea: Looking for the Most Probable Tree

20 9.12.2009http://ufal.mff.cuni.cz/course/npfl09420 Base Idea: Looking for the Most Probable Tree p(S) is the probability of the occurrence of the sentence S. From the point of view of searching the most probable tree this is a mere constant that does not influence the result: So the task is to estimate the probabilities p(S|M) and p(M). p(S|M) can be maximized so that the tree M is constructed directly of the words of the sentence S.

21 Assumption: dependencies do not depend on each other (strong and wrong—a better model would be more careful) Product of probabilities of dependencies. How to find the most probable tree? Similarly to tagging: by Viterbi algorithm! (The middle course between the greedy algorithm and backtracking.) 9.12.2009http://ufal.mff.cuni.cz/course/npfl09421 Tree Probability

22 9.12.2009http://ufal.mff.cuni.cz/course/npfl09422 MST Parser McDonald et al., HLT-EMNLP 2005 http://sourceforge.net/projects/mstparser/ MST = maximum spanning tree = cs: nejlépe ohodnocená kostra (orientovaného) grafu Start with a total graph. –We assume that there can be a dependency between any two words of the sentence. Gradually remove poorly valued edges. A statistical algorithm will take care of the valuation. –It is trained on edge features. –Example features: lemma, POS, case… of governing / dependent node.

23 9.12.2009http://ufal.mff.cuni.cz/course/npfl09423 MST Parser Feature engineering (tell the parser what features to track) by modifying the source code (Java). Not easy to incorporate 2 nd order features –I.e. edge weight depends e.g. on POS tag of its grandparent. Parser can be run in nonprojective mode. Training on the whole PDT reportedly takes about 30 hours. –It is necessary to iterate over all feature combinations and look for the most useful ones. In comparison to that, the parsing proper is quite fast.

24 9.12.2009http://ufal.mff.cuni.cz/course/npfl09424 Malt Parser Nivre et al., Natural Language Engineering, 2007 http://maltparser.org/ Based on transitions from one configuration to another. Configuration: –Input buffer (words of the sentence, left-to-right) –Stack –Output tree (words, dependencies and dependency labels) Transitions: –Shift: move word from buffer to stack –Larc: left dependency between two topmost words on stack –Rarc: right dependency between two topmost words on stack

25 9.12.2009http://ufal.mff.cuni.cz/course/npfl09425 Malt Parser Parser driven by oracle that selects the transition operation based on the current configuration. Training: decompose the tree from training data to a sequence of configurations and transitions –Sometimes there are more than one possibility Various learning strategies: e.g. create dependencies eagerly, as soon as possible. The oracle learns based on the features of the configuration. –E.g. word, lemma, POS, case, number… n th word from the top of the stack k th word remaining in the buffer particular node in output tree part created so far

26 9.12.2009http://ufal.mff.cuni.cz/course/npfl09426 Malt Parser Again, a machine learning algorithm is responsible for training, here the Support Vector Machines (SVM). –Classifier. Input vectors: values of all features of the current configuration. –In addition, during training there is the output value, i.e. action identifier (Shift / Larc / Rarc). –The trained oracle (SVM) tells the output value during parsing. Training on the whole PDT may take weeks! –Complexity O(n 2 ) where n is number of training examples. –Over 3 million training examples can be extracted from PDT. Parsing is relatively faster (~ 1 sentence / second) and can be parallelized.

27 9.12.2009http://ufal.mff.cuni.cz/course/npfl09427 Example of Malt Parsing stack=# buffer=Pavel dal Petrovi dvě hrušky. English=Paul gave to-Peter two pears.

28 9.12.2009http://ufal.mff.cuni.cz/course/npfl09428 Example of Malt Parsing stack=# buffer=Pavel dal Petrovi dvě hrušky. tree= SHIFT stack=# Pavel buffer=dal Petrovi dvě hrušky. tree=

29 9.12.2009http://ufal.mff.cuni.cz/course/npfl09429 Example of Malt Parsing stack=# Pavel buffer=dal Petrovi dvě hrušky. tree= SHIFT stack=# Pavel dal buffer=Petrovi dvě hrušky. tree=

30 9.12.2009http://ufal.mff.cuni.cz/course/npfl09430 Example of Malt Parsing stack=# Pavel dal buffer=Petrovi dvě hrušky. tree= LARC stack=# dal buffer=Petrovi dvě hrušky. tree=dal(Pavel)

31 9.12.2009http://ufal.mff.cuni.cz/course/npfl09431 Example of Malt Parsing stack=# dal buffer=Petrovi dvě hrušky. tree=dal(Pavel) SHIFT stack=# dal Petrovi buffer=dvě hrušky. tree=dal(Pavel)

32 9.12.2009http://ufal.mff.cuni.cz/course/npfl09432 Example of Malt Parsing stack=# dal Petrovi buffer=dvě hrušky. tree=dal(Pavel) RARC stack=# dal buffer=dvě hrušky. tree=dal(Pavel,Petrovi)

33 9.12.2009http://ufal.mff.cuni.cz/course/npfl09433 Example of Malt Parsing stack=# dal buffer=dvě hrušky. tree=dal(Pavel,Petrovi) SHIFT stack=# dal dvě buffer=hrušky. tree=dal(Pavel,Petrovi)

34 9.12.2009http://ufal.mff.cuni.cz/course/npfl09434 Example of Malt Parsing stack=# dal dvě buffer=hrušky. tree=dal(Pavel,Petrovi) SHIFT stack=# dal dvě hrušky buffer=. tree=dal(Pavel,Petrovi)

35 9.12.2009http://ufal.mff.cuni.cz/course/npfl09435 Example of Malt Parsing stack=# dal dvě hrušky buffer=. tree=dal(Pavel,Petrovi) LARC stack=# dal hrušky buffer=. tree=dal(Pavel,Petrovi),hrušky(dvě)

36 9.12.2009http://ufal.mff.cuni.cz/course/npfl09436 Example of Malt Parsing stack=# dal hrušky buffer=. tree=dal(Pavel,Petrovi),hrušky(dvě) RARC stack=# dal buffer=. tree=dal(Pavel,Petrovi,hrušky(dvě))

37 9.12.2009http://ufal.mff.cuni.cz/course/npfl09437 Example of Malt Parsing stack=# dal buffer=. tree=dal(Pavel,Petrovi,hrušky(dvě)) RARC stack=# buffer=. tree=#(dal(Pavel,Petrovi,hrušky(dvě)))

38 9.12.2009http://ufal.mff.cuni.cz/course/npfl09438 Example of Malt Parsing stack=# buffer=. tree=#(dal(Pavel,Petrovi,hrušky(dvě))) SHIFT stack=#. buffer= tree=#(dal(Pavel,Petrovi,hrušky(dvě)))

39 9.12.2009http://ufal.mff.cuni.cz/course/npfl09439 Example of Malt Parsing stack=#. buffer= tree=#(dal(Pavel,Petrovi,hrušky(dvě))) RARC stack=# buffer= tree= #(dal(Pavel,Petrovi,hrušky(dvě)),.)

40 9.12.2009http://ufal.mff.cuni.cz/course/npfl09440 Nonprojective Mode of Malt It can be proved that the above transition system is –correct resulting graph is always a tree (continuous, cycle-free) –complete for the set of projective trees every projective tree can be expressed as a sequence of transitions How to add nonprojective dependencies? –New transition operation SWAP : –Take second topmost word from stack and return it to buffer. That will swap the order of the input words. –This action is permitted only for words that have not been swapped before (their order on the stack corresponds to their original order in the sentence).

41 9.12.2009http://ufal.mff.cuni.cz/course/npfl09441 Nonprojective Parsing Example stack=# buffer=Soubor se nepodařilo otevřít. English=File itself it-did-not-succeed to-open.

42 9.12.2009http://ufal.mff.cuni.cz/course/npfl09442 Nonprojective Parsing Example stack=# buffer=Soubor se nepodařilo otevřít. tree= SHIFT stack=# Soubor buffer=se nepodařilo otevřít. tree=

43 9.12.2009http://ufal.mff.cuni.cz/course/npfl09443 Nonprojective Parsing Example stack=# Soubor buffer=se nepodařilo otevřít. tree= SHIFT stack=# Soubor se buffer=nepodařilo otevřít. tree=

44 9.12.2009http://ufal.mff.cuni.cz/course/npfl09444 Nonprojective Parsing Example stack=# Soubor se buffer=nepodařilo otevřít. tree= SHIFT stack=# Soubor se nepodařilo buffer=otevřít. tree=

45 9.12.2009http://ufal.mff.cuni.cz/course/npfl09445 Nonprojective Parsing Example stack=# Soubor se nepodařilo buffer=otevřít. tree= LARC stack=# Soubor nepodařilo buffer=otevřít. tree=nepodařilo(se)

46 9.12.2009http://ufal.mff.cuni.cz/course/npfl09446 Nonprojective Parsing Example stack=# Soubor nepodařilo buffer=otevřít. tree=nepodařilo(se) SHIFT stack=# Soubor nepodařilo otevřít buffer=. tree=nepodařilo(se)

47 9.12.2009http://ufal.mff.cuni.cz/course/npfl09447 Nonprojective Parsing Example stack=# Soubor nepodařilo otevřít buffer=. tree=nepodařilo(se) SWAP stack=# Soubor otevřít buffer=nepodařilo. tree=nepodařilo(se)

48 9.12.2009http://ufal.mff.cuni.cz/course/npfl09448 Nonprojective Parsing Example stack=# Soubor otevřít buffer=nepodařilo. tree=nepodařilo(se) LARC stack=# otevřít buffer=nepodařilo. tree=nepodařilo(se),otevřít(Soubor)

49 9.12.2009http://ufal.mff.cuni.cz/course/npfl09449 Nonprojective Parsing Example stack=# otevřít buffer=nepodařilo. tree=nepodařilo(se),otevřít(Soubor) SHIFT stack=# otevřít nepodařilo buffer=. tree=nepodařilo(se),otevřít(Soubor)

50 9.12.2009http://ufal.mff.cuni.cz/course/npfl09450 Nonprojective Parsing Example stack=# otevřít nepodařilo buffer=. tree=nepodařilo(se),otevřít(Soubor) LARC stack=# nepodařilo buffer=. tree=nepodařilo(se,otevřít(Soubor))

51 9.12.2009http://ufal.mff.cuni.cz/course/npfl09451 Nonprojective Parsing Example stack=# nepodařilo buffer=. tree=nepodařilo(se,otevřít(Soubor)) RARC stack=# buffer=. tree=#(nepodařilo(se,otevřít(Soubor)))

52 9.12.2009http://ufal.mff.cuni.cz/course/npfl09452 Nonprojective Parsing Example stack=# buffer=. tree=#(nepodařilo(se,otevřít(Soubor))) SHIFT stack=#. buffer= tree=#(nepodařilo(se,otevřít(Soubor)))

53 9.12.2009http://ufal.mff.cuni.cz/course/npfl09453 Nonprojective Parsing Example stack=#. buffer= tree=#(nepodařilo(se,otevřít(Soubor))) RARC stack=# buffer= tree= #(nepodařilo(se,otevřít(Soubor)),.)

54 9.12.2009http://ufal.mff.cuni.cz/course/npfl09454 Malt and MST Accuracy Czech (PDT): –MST Parser over 85% –Malt Parser over 86% Sentence accuracy (“complete match”) 35%, that is high! –The two parsers use different strategies and can be combined (either by voting (third parser needed) or one preparing features for the other) Other languages (CoNLL shared tasks) –MST was slightly better on most languages. –Accuracies not comparable cross-linguistically, figures are very dependent on particular corpora.

55 9.12.2009http://ufal.mff.cuni.cz/course/npfl09455 Features Are the Key to Success Common feature of MST and Malt: –Both can use large number of input text features. –Nontrivial machine learning algorithm makes sure that the important features will be given higher weight. –Machine learning algorithms are general classifiers. Typically there is a library ready to download. The concrete problem (here tree building) must be converted to a sequence of classification decisions, e.g. vectors (feature values + answer).

56 Advertisement new course “New Language” Daniel Zeman http://ufal.mff.cuni.cz/course/npfl105

57 11.1.2013http://ufal.mff.cuni.cz/course/npfl10557 NPFL105 New Language (think Morph-Synt-Anal II) New course in summer term Formally 2 hours/week, 2 points, 6 e-credits (!?) In practice: –Sort of team project –Meetings every two weeks or so –Similar work to your personal projects in this semester –But all students work on the same language, each on different part Goal: –As many NLP resources as possible for one language –Make them work together (Treex; LREC Language Library)

58 9.12.2009http://ufal.mff.cuni.cz/course/npfl09458 Valence Sloveso je centrum věty. Větné členy závislé na slovesu jsou jeho doplnění. Dva druhy doplnění: –vnitřní = aktanty = participanty –vnější = volná

59 9.12.2009http://ufal.mff.cuni.cz/course/npfl09459 Druhy slovesných doplnění: vnitřní × volné a)Nejvýše jedno doplnění daného typu může rozvíjet tentýž slovesný výskyt … vnitřní doplnění. b)Doplnění téhož typu může jeden slovesný výskyt rozvíjet vícekrát … volné doplnění. a´)Toto doplnění může stát pouze u jisté skupiny sloves … vnitřní doplnění kromě konatele. b´)Toto doplnění může stát téměř u každého slovesa volné doplnění nebo konatel.

60 9.12.2009http://ufal.mff.cuni.cz/course/npfl09460 Druhy slovesných doplnění: (sémanticky) povinné × volitelné I povinné doplnění může ve větě chybět, pak ale je skryto nebo známo z kontextu. Pokud doplnění chybí, ale autor věty ho nemůže neznat, jde o povinné doplnění. Příklad 1: Moji přátelé přijeli. Kam? *Nevím. Odkud? Nevím. Příklad 2: Moji přátelé odjeli. Odkud? *Nevím. Kam? Nevím.

61 9.12.2009http://ufal.mff.cuni.cz/course/npfl09461 Druhy slovesných doplnění: argument × adjunct Jde v podstatě o opozici povinné × volitelné, ale posuzuje se povrchově, ne sémanticky. „Odjeli odněkud.“ „Odněkud“ sémanticky povinné, ale povrchově (spíše) volitelné. „Položil to na stůl.“ „Na stůl“ je asi povinné i povrchově, ale méně než v angličtině. Nadále budeme termínem povinné × volitelné rozumět povrchovou povinnost a volitelnost, tj. argument × adjunct.

62 9.12.2009http://ufal.mff.cuni.cz/course/npfl09462 Druhy vnitřních doplnění Konatel (agens, actor, bearer, původce) Trpitel (paciens, zasažený předmět) Adresát (addressee, nepřímý předmět) Původ (origo, origin) Výsledek (efekt, effect) Do hloubkového rámce patří všechna vnitřní doplnění a sémanticky povinná volná doplnění.

63 9.12.2009http://ufal.mff.cuni.cz/course/npfl09463 Příklad věty se všemi vnitřními doplněními Doplnění v závorkách jsou volitelná, ostatní povinná. (Téměř) všechna jsou však vnitřní (viz poznámku dole)! Matka Act předělala (dětem Adr ) loutku Pat (z kašpárka Orig ) (na čerta Ef ). –Poznámka: Tento prastarý příklad se opisuje z místa na místo, ale není přesný. „dětem“ je spíš benefaktor než adresát, tj. volné, nikoli vnitřní doplnění. Takovýhle dativ jde totiž přidat skoro všude. Skutečný adresát by to byl např. v „Matka dala dětem loutku.“

64 9.12.2009http://ufal.mff.cuni.cz/course/npfl09464 Základní třídy rámců Slovesa bez aktantů (prší) Nepřechodná slovesa (Pavel padá) Přechodná slovesa (Pavel bije Petra) Dvojpřechodná slovesa (Pavel dává Petrovi knihu) A řada dalších: při povrchovém členění asi 180 tříd?

65 9.12.2009http://ufal.mff.cuni.cz/course/npfl09465 Rámce lze automaticky odfiltrovat z korpusu Jan viděl Marii. vs. Jan viděl Marii včera kolem páté na nádraží.

66 9.12.2009http://ufal.mff.cuni.cz/course/npfl09466 Typy povinných doplnění — příklady Jmenné fráze: N4, N3, N2, N7, N1(Pnom) Předložkové fráze: R2(bez), R3(k), R4(na), R6(na), R7(s)… Zvratná zájmena „se“, „si“: PR4, PR3. Vedlejší věty: S, JS(že), JS(zda)… Infinitivy (VINF), příčestí trpná (VPAS), příslovce (DB)…


Stáhnout ppt "Dependency Parsing Daniel Zeman"

Podobné prezentace


Reklamy Google