Algebraic Effects and Handlers in Natural Language Interpretation Jiˇ r´ ı Marˇ s´ ık and Maxime Amblard LORIA, UMR 7503, Universit´ e de Lorraine, CNRS, Inria, Campus Scientifique, F-54506 Vandœuvre-l` es-Nancy, France July 17, 2014 1/19
Objectives 1. Detailed semantics for a large-scale grammar of a natural language 2. Capturing the interactions of non-local (i.e. non-compositional) semantic phenomena ◮ anaphora ◮ in-situ quantification ◮ event arguments ◮ presupposition ◮ intensionalization ◮ extraction ◮ . . . 3. Multiple semantic phenomena in a single treatment without overly complicated types and terms 2/19
In-situ quantification Barker (2002) Mary read every book. ∀ x . book ( x ) → read ( Mary , x ) � s � = o � np � = ( ι → o ) → o � read � : � np � → � np � → � s � � read � : (( ι → o ) → o ) → (( ι → o ) → o ) → o � read � = λ so . s ( λ x . o ( λ y . read ( x , y ))) 3/19
Anaphora de Groote (2006) Mary 1 read her 1 favorite book. read ( Mary , favorite-book ( Mary )) � s � = o = γ → ( γ → o ) → o � np � = ( ι → o ) → o = ( ι → γ → ( γ → o ) → o ) → γ → ( γ → o ) → o � read � : � np � → � np � → � s � � read � : (( ι → o ) → o ) → (( ι → o ) → o ) → o � read � : (( ι → γ → ( γ → o ) → o ) → γ → ( γ → o ) → o ) → (( ι → γ → ( γ → o ) → o ) → γ → ( γ → o ) → o ) → γ → ( γ → o ) → o � read � = λ so . s ( λ x . o ( λ ye φ. read ( x , y ) ∧ φ e )) 4/19
Motivation ◮ non-local phenomena + compositionality = generalizing meaning (often by abstracting over some new parameter) ◮ more non-local phenomena ⇒ more parameters ⇒ more complexity ◮ most research focuses on single phenomena 5/19
Effects in Interpretation semantic generalizations ≈ monads (Shan 2002) Montague’s PTQ ≈ evaluation order + continuations (Barker 2002) non-local phenomena ≈ computational effects ⇒ elegant explanation of their interactions (Kiselyov 2008; Shan 2005) 6/19
Effects and Handlers Introduction ◮ Effectful operation: throws an exception containing the supplied argument and the current continuation ◮ Handlers: capture the exceptions to implement the operations ◮ e.g. just by applying the continuation to some result ◮ Type-and-effect system: like Java’s checked exceptions ( op : A → B ) ∈ E Γ ⊢ V : A Γ , x : B ⊢ E M : C Γ ⊢ E op V ( λ x . M ) : C (Kammar, Lindley, and Oury 2013) 7/19
Effects and Handlers Advantages ◮ Easier to combine multiple effects in a single semantics (Cartwright and Felleisen 1994) (Kiselyov, Sabry, and Swords 2013) � A × � C E � B � C E � = C + ( op : A → B ) ∈ E “effects + handlers” : “delimited continuations” = “while” : “goto” (Bauer and Pretnar 2012) 8/19
Translating Dynamic Logic Effects and Handlers ◮ Effectful operations get : 1 → γ { get } fresh : 1 → ι { fresh } assert : o → 1 { assert } scope over : (( ι → o ) → o ) → ι { scope over } move : 1 → ι { move } ◮ Handlers drs : γ → ( o { get ; fresh ; assert | ρ } ⇒ o ρ ) tensed clause : o { scope over | ρ } ⇒ o ρ extract : α { move | ρ } ⇒ ( ι → α ρ ) 9/19
Translating Dynamic Logic Logical Connectives ∃ P = λ e φ. ∃ x . Px ( x :: e ) φ ¬ A = λ e φ. ¬ ( Ae ( λ e ′ . ⊤ )) ∧ φ e A ∧ B = λ e φ. Ae ( λ e ′ . Be ′ φ ) 10/19
Translating Dynamic Logic Logical Connectives ∃ P = λ e φ. ∃ x . Px ( x :: e ) φ ∃ P = P ( fresh ()) ¬ A = λ e φ. ¬ ( Ae ( λ e ′ . ⊤ )) ∧ φ e ¬ A = ¬ ( with drs ( get ()) handle A ) A ∧ B = λ e φ. Ae ( λ e ′ . Be ′ φ ) A ∧ B = A ∧ B 10/19
Translating Dynamic Logic Logical Connectives ∃ P = λ e φ. ∃ x . Px ( x :: e ) φ ∃ P = P ( fresh ()) ¬ A = λ e φ. ¬ ( Ae ( λ e ′ . ⊤ )) ∧ φ e ¬ A = ¬ ( with drs ( get ()) handle A ) A ∧ B = λ e φ. Ae ( λ e ′ . Be ′ φ ) A ∧ B = A ∧ B A → B = ¬ ( A ∧ ¬ B ) ∀ P = ¬ ∃ x . ¬ Px 10/19
Translating Dynamic Logic Lexical Items � she � = λ ke φ. k ( sel she ( e )) e φ � something � = λ k . ∃ x . ( k x ) = λ ke φ. ∃ x . kx ( x :: e ) φ � every � = λ nk . ∀ x . ( n x ) → ( k x ) � read � = λ SO . S ( λ s . O ( λ oe φ. read ( s , o ) ∧ φ e )) 11/19
Translating Dynamic Logic Lexical Items � she � = λ ke φ. k ( sel she ( e )) e φ � she � = λ k . k ( sel she ( get ())) � something � = λ k . ∃ x . ( k x ) = λ ke φ. ∃ x . kx ( x :: e ) φ � something � = λ k . ∃ x . ( k x ) = λ k . k ( fresh ()) � every � = λ nk . ∀ x . ( n x ) → ( k x ) � every � = λ nk . ∀ x . ( n x ) → ( k x ) � read � = λ SO . S ( λ s . O ( λ oe φ. read ( s , o ) ∧ φ e )) � read � = λ SO . S ( λ s . O ( λ o . read ( s , o ))) 11/19
Translating Dynamic Logic Lexical Items � she � = λ ke φ. k ( sel she ( e )) e φ � she � = λ k . k ( sel she ( get ())) � she � = { sel she ( get ()) } � something � = λ k . ∃ x . ( k x ) = λ ke φ. ∃ x . kx ( x :: e ) φ � something � = λ k . ∃ x . ( k x ) = λ k . k ( fresh ()) � something � = { fresh () } � every � = λ nk . ∀ x . ( n x ) → ( k x ) � every � = λ nk . ∀ x . ( n x ) → ( k x ) � every � = λ n . { scope over ( λ k . ∀ x . ( n x ) → ( k x )) } � read � = λ SO . S ( λ s . O ( λ oe φ. read ( s , o ) ∧ φ e )) � read � = λ SO . S ( λ s . O ( λ o . read ( s , o ))) � read � = λ s t o t . { with tensed clause handle read ( s t ! , o t !) } 11/19
Translating Dynamic Logic Lexical Items (cont’d) � some � = λ nk . ∃ x . ( n x ) ∧ ( k x ) � who � = λ rnx . nx ∧ r ( λ k . kx ) 12/19
Translating Dynamic Logic Lexical Items (cont’d) � some � = λ nk . ∃ x . ( n x ) ∧ ( k x ) � some � = λ nk . ∃ x . ( n x ) ∧ ( k x ) = λ nk . k ( let x = fresh () in let () = assert ( n x ) in x ) � who � = λ rnx . nx ∧ r ( λ k . kx ) � who � = λ rnx . nx ∧ r ( λ k . kx ) 12/19
Translating Dynamic Logic Lexical Items (cont’d) � some � = λ nk . ∃ x . ( n x ) ∧ ( k x ) � some � = λ nk . ∃ x . ( n x ) ∧ ( k x ) = λ nk . k ( let x = fresh () in let () = assert ( n x ) in x ) � some � = λ n . { scope over ( λ k . ∃ x . ( n x ) ∧ ( k x )) } = λ n . { let x = fresh () in let () = assert ( n x ) in x } � who � = λ rnx . nx ∧ r ( λ k . kx ) � who � = λ rnx . nx ∧ r ( λ k . kx ) � who � = λ rnx . nx ∧ rx 12/19
Treating Extraction as an Effect � who � : � s � { move | ρ } → � n � → � n � ρ � who � = λ r t n .λ x . let r = with extract handle r t ! in ( n x ) ∧ ( r x ) r t : o { move | ρ } r : ι → o ρ n : ι → o x : ι � ǫ � : � np � { move } � ǫ � = { move () } 13/19
Example - Syntax Every farmer who owns a donkey beats it. 14/19
Example - Semantics Every farmer who owns a donkey beats it. 15/19
Conclusion We have: ◮ motivated the use of algebraic effects and handlers in semantics. ◮ translated de Groote’s continuation-based dynamic logic (de Groote 2006) to effects, reconstructing notions from DRT. ◮ treated extraction as an effect in interpretation instead of using hypothetical reasoning and lambda abstractions in the syntax. 16/19
Future Work We would like to: ◮ show how effects and handlers apply to the other non-local phenomena (presupposition, event arguments, optional items, intensionalization). ◮ build a fragment that combines all of these. ◮ design a calculus with algebraic effects and handlers and a suitable evaluation order (CBV vs CBN). 17/19
Thank You Questions? Would you like to know more? http://jirka.marsik.me/research/ algebraic-effects-and-handlers-in-natural-language-interpretation 18/19
References Barker, Chris (2002). “Continuations and the nature of quantification”. Bauer, Andrej and Matija Pretnar (2012). “Programming with algebraic effects and handlers”. Cartwright, Robert and Matthias Felleisen (1994). “Extensible denotational language specifications”. de Groote, Philippe (2006). “Towards a montagovian account of dynamics”. Kammar, Ohad, Sam Lindley, and Nicolas Oury (2013). “Handlers in action”. Kiselyov, Oleg (2008). “Call-by-name linguistic side effects”. Kiselyov, Oleg, Amr Sabry, and Cameron Swords (2013). “Extensible effects: an alternative to monad transformers”. Shan, Chung-chieh (2002). “Monads for natural language semantics”. Shan, Chung-chieh (2005). “Linguistic Side Effects”. 19/19
Recommend
More recommend