Skip to content

Commit 9ba6b6a

Browse files
author
Pascual Martinez-Gomez
committed
First merge from sts_merge: uploaded files
2 parents 494463c + b39023f commit 9ba6b6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+7187
-1848
lines changed

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and install the packages in the virtual environment with `pip`:
1111

1212
```bash
1313
git clone https://github.com/mynlp/ccg2lambda.git
14+
cd ccg2lambda
1415
virtualenv --no-site-packages --distribute -p /usr/bin/python3 py3
1516
source py3/bin/activate
1617
pip install lxml simplejson pyyaml -I nltk==3.0.5
@@ -25,7 +26,6 @@ python -c "import nltk; nltk.download('wordnet')"
2526
To ensure that all software is working as expected, you can run the tests:
2627

2728
```bash
28-
cd ccg2lambda/
2929
python scripts/run_tests.py
3030
```
3131
(all tests should pass, except a few expected failures).
@@ -46,10 +46,10 @@ Our system assigns semantics to CCG structures. At the moment, we support C&C fo
4646

4747
### Installing [C&C parser](http://www.cl.cam.ac.uk/~sc609/candc-1.00.html) (for English)
4848

49-
In order to install the C&C parser, you may need to register, download the parser and the models, and follow their instructions to set it up. For ccg2lambda to find the C&C parser, please create a file `candc_location.txt` with the path to the C&C parser:
49+
In order to install the C&C parser, you may need to register, download the parser and the models, and follow their instructions to set it up. For ccg2lambda to find the C&C parser, please create a file `en/candc_location.txt` with the path to the C&C parser:
5050

5151
```bash
52-
echo "/path/to/candc-1.00/" > candc_location.txt
52+
echo "/path/to/candc-1.00/" > en/candc_location.txt
5353
```
5454

5555
### Installing [Jigg parser](https://github.com/mynlp/jigg) (for Japanese)
@@ -60,7 +60,7 @@ Simply do:
6060
./ja/download_dependencies.sh
6161
```
6262

63-
The command above will download Jigg, its models, and create the file `jigg_location.txt` where the path to Jigg is specified. That is all.
63+
The command above will download Jigg, its models, and create the file `ja/jigg_location.txt` where the path to Jigg is specified. That is all.
6464

6565
## Using the Semantic Parser
6666

@@ -86,16 +86,16 @@ First we need to obtain the CCG derivations (parse trees) of the sentences
8686
in the text file using C&C and convert its XML format into Jigg's XML format:
8787

8888
```bash
89-
cat sentences.txt | perl tokenizer.perl -l en 2>/dev/null > sentences.tok
89+
cat sentences.txt | sed -f en/tokenizer.sed > sentences.tok
9090
/path/to/candc-1.00/bin/candc --models /path/to/candc-1.00/models --candc-printer xml --input sentences.tok > sentences.candc.xml
91-
python candc2transccg.py sentences.candc.xml > sentences.xml
91+
python en/candc2transccg.py sentences.candc.xml > sentences.xml
9292
```
9393

9494
Then, we are ready to obtain the semantic representations by using semantic
9595
templates and the CCG derivations obtained above:
9696

9797
```bash
98-
python semparse.py sentences.xml semantic_templates_en_emnlp2015.yaml sentences.sem.xml
98+
python scripts/semparse.py sentences.xml en/semantic_templates_en_emnlp2015.yaml sentences.sem.xml
9999
```
100100

101101
The semantic representations are in the `sentences.sem.xml` file,
@@ -136,7 +136,7 @@ pipe it to a theorem prover (Coq) and judge the entailment
136136
relation, you can run the following command:
137137

138138
```bash
139-
python prove.py sentences.sem.xml --graph_out graphdebug.html
139+
python scripts/prove.py sentences.sem.xml --graph_out graphdebug.html
140140
```
141141

142142
That command will output `yes` (entailment relation - the conclusion
@@ -163,7 +163,7 @@ For example, to visualize the CCG trees only (without
163163
semantic representations):
164164

165165
```bash
166-
python visualize.py sentences.xml > sentences.html
166+
python scripts/visualize.py sentences.xml > sentences.html
167167
```
168168

169169
and then open the file `sentences.html` with your favourite web browser.
@@ -173,15 +173,16 @@ You should be able to see something like this:
173173

174174
## Reproducibility
175175

176-
If you wish to reproduce our results reported in EMNLP 2015 or EMNLP 2016, please follow the instructions below:
176+
If you wish to reproduce our reported results, please follow the instructions below:
177177

178178
* [Experiments on FraCaS at EMNLP 2015](en/fracas.md)
179179
* [Experiments on JSeM at EMNLP 2016](ja/jsem.md)
180+
* [Experiments on SICK at EACL 2017](en/sick.md)
180181
* [Experiments on SICK STS at EMNLP 2017](en/sick_sts.md)
181182

182183
## Interpreting (and writing your own) semantic templates.
183184

184-
You can find our semantic templates in `semantic_templates_en.yaml`. Here are some notes:
185+
You can find one of our semantic templates in `en/semantic_templates_en.yaml`. Here are some notes:
185186

186187
1. Each Yaml block is a rule. If the rule matches the attributes of a CCG node, then the semantic template specified by "semantics" is applied. It is possible to write an arbitrary set of field names and their values. For example, you could specify the "category" of the CCG node and the surface "surf" form of a word (in case the CCG node is a leaf). Only the "category" field and the "semantics" field are compulsory.
187188
2. If you underspecify the characteristics of a CCG node, the semantic rule will match more general CCG nodes. It is also possible to underspecify the features of syntactic categories.
@@ -217,6 +218,24 @@ If you use this software or the semantic templates for your work, please conside
217218
}
218219
```
219220

221+
## A mechanism to inject axioms on-demand:
222+
223+
* Pascual Martínez-Gómez, Koji Mineshima, Yusuke Miyao, Daisuke Bekki. On-demand Injection of Lexical Knowledge for Recognising Textual Entailment. Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics, pages 710-720, Valencia, Spain, 3-7 April, 2017. [pdf](http://www.aclweb.org/anthology/E17-1067)
224+
225+
```
226+
@InProceedings{martinezgomez-EtAl:2017:EACLlong,
227+
author = {Mart\'{i}nez-G\'{o}mez, Pascual and Mineshima, Koji and Miyao, Yusuke and Bekki, Daisuke},
228+
title = {On-demand Injection of Lexical Knowledge for Recognising Textual Entailment},
229+
booktitle = {Proceedings of the 15th Conference of the European Chapter of the Association for Computational Linguistics: Volume 1, Long Papers},
230+
month = {April},
231+
year = {2017},
232+
address = {Valencia, Spain},
233+
publisher = {Association for Computational Linguistics},
234+
pages = {710--720},
235+
url = {http://www.aclweb.org/anthology/E17-1067}
236+
}
237+
```
238+
220239
## The English semantic model declared as semantic templates:
221240

222241
* Koji Mineshima, Pascual Martínez-Gómez, Yusuke Miyao, Daisuke Bekki. Higher-order logical inference with compositional semantics. Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing, pages 2055–2061, Lisbon, Portugal, 17-21 September 2015. [pdf](http://www.aclweb.org/anthology/D15-1244)

coqlib.v

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
(* Basic types *)
2+
Parameter Entity : Type.
3+
Parameter Event : Type.
4+
5+
Parameter Rel : Entity -> Entity -> Prop.
6+
Parameter Prog : Prop -> Prop.
7+
Parameter two : Entity -> Prop.
8+
Parameter _people : Entity -> Prop.
9+
10+
(* Temporal operators *)
11+
Parameter Hold : Event -> Prop.
12+
Parameter Cul : Event -> Prop.
13+
Parameter Past : Event -> Prop.
14+
Parameter Future : Event -> Prop.
15+
16+
(* Thematic roles *)
17+
Parameter Subj : Event -> Entity.
18+
Parameter Top : Event -> Entity.
19+
Parameter Acc : Event -> Entity.
20+
Parameter AccI : Event -> Prop -> Prop.
21+
Parameter AccE : Event -> Event.
22+
Parameter Dat : Event -> Entity.
23+
Parameter Attr : Event -> Entity.
24+
Parameter Deg : Event -> Entity.
25+
26+
(* for underspecified terms *)
27+
Parameter ArgOf : Entity -> Entity -> Prop.
28+
29+
Parameter _in_front_of : Event -> Entity -> Prop.
30+
31+
(* Generalized quantifiers *)
32+
Parameter Most : (Entity -> Prop) -> (Entity -> Prop) -> Prop.
33+
34+
Notation "'most' x ; P , Q" := (Most (fun x => P) (fun x => Q))
35+
(at level 30, x ident, right associativity) : type_scope.
36+
37+
Axiom most_ex_import :
38+
forall (F G: Entity -> Prop),
39+
(Most F G -> exists x, F x /\ G x).
40+
41+
Axiom most_consv :
42+
forall (F G: Entity -> Prop),
43+
(Most F G -> Most F (fun x => (F x /\ G x))).
44+
45+
Axiom most_rightup :
46+
forall (F G H: Entity -> Prop),
47+
((Most F G) ->
48+
(forall x, G x -> H x) -> (Most F H)).
49+
50+
Hint Resolve most_ex_import most_consv most_rightup.
51+
52+
(* veridical predicates *)
53+
Parameter _true : Prop -> Prop.
54+
55+
Axiom veridical_true : forall P, (_true P -> P).
56+
57+
Ltac solve_veridical_true :=
58+
match goal with
59+
H : _true _ |- _
60+
=> try apply veridical_true in H
61+
end.
62+
63+
(* anti-veridical predicates *)
64+
Parameter _false : Prop -> Prop.
65+
66+
Axiom antiveridical_false : forall P, (_false P -> ~P).
67+
68+
Hint Resolve antiveridical_false.
69+
70+
Ltac solve_antiveridical_false :=
71+
match goal with
72+
H : _false _ |- _
73+
=> try apply antiveridical_false in H
74+
end.
75+
76+
(* implicative verbs *)
77+
Parameter _manage : Event -> Prop.
78+
79+
Axiom implicative_manage : forall v : Event, forall P : Prop, AccI v P -> _manage v -> P.
80+
81+
Ltac solve_implicative_manage :=
82+
match goal with
83+
H1 : _manage ?v, H2 : AccI ?v _ |- _
84+
=> try apply implicative_manage in H2
85+
end.
86+
87+
Parameter _fail : Event -> Prop.
88+
89+
Axiom implicative_fail : forall v : Event, forall P : Prop, AccI v P -> _fail v -> ~ P.
90+
91+
Ltac solve_implicative_fail :=
92+
match goal with
93+
H : _fail ?v, H2 : AccI ?v _ |- _
94+
=> try apply implicative_fail in H2
95+
end.
96+
97+
(* factive verbs *)
98+
Parameter _know : Event -> Prop.
99+
100+
Axiom factive_know : forall v : Event, forall P : Prop, AccI v P -> _know v -> P.
101+
102+
Ltac solve_factive :=
103+
match goal with
104+
H1 : _know ?v, H2 : AccI ?v _ |- _
105+
=> try apply factive_know in H2
106+
end.
107+
108+
(* privative adjectives *)
109+
Parameter _former : Prop -> Prop.
110+
Axiom privative_former : forall P, (_former P -> ~P).
111+
112+
Ltac solve_privative_former :=
113+
match goal with
114+
H : _former _ |- _
115+
=> try apply privative_former in H
116+
end.
117+
118+
Parameter _fake : Prop -> Prop.
119+
Axiom privative_fake : forall P, (_fake P -> ~P).
120+
121+
Ltac solve_privative_fake :=
122+
match goal with
123+
H : _fake _ |- _
124+
=> try apply privative_fake in H
125+
end.
126+
127+
(* before and after *)
128+
Parameter _before : Event -> Event -> Prop.
129+
Parameter _after : Event -> Event -> Prop.
130+
131+
Axiom transitivity_before : forall v1 v2 v3 : Event,
132+
_before v1 v2 -> _before v2 v3 -> _before v1 v3.
133+
134+
Axiom transitivity_after : forall v1 v2 v3 : Event,
135+
_after v1 v2 -> _after v2 v3 -> _after v1 v3.
136+
137+
Axiom before_after : forall v1 v2 : Event,
138+
_before v1 v2 -> _after v2 v1.
139+
140+
Axiom after_before : forall v1 v2 : Event,
141+
_after v1 v2 -> _before v2 v1.
142+
143+
Hint Resolve transitivity_before transitivity_after before_after after_before.
144+
145+
146+
(* Preliminary tactics *)
147+
148+
Ltac apply_ent :=
149+
match goal with
150+
| [x : Entity, H : forall x : Entity, _ |- _]
151+
=> apply H; clear H
152+
end.
153+
154+
Ltac eqlem_sub :=
155+
match goal with
156+
| [ H1: ?A ?t, H2: forall x, @?D x -> @?C x |- _ ]
157+
=> match D with context[ A ]
158+
=> assert(C t); try (apply H2 with (x:= t)); clear H2
159+
end
160+
end.
161+
162+
Axiom unique_role : forall v1 v2 : Event, Subj v1 = Subj v2 -> v1 = v2.
163+
Ltac resolve_unique_role :=
164+
match goal with
165+
H : Subj ?v1 = Subj ?v2 |- _
166+
=> repeat apply unique_role in H
167+
end.
168+
169+
Ltac substitution :=
170+
match goal with
171+
| [H1 : _ = ?t |- _ ]
172+
=> try repeat resolve_unique_role; try rewrite <- H1 in *; subst
173+
| [H1 : ?t = _ |- _ ]
174+
=> try resolve_unique_role; try rewrite H1 in *; subst
175+
end.
176+
177+
Ltac exchange :=
178+
match goal with
179+
| [H1 : forall x, _, H2 : forall x, _ |- _]
180+
=> generalize dependent H2
181+
end.
182+
183+
Ltac exchange_equality :=
184+
match goal with
185+
| [H1 : _ = _, H2: _ = _ |- _]
186+
=> generalize dependent H2
187+
end.
188+
189+
Ltac clear_pred :=
190+
match goal with
191+
| [H1 : ?F ?t, H2 : ?F ?u |- _ ]
192+
=> clear H2
193+
end.
194+
195+
Ltac solve_false :=
196+
match goal with
197+
| [H : _ -> False |- False]
198+
=> apply H
199+
end.
200+
201+
(* Main tactics *)
202+
203+
Ltac nltac_init :=
204+
try(intuition;
205+
try solve_false;
206+
firstorder;
207+
repeat subst;
208+
firstorder).
209+
210+
Ltac nltac_base :=
211+
try nltac_init;
212+
try (eauto; eexists; firstorder);
213+
try repeat substitution;
214+
try (subst; eauto; firstorder; try congruence).
215+
216+
Ltac nltac_axiom :=
217+
try first
218+
[solve_veridical_true |
219+
solve_antiveridical_false |
220+
solve_implicative_manage |
221+
solve_implicative_fail |
222+
solve_factive |
223+
solve_privative_former |
224+
solve_privative_fake
225+
].
226+
227+
Ltac nltac_set :=
228+
repeat (nltac_init;
229+
try repeat substitution;
230+
try exchange_equality;
231+
try repeat substitution;
232+
try eqlem_sub).
233+
234+
Ltac nltac_set_exch :=
235+
repeat (nltac_init;
236+
try repeat substitution;
237+
try apply_ent;
238+
try exchange;
239+
try eqlem_sub).
240+
241+
Ltac nltac_final :=
242+
try solve [repeat nltac_base | clear_pred; repeat nltac_base].
243+
244+
Axiom urevent : Event.
245+
Ltac ap_event := try apply urevent.
246+
247+
Ltac solve_gq :=
248+
match goal with
249+
H : Most _ _ |- _
250+
=> let H0 := fresh in
251+
try solve [
252+
pose (H0 := H); eapply most_ex_import in H0;
253+
try (nltac_set; nltac_final) |
254+
pose (H0 := H); eapply most_consv in H0;
255+
eapply most_rightup in H0;
256+
try (nltac_set; nltac_final) |
257+
pose (H0 := H); eapply most_consv in H0;
258+
try (nltac_set; nltac_final) |
259+
pose (H0 := H); eapply most_rightup in H0;
260+
try (nltac_set; nltac_final) ]
261+
end.
262+
263+
Ltac nltac :=
264+
try solve
265+
[nltac_set; nltac_final].
266+

0 commit comments

Comments
 (0)