How can we automate the process of associating semantic representations with natural language expressions?

2.1 Compositionality

2.2 Two experiments

Experiment 1

%%%%%%%%%%%%%%%%%

% Syntax-Semantics Rules 

%%%%%%%%%%%%%%%%%
% quantifier free sentences

s(Sem)--> np(SemNP), vp(Sem), 
   {
    arg(1,Sem,SemNP)
   }.

np(Sem)--> pn(Sem).

vp(Sem)--> tv(Sem), np(SemNP), 
   { 
    arg(2,Sem,SemNP)
   }.

%%%%%%%%%%%%%%%%%

% quantifier sentences

s(Sem)--> np(Sem), vp(SemVP), 
   {
    arg(1,SemVP,X),
    arg(1,Sem,X),
    arg(2,Sem,Matrix),
    arg(2,Matrix,SemVP)
   }.
            

np(Sem)--> det(Sem), noun(SemNoun), 
   {
    arg(1,SemNoun,X),
    arg(1,Sem,X),
    arg(2,Sem,Matrix),
    arg(1,Matrix,SemNoun)
   }.


vp(Sem)--> tv(SemTV), np(Sem), 
   {
    arg(2,SemTV,X),
    arg(1,Sem,X),
    arg(2,Sem,Matrix),
    arg(2,Matrix,SemTV)
   }.
   
   
vp(Sem)--> iv(Sem).

%%%%%%%%%%%%%%%%%
% Lexicon
%%%%%%%%%%%%%%%%%

%  Proper Names

pn(mia)--> [mia].

%   Transitive Verbs

tv(love(_,_))--> [loves].

%  Intransitive Verbs

iv(snort(_))--> [snorts].

%  Determiners

det(exists(_,_ & _))--> [a].

% Nouns

noun(woman(_))--> [woman].
  • Erklären Sie, wie die semantische Information in den syntaktischen Regeln verarbeitet wird.
  • Warum führen die zwei NP-Regeln zu Problemen?
  • Generiert diese Grammatik alle gewünschten Sätze mit ihren semantischen Repräsentationen? Generiert sie nur die gewünschten Repräsentationen?

Experiment 2

* Wie arbeitet die Regel NP -> PN?

2.3 The Lambda Calculus

2.4 Implementing Lambda Calculus

Lambda expressions in Prolog

  • \(\lambda x. E\) repräsentieren wir als lam(x,E).
  • \(\mathcal{F}@\mathcal{A}\) repräsentieren wir als app(F,A).

Grammatikregeln:

s(app(NP,VP))--> np(NP), vp(VP).
np(PN)--> pn(PN).
np(app(Det,Noun))--> det(Det), noun(Noun).
vp(IV)--> iv(IV).
vp(app(TV,NP))--> tv(TV), np(NP).

Lexikoneinträge:

noun(lam(X,woman(X)))--> [woman].
iv(lam(X,walk(X)))--> [walks].
pn(lam(X,app(X,mia)))--> [mia].
det(lam(U,lam(V,all(X,imp(app(U,X),app(V,X))))))--> [every].
det(lam(U,lam(V,some(X,and(app(U,X),app(V,X))))))--> [a].

Anfragen:

?- s(Sem,[mia,walks],[]).

Aufgabe: Laden Sie die Datei experiment3.pl und testen Sie ein paar Sätze.

Implementing \(\beta\)-conversion

  • Problem: Der semantische Output gibt lediglich an, wie die Information zu verkleben ist, um die semantische Repräsentation des Satzes zu erhalten.
  • Ziel: Ausführung aller \(\beta\)-Konversionen.
  • Idee: Stack zur Verwaltung der Argumente.
Expression                                          Stack
app(app(lam(Z,lam(Y,invite(Y,Z))),mia),vincent)        []
app(lam(Z,lam(Y,invite(Y,Z))),mia)              [vincent]
lam(Z,lam(Y,invite(Y,Z)))                  [mia, vincent]
lam(Y,invite(Y,mia))                            [vincent]
invite(vincent,mia)                                    []

Aufgabe: Übertragen Sie die Darstellung von der Präfix- in die Infixnotation und erklären Sie wie der Stack eingesetzt wird (was geschieht bei funktionaler Applikation, was bei Abstraktion?).

Das folgende Bild zeigt, die Aufspaltung eines Ausdrucks, der keine funktionale Applikatoin ist:

Implementierung:


% ?- betaConvert(app(lam(U,app(U,mia)),lam(X,smoke(X))),Converted).
% introducing empty stack
betaConvert(X,Y):-
   betaConvert(X,Y,[]).

% no change for variables   
betaConvert(X,Y,[]):-
   var(X), !,
   Y=X.

% expression is application => push argument to stack
betaConvert(Expression,Result,Stack):- 
   nonvar(Expression),
   Expression = app(Functor,Argument),
   nonvar(Functor)
   alphaConvert(Functor,Converted),
   betaConvert(Converted,Result,[Argument|Stack]).

% expression is abstraction => pop argument from stack
betaConvert(Expression,Result,[X|Stack]):-
   nonvar(Expression),
   Expression = lam(X,Formula),
   betaConvert(Formula,Result,Stack), !.

% other expression 
% => break down complex expression 
betaConvert(Expression,Result,[]):-
   nonvar(Expression), 
   \+(Expression= app(X,_), nonvar(X)),
   compose(Expression,Functor,SubExpressions),
   betaConvertList(SubExpressions,ResultSubExpressions),
   compose(Result,Functor,ResultSubExpressions).

% beta convert lists
betaConvertList([],[]).

betaConvertList([Expression|Others], [Result|Results]) :- 
     betaConvert(Expression,Result),
     betaConvertList(Others,Results).
  • Laden Sie experiment3.pl und testen Sie einige Anfragen wie ?-s(Sem,[mia,walks],[]),betaConvert(Sem,SemConv).
  • Erklären Sie was \(\alpha\)-Konversion macht und warum sie wichtig ist. Experimentieren Sie indem Sie den \(\alpha\)-Konversionsschritt auskommentieren.
% ?- alphaConvert(some(X,and(man(X),all(X,woman(X)))),R).
% initializing list of substitutions and difference list of free variables
alphaConvert(F1,F2):-
   alphaConvert(F1,[],[]-_,F2).

% expression is a variable
alphaConvert(X,Sub,Free1-Free2,Y):-
   var(X), 
   (
      memberList(sub(Z,Y),Sub),
      X==Z, !,
      Free2=Free1
   ;
      Y=X,
      Free2=[X|Free1]
   ).

% expression is a some(_,_)
alphaConvert(Expression,Sub,Free1-Free2,some(Y,F2)):-
   nonvar(Expression),
   Expression = some(X,F1),
   alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F2).

% expression is a all(_,_)
alphaConvert(Expression,Sub,Free1-Free2,all(Y,F2)):- 
   nonvar(Expression),
   Expression = all(X,F1),
   alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F2).

% expression is a lam(_,_)
alphaConvert(Expression,Sub,Free1-Free2,lam(Y,F2)):- 
   nonvar(Expression),
   Expression = lam(X,F1),
   alphaConvert(F1,[sub(X,Y)|Sub],Free1-Free2,F2).

% expression is something else
alphaConvert(F1,Sub,Free1-Free2,F2):-
   nonvar(F1),
   \+ F1 = some(_,_),
   \+ F1 = all(_,_),
   \+ F1 = lam(_,_),
   compose(F1,Symbol,Args1),
   alphaConvertList(Args1,Sub,Free1-Free2,Args2),
   compose(F2,Symbol,Args2).


alphaConvertList([],_,Free-Free,[]).

alphaConvertList([X|L1],Sub,Free1-Free3,[Y|L2]):-
   alphaConvert(X,Sub,Free1-Free2,Y),
   alphaConvertList(L1,Sub,Free2-Free3,L2).
  • Formulieren Sie Anfragen an das Prädikat alphaConvert/2 und stellen Sie sicher, dass Sie es verstanden haben.
alphabeticVariants(Term1,Term2):-
  alphaConvert(Term1,[),[]-Free1,Term3),
  alphaConvert(Term2,[],[]-Free2,Term4),
  Free1==Free2,
  numbervars(Term3,0,_),
  numbervars(Term4,0,_),
  Term3=Term4.

Wozu benötigt man das Prädikat alphabeticVariants/2?

2.5 Grammar Engineering

Exercise 2.5.1 Find out how copula verbs are handled in the lexicon and grammar, and how the semantic representations for sentences like Mia is a boxer and Mia is not Vincent are generated.

Exercise 2.5.2 Extend the grammar so that it handles expressions of the form Vincent is male, Mia and Vincent are cool, and Marsellus or Butch is big.

Exercise 2.5.3 Extend the grammar so that it handles expressions of the form Vincent and Jules are in a restaurant and Butch is on a motorbike.

Exercise 2.5.4 Add the preposition without to the lexicon, and define a new semantic macro that takes the implicit negation of this preposition into account. For instance, a man without a weapon should receive a representation such as :\(\exists X (man(X) \wedge \neg \exists Y (weapon(Y) \wedge with(X,Y)))\).

Exercise 2.5.5 Extend the grammar (the syntax rules and the lexicon) to cover plural forms of nouns. Introduce a new feature in the lexical entries to express number information. Then add entries for determiners and classify them as combining with singular nouns only (for instance the determiner a), combining with plural nouns only (for instance both, or all), or combining with either (for example the).