Algebraic Effects and Handlers in Natural Language Interpretation - - PowerPoint PPT Presentation

algebraic effects and handlers in natural language
SMART_READER_LITE
LIVE PREVIEW

Algebraic Effects and Handlers in Natural Language Interpretation - - PowerPoint PPT Presentation

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 Vanduvre-l` es-Nancy, France July 17,


slide-1
SLIDE 1

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

slide-2
SLIDE 2

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
  • verly complicated types and terms

2/19

slide-3
SLIDE 3

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

slide-4
SLIDE 4

Anaphora

de Groote (2006)

Mary1 read her1 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

slide-5
SLIDE 5

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

slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

Effects and Handlers

Advantages

◮ Easier to combine multiple effects in a single semantics

(Cartwright and Felleisen 1994) (Kiselyov, Sabry, and Swords 2013) CE = C +

  • (op:A→B)∈E

A × CEB “effects + handlers” : “delimited continuations” = “while” : “goto” (Bauer and Pretnar 2012) 8/19

slide-9
SLIDE 9

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

slide-10
SLIDE 10

Translating Dynamic Logic

Logical Connectives

∃ P = λeφ.∃x.Px(x :: e)φ ¬ A = λeφ.¬(Ae(λe′.⊤)) ∧ φe A ∧ B = λeφ.Ae(λe′.Be′φ) 10/19

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

Translating Dynamic Logic

Lexical Items

she = λkeφ.k(selshe(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

slide-14
SLIDE 14

Translating Dynamic Logic

Lexical Items

she = λkeφ.k(selshe(e))eφ she = λk.k(selshe(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

slide-15
SLIDE 15

Translating Dynamic Logic

Lexical Items

she = λkeφ.k(selshe(e))eφ she = λk.k(selshe(get ())) she = {selshe(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 = λstot.{with tensed clause handle read(st!, ot!)} 11/19

slide-16
SLIDE 16

Translating Dynamic Logic

Lexical Items (cont’d)

some = λnk. ∃ x.(n x) ∧ (k x) who = λrnx.nx ∧ r(λk.kx) 12/19

slide-17
SLIDE 17

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

slide-18
SLIDE 18

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

slide-19
SLIDE 19

Treating Extraction as an Effect

who : s{move|ρ} → n → nρ who = λrtn.λx. let r = with extract handle rt! in (n x) ∧ (r x) rt : o{move|ρ} r : ι → oρ n : ι → o x : ι ǫ : np{move} ǫ = {move ()} 13/19

slide-20
SLIDE 20

Example - Syntax

Every farmer who owns a donkey beats it.

14/19

slide-21
SLIDE 21

Example - Semantics

Every farmer who owns a donkey beats it.

15/19

slide-22
SLIDE 22

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

slide-23
SLIDE 23

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

slide-24
SLIDE 24

Thank You

Questions? Would you like to know more?

http://jirka.marsik.me/research/ algebraic-effects-and-handlers-in-natural-language-interpretation

18/19

slide-25
SLIDE 25

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