Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect semantics for ccg >T when the argument semantics is a lambda abstraction #2665

Open
MatsRooth opened this issue Feb 3, 2021 · 0 comments

Comments

@MatsRooth
Copy link

This demonstrates the problem and a solution using https://github.com/MatsRooth/nltk/blob/develop/nltk/ccg/prescoped.py and https://github.com/MatsRooth/nltk/blob/develop/nltk/ccg/logic.py.

Lexicon

Justin => NP {\P.P(j)}
Keisha => NP {\P.P(k)}
admires => ((S\NP)/NP) {\Y Z.Z(\z.Y(\y.admire(z,y)))}
complains => (S\NP) {complain}
everybody => NP {\P.all x.(person(x) -> P(x))}
somebody => NP {\P.exists x.(person(x) & P(x))}

Derivation for 'somebody admires everybody' obtained with ApplicationRuleSet
The semantics is the expected one.

              somebody                                 admires                                everybody
 NP {\P.exists x.(person(x) & P(x))}  ((S\NP)/NP) {\Y Z.Z(\z.Y(\y.admire(z,y)))}  NP {\P.all x.(person(x) -> P(x))}
                                     ------------------------------------------------------------------------------->
                                                   (S\NP) {\Z.Z(\z.all x.(person(x) -> admire(z,x)))}
--------------------------------------------------------------------------------------------------------------------<
                           S {exists x.(person(x) & all z1.(person(z1) -> admire(x,z1)))}

Derivation for 'somebody admires everybody' obtained with ForwardTypeRaiseRule + ForwardApplication. The result has scrambled scopes.

                somebody                                  admires                                everybody
 NP {\P.F(exists x.(person(x) & P(x)))}  ((S\NP)/NP) {\Y Z.Z(\z.Y(\y.admire(z,y)))}  NP {\P.all x.(person(x) -> P(x))}
---------------------------------------->T
(S/(S\NP)) {\F P.F(exists x.(person(x) & P(x)))}
                                        ------------------------------------------------------------------------------->
                                                      (S\NP) {\Z.Z(\z.all x.(person(x) -> admire(z,x)))}
----------------------------------------------------------------------------------------------------------------------->
                        S {\P.exists x.(person(x) & P(x))(\z.all x.(person(x) -> admire(z,x)))}

Derivation for 'Justin admires Justin' obtained with ForwardTypeRaiseRule + ForwardApplication.
The result is ill-formed, and a free F appears.

     Justin                        admires                        Justin
 NP {\P.F(P(j))}  ((S\NP)/NP) {\Y Z.Z(\z.Y(\y.admire(z,y)))}  NP {\P.F(P(j))}
----------------->T
(S/(S\NP)) {\F P.F(P(j))}
                 ------------------------------------------------------------->
                               (S\NP) {\Z.Z(\z.F(admire(z,j)))}
------------------------------------------------------------------------------>
                        S {\P.P(j,\z.F(admire(z,j)))}

The problem is fixed by this change in nltk/ccg/logic.py. I'm not clear enough about
the chart design to say if the change has any unwelcome consequences. This constructs
a closed type raiser, applies it to the input semantics, and normalizes.

def compute_type_raised_semantics(semantics):
    varf = Variable('F')
    vara = Variable('z')
    expf = FunctionVariableExpression(varf)
    expa = FunctionVariableExpression(vara)

    raiser = LambdaExpression(vara,LambdaExpression(varf,ApplicationExpression(expf, expa)))

    semantics2 = ApplicationExpression(raiser,semantics)
    return semantics2.simplify()

Derivation for 'somebody admires everybody' obtained with ForwardTypeRaiseRule + ForwardApplication.

              somebody                                 admires                                everybody
 NP {\P.exists x.(person(x) & P(x))}  ((S\NP)/NP) {\Y Z.Z(\z.Y(\y.admire(z,y)))}  NP {\P.all x.(person(x) -> P(x))}
------------------------------------->T
(S/(S\NP)) {\F.F(\P.exists x.(person(x) & P(x)))}
                                     ------------------------------------------------------------------------------->
                                                   (S\NP) {\Z.Z(\z.all x.(person(x) -> admire(z,x)))}
-------------------------------------------------------------------------------------------------------------------->
                           S {exists x.(person(x) & all z2.(person(z2) -> admire(x,z2)))}

Derivation for 'Justin admires Justin' obtained with ForwardTypeRaiseRule + ForwardApplication.

    Justin                      admires                       Justin
 NP {\P.P(j)}  ((S\NP)/NP) {\Y Z.Z(\z.Y(\y.admire(z,y)))}  NP {\P.P(j)}
-------------->T
(S/(S\NP)) {\F.F(\P.P(j))}
              ---------------------------------------------------------->
                            (S\NP) {\Z.Z(\z.admire(z,j))}
------------------------------------------------------------------------>
                            S {admire(j,j)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant