-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplication-multinomial.conf
984 lines (877 loc) · 32.2 KB
/
application-multinomial.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
deepdive {
db.default: {
driver: "org.postgresql.Driver"
url: "jdbc:postgresql://"${PGHOST}":"${PGPORT}"/"${DBNAME} #"
user: ${PGUSER}
password: ${PGPASSWORD}
dbname: ${DBNAME}
host: ${PGHOST}
port: ${PGPORT}
}
schema.variables {
# labels
variable.label: Categorical(4)
# 0: none
# 1: T
# 2: C
# 3: CT
}
extraction.extractors: {
# cand_word table is ready in advance
ext_prepare_variable {
style: "sql_extractor"
# before: util/fill_sequence.sh cand_word cand_word_id
sql: """
UPDATE cand_word
SET cand_word_id = docid || '@' || varid || '_' || candid || '.' || wordid;
DROP TABLE IF EXISTS variable cascade;
CREATE TABLE variable(
docid TEXT,
varid INT,
label INT,
variable_id TEXT,
id BIGINT
) DISTRIBUTED BY (docid);
INSERT INTO variable(
docid,
varid,
variable_id)
SELECT DISTINCT docid, varid,
(docid || '@' || varid) AS variable_id
FROM cand_word;
"""
# after: util/fill_sequence.sh variable variable_id
dependencies: []
}
ext_prepare_candidate {
style: "sql_extractor"
sql: """
DROP TABLE IF EXISTS candidate CASCADE;
CREATE TABLE candidate(
variable_id TEXT,
docid TEXT,
varid INT,
candid INT,
source TEXT,
label BOOLEAN,
candidate_id TEXT,
id BIGINT
)
DISTRIBUTED BY (docid);
INSERT INTO candidate(variable_id, docid, varid, candid, source, candidate_id)
SELECT DISTINCT
variable.variable_id,
variable.docid,
variable.varid,
candid,
source,
(variable.variable_id || '_' || candid) AS candidate_id
FROM cand_word, variable
WHERE variable.docid = cand_word.docid
AND variable.varid = cand_word.varid;
UPDATE cand_word
SET candidate_id = candidate.candidate_id
FROM candidate
WHERE cand_word.docid = candidate.docid
AND cand_word.varid = candidate.varid
AND cand_word.candid = candidate.candid
;
"""
# after: util/fill_sequence.sh candidate candidate_id
dependencies: ["ext_prepare_variable"]
}
# Preparation Before holdout documents
ext_prepare_document {
style: "sql_extractor"
sql: """
DROP TABLE IF EXISTS document CASCADE;
CREATE TABLE document(
document_id BIGSERIAL,
docid TEXT)
DISTRIBUTED BY (document_id);
INSERT INTO document(docid)
SELECT DISTINCT docid
FROM cand_word
ORDER BY docid;
DROP TABLE IF EXISTS document_backup CASCADE;
SELECT *
INTO document_backup
FROM document;
-- CREATE VIEW eval_docs AS
-- SELECT docid
-- FROM document_backup
-- WHERE document_id IN (
-- SELECT document_id FROM document WHERE docid IS NULL
-- );
"""
dependencies: ["ext_prepare_variable"]
}
# K-fold a fraction of documents.
ext_holdout_document {
style: "sql_extractor" # "cmd + sql"
dependencies: ["ext_prepare_document"]
before: ${APP_HOME}"/udf/kfold.py "${KFOLD_NUM}" "${KFOLD_ITER}" document document_id docid"
# IMPORTANT: holdout result is reproducible across different runs.
sql: """
DROP TABLE IF EXISTS eval_docs CASCADE;
CREATE TABLE eval_docs AS
SELECT docid
FROM document_backup
WHERE document_id IN (
SELECT document_id FROM document WHERE docid IS NULL
) DISTRIBUTED BY (docid);
"""
}
# K-fold a fraction of documents defined by .
ext_holdout_from_orderaware {
style: "cmd_extractor"
cmd: ${APP_HOME}"/udf/before_ext_fold_from_orderaware.sh"
}
# Extract naive ocr-specific features
ext_naivefeature {
style: "tsv_extractor"
input: """
SELECT docid, cand_word_id, word, source
FROM cand_word
"""
output_relation: "feature"
before: ${APP_HOME}"/udf/before_naivefeature.sh"
udf: "pypy "${APP_HOME}"/udf/ext_naivefeature.py"
parallelism: ${MAX_PARALLELISM}
# input_batch_size: 5000
# output_batch_size: 5000
}
# ext_prepare_domain_1gram SUCCESS [144211 ms]
# INSERT 0 8408220 (group by docs)
# SELECT 674194 (aggregated)
ext_prepare_domain_1gram {
style: "plpy_extractor"
dependencies: []
input: """
SELECT docid,
string_to_array(article, '~^~') as words,
1 as gram_len,
0 as count_filter
FROM domain_corpus
WHERE article != '';
"""
output_relation: "doc_domain_1gram"
before: ${APP_HOME}"/udf/before_prepare_domain_ngram.sh 1"
udf: ${APP_HOME}"/udf/ext_prepare_domain_ngram.py"
# 1: gram_len, 0: count_filter
# after: ${APP_HOME}"/udf/after_prepare_domain_ngram.sh 1 0"
}
# ext_prepare_domain_2gram SUCCESS [334037 ms]
# INSERT 0 22982529
# SELECT 6197359
ext_prepare_domain_2gram {
style: "plpy_extractor"
dependencies: []
input: """
SELECT docid,
string_to_array(article, '~^~') as words,
2 as gram_len,
0 as count_filter
FROM domain_corpus
WHERE article != '';
"""
output_relation: "doc_domain_2gram"
before: ${APP_HOME}"/udf/before_prepare_domain_ngram.sh 2"
udf: ${APP_HOME}"/udf/ext_prepare_domain_ngram.py"
# 2: gram_len, 0: count_filter
# after: ${APP_HOME}"/udf/after_prepare_domain_ngram.sh 2 0"
}
# ext_prepare_domain_3gram SUCCESS [174428 ms]
# INSERT 0 31118773 (group by docs)
# SELECT 16550020 (aggregated)
ext_prepare_domain_3gram {
style: "plpy_extractor"
dependencies: []
input: """
SELECT docid,
string_to_array(article, '~^~') as words,
3 as gram_len,
0 as count_filter
FROM domain_corpus
WHERE article != '';
"""
output_relation: "doc_domain_3gram"
before: ${APP_HOME}"/udf/before_prepare_domain_ngram.sh 3"
udf: ${APP_HOME}"/udf/ext_prepare_domain_ngram.py"
# 3: gram_len, 0: count_filter
# after: ${APP_HOME}"/udf/after_prepare_domain_ngram.sh 3 0"
}
# Get domain Ngram excluding evaluation docs
ext_domain_ngram {
style: "sql_extractor"
dependencies: ["ext_prepare_domain_1gram","ext_prepare_domain_2gram","ext_prepare_domain_3gram"]
sql: """
DROP TABLE IF EXISTS domain_1gram CASCADE;
DROP TABLE IF EXISTS domain_2gram CASCADE;
DROP TABLE IF EXISTS domain_3gram CASCADE;
CREATE TABLE domain_1gram AS
SELECT ngram, sum(count) as count
FROM doc_domain_1gram
WHERE NOT EXISTS (
SELECT *
FROM eval_docs
WHERE eval_docs.docid = doc_domain_1gram.docid
) GROUP BY ngram
DISTRIBUTED BY (ngram);
CREATE TABLE domain_2gram AS
SELECT ngram, sum(count) as count
FROM doc_domain_2gram
WHERE NOT EXISTS (
SELECT *
FROM eval_docs
WHERE eval_docs.docid = doc_domain_2gram.docid
) GROUP BY ngram
DISTRIBUTED BY (ngram);
CREATE TABLE domain_3gram AS
SELECT ngram, sum(count) as count
FROM doc_domain_3gram
WHERE NOT EXISTS (
SELECT *
FROM eval_docs
WHERE eval_docs.docid = doc_domain_3gram.docid
) GROUP BY ngram
DISTRIBUTED BY (ngram);
"""
# cmd: ${APP_HOME}"/udf/after_prepare_domain_ngram.sh 1 0 ; "${APP_HOME}"/udf/after_prepare_domain_ngram.sh 2 0 ; "${APP_HOME}"/udf/after_prepare_domain_ngram.sh 3 0 ; "
}
#################### NGRAM SUPERVISION ####################
ext_prepare_supv_ngram {
style: "plpy_extractor"
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware"]
input: """
SELECT docid,
array_agg(word order by wordid) as words,
"""${SUPV_GRAM_LEN}""" as gram_len
FROM html_seq GROUP BY (docid);
"""
###### TODO html_seq -> domain_corpus??? faster?
output_relation: "supv_ngram"
before: ${APP_HOME}"/udf/before_prepare_supv_ngram.sh"
udf: ${APP_HOME}"/udf/ext_prepare_supv_ngram.py"
}
# Extract all candidate 2grams
# Fixed parameters. Used for ONLY google features
ext_cand_2gram {
style: "plpy_extractor"
dependencies: ["ext_prepare_document", "ext_prepare_variable", "ext_prepare_candidate"]
input: """
SELECT
docid,
array_agg(cand_word_id order by varid, candid, wordid) as arr_cand_word_id,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(candid order by varid, candid, wordid) as arr_candid,
array_agg(word order by varid, candid, wordid) as arr_feature,
2 as gram_len
FROM cand_word
GROUP BY docid
"""
output_relation: "cand_2gram"
# udf: "pypy "${APP_HOME}"/udf/ext_cand_ngram.py 2"
udf: ${APP_HOME}"/udf/ext_cand_ngram_plpy.py"
# parallelism: ${MAX_PARALLELISM}
before: ${APP_HOME}"/udf/before_cand_ngram.sh 2"
}
# Extract all candidate Ngrams. Accept N as input (SUPV_GRAM_LEN)
# Used for BOTH supervision and features
ext_cand_ngram {
style: "plpy_extractor"
dependencies: ["ext_prepare_document", "ext_prepare_variable", "ext_prepare_candidate"]
input: """
SELECT
docid,
array_agg(cand_word_id order by varid, candid, wordid) as arr_cand_word_id,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(candid order by varid, candid, wordid) as arr_candid,
array_agg(word order by varid, candid, wordid) as arr_feature,
"""${SUPV_GRAM_LEN}""" as gram_len
FROM cand_word
GROUP BY docid
"""
output_relation: "cand_"${SUPV_GRAM_LEN}"gram"
# udf: "pypy "${APP_HOME}"/udf/ext_cand_ngram.py 2"
udf: ${APP_HOME}"/udf/ext_cand_ngram_plpy.py"
# parallelism: ${MAX_PARALLELISM}
before: ${APP_HOME}"/udf/before_cand_ngram.sh "${SUPV_GRAM_LEN}
}
ext_sup_ngram {
style: "cmd_extractor"
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware", "ext_cand_ngram", "ext_prepare_supv_ngram"]
cmd: "bash "${APP_HOME}"/udf/ext_sup_ngram.sh "${SUPV_GRAM_LEN}
}
# array_agg(id order by varid, candid, wordid) as arr_id,
# array_agg(candid order by varid, candid, wordid) as arr_candid,
# array_agg(wordid order by varid, candid, wordid) as arr_wordid,
# TAKES VERY LONG
########### TODO at least change this to TSV... ############
ext_sup_orderaware {
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware"]
input: """select
docid,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(word order by varid, candid, wordid) as arr_word
from cand_word
group by docid
"""
# where docid in (select * from eval_docs)
output_relation: "orderaware_supv_label"
# Supervision dir
udf: "pypy "${APP_HOME}"/udf/ext_sup_orderaware.py "
# # Using Evaluation dir
# udf: "pypy "${APP_HOME}"/udf/ext_sup_orderaware.py "${EVAL_DIR}
parallelism: ${MAX_PARALLELISM}
before: ${APP_HOME}"/udf/before_sup_orderaware.sh"
# after: ${APP_HOME}"/udf/after_sup_orderaware.sh"
input_batch_size: 1
output_batch_size: 10000
}
ext_eval_orderaware_bestpick {
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware"]
input: """select
docid,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(word order by varid, candid, wordid) as arr_word
from cand_word
where docid in (select * from eval_docs)
group by docid
"""
# where docid in (select * from eval_docs)
output_relation: "orderaware_eval_label_bestpick"
udf: "pypy "${APP_HOME}"/udf/ext_sup_orderaware.py /lfs/local/0/zifei/bestpick-result/ "${EVAL_DIR}
parallelism: ${MAX_PARALLELISM}
before: ${APP_HOME}"/udf/before_sup_orderaware_bestpick.sh orderaware_eval_label_bestpick"
# after: ${APP_HOME}"/udf/after_sup_orderaware.sh"
input_batch_size: 1
output_batch_size: 10000
}
ext_eval_orderaware_bestpick_tess {
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware"]
input: """select
docid,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(word order by varid, candid, wordid) as arr_word
from cand_word
where docid in (select * from eval_docs)
and (source = 'T' or source = 'CT' or source = 'TC')
group by docid
"""
# where docid in (select * from eval_docs)
output_relation: "orderaware_eval_label_bestpick_tess"
udf: "pypy "${APP_HOME}"/udf/ext_sup_orderaware.py /lfs/local/0/zifei/bestpick-result-tess/ "${EVAL_DIR}
parallelism: ${MAX_PARALLELISM}
before: ${APP_HOME}"/udf/before_sup_orderaware_bestpick.sh orderaware_eval_label_bestpick_tess"
# after: ${APP_HOME}"/udf/after_sup_orderaware.sh"
input_batch_size: 1
output_batch_size: 10000
}
ext_eval_orderaware_bestpick_cuni {
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware"]
input: """select
docid,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(word order by varid, candid, wordid) as arr_word
from cand_word
where docid in (select * from eval_docs)
and (source = 'C' or source = 'CT' or source = 'TC')
group by docid
"""
# where docid in (select * from eval_docs)
output_relation: "orderaware_eval_label_bestpick_cuni"
udf: "pypy "${APP_HOME}"/udf/ext_sup_orderaware.py /lfs/local/0/zifei/bestpick-result-cuni/ "${EVAL_DIR}
parallelism: ${MAX_PARALLELISM}
before: ${APP_HOME}"/udf/before_sup_orderaware_bestpick.sh orderaware_eval_label_bestpick_cuni"
# after: ${APP_HOME}"/udf/after_sup_orderaware.sh"
input_batch_size: 1
output_batch_size: 10000
}
ext_sup_orderaware_incremental {
dependencies: ["ext_holdout_document", "ext_prepare_document", "ext_holdout_from_orderaware"]
input: """select
docid,
array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
array_agg(varid order by varid, candid, wordid) as arr_varid,
array_agg(word order by varid, candid, wordid) as arr_word
from cand_word
where not exists
(select DISTINCT docid from orderaware_supv_label
where orderaware_supv_label.docid = cand_word.docid
)
group by docid
"""
# TODO CHECK IT!!
# where docid in (select * from eval_docs)
output_relation: "orderaware_supv_label"
udf: "pypy "${APP_HOME}"/udf/ext_sup_orderaware.py"
parallelism: ${MAX_PARALLELISM}
# before: ${APP_HOME}"/udf/before_sup_orderaware.sh"
# after: ${APP_HOME}"/udf/after_sup_orderaware.sh"
input_batch_size: 1
output_batch_size: 10000
}
# NO EXTRACT, Use only
ext_sup_use_orderaware {
dependencies: ["ext_sup_orderaware"]
style: "sql_extractor"
sql: """
update candidate set label = NULL;
update candidate
set label = true
where candidate_id in
(select candidate_id from orderaware_supv_label where label = true);
update candidate
set label = false
where label is null
and docid in (select distinct docid from orderaware_supv_label);
"""
}
# TODO
ext_sup_variable_label {
dependencies: ["ext_sup_use_orderaware", "ext_sup_ngram"]
style: "sql_extractor"
sql: """
UPDATE variable v SET label = null;
UPDATE variable v
SET label = 3
FROM candidate c
WHERE c.docid = v.docid
AND c.variable_id = v.variable_id
AND c.source = 'CT'
AND c.label = true;
UPDATE variable v
SET label = 2
FROM candidate c
WHERE c.docid = v.docid
AND c.variable_id = v.variable_id
AND c.source = 'C'
AND c.label = true;
UPDATE variable v
SET label = 1
FROM candidate c
WHERE c.docid = v.docid
AND c.variable_id = v.variable_id
AND c.source = 'T'
AND c.label = true
AND v.label is null;
UPDATE variable v
SET label = 0
WHERE label is null
AND NOT EXISTS (
SELECT * FROM candidate
WHERE candidate.variable_id = v.variable_id
AND candidate.docid = v.docid
AND (candidate.label != false OR candidate.label is null)
);
UPDATE variable v
SET label = null
FROM candidate c
WHERE c.docid = v.docid
AND c.variable_id = v.variable_id
AND c.source = 'T'
AND c.label = true
AND v.label = 2;
""" # disambi not necessary: done in supervision step...
}
# # Deprecated since DD's manual holdout is enabled
# ext_sup_holdout_labels {
# style: "sql_extractor"
# dependencies: ["ext_sup_1gram", "ext_sup_1gram_2gram", "ext_sup_use_orderaware"]
# sql: """UPDATE candidate
# SET label = null
# WHERE docid IN (select docid from eval_docs);"""
# # after: ${APP_HOME}"/udf/after_sup_holdout_labels.sh"
# }
# Use 2gram results to generate features based on Google Ngrams
ext_cand_2gram_feature {
style: "sql_extractor"
# cmd: ${APP_HOME}"/udf/after_cand_2gram.sh"
sql: """
DROP TABLE IF EXISTS cand_2gram_positive CASCADE;
DROP TABLE IF EXISTS cand_2gram_somepos_candidates CASCADE;
DROP TABLE IF EXISTS cand_2gram_someneg_candidates CASCADE;
CREATE TABLE cand_2gram_positive AS
select cand_2gram.*, count
from cand_2gram, google_2gram_reduced
where count > 1000 and ngram = gram
DISTRIBUTED BY (docid);
CREATE TABLE cand_2gram_somepos_candidates AS
select cand_word.docid,
cand_word.candidate_id
from cand_2gram_positive t,
cand_word
where cand_word.cand_word_id = t.cand_word_id
AND cand_word.docid = t.docid
group by cand_word.docid, cand_word.candidate_id
DISTRIBUTED BY (docid);
CREATE TABLE cand_2gram_someneg_candidates AS
SELECT cand_word.docid, cand_word.candidate_id
FROM cand_word
WHERE NOT EXISTS
( select *
from cand_2gram_positive t
where t.cand_word_id = cand_word.cand_word_id
and t.docid = cand_word.docid
)
group by cand_word.docid, cand_word.candidate_id
DISTRIBUTED BY (docid);
"""
dependencies: ["ext_cand_2gram"]
}
# Do not do cross-words
# Select character Ngrams (N is 3rd input in the query / before / output_relation)
ext_char_1gram {
style: "plpy_extractor"
dependencies: ["ext_prepare_document", "ext_prepare_variable", "ext_prepare_candidate"]
input: """
SELECT docid, candidate_id, word, 1 as gram_len
FROM cand_word
"""
output_relation: "f_char_1gram"
udf: ${APP_HOME}"/udf/ext_char_ngram.py"
before: ${APP_HOME}"/udf/before_ngram.sh char_1"
}
ext_char_2gram {
style: "plpy_extractor"
dependencies: ["ext_prepare_document", "ext_prepare_variable", "ext_prepare_candidate"]
input: """
SELECT docid, candidate_id, word, 2 as gram_len
FROM cand_word
"""
output_relation: "f_char_2gram"
udf: ${APP_HOME}"/udf/ext_char_ngram.py"
before: ${APP_HOME}"/udf/before_ngram.sh char_2"
}
# ext_pos_3gram {
# # TODO write a general script to lable sequences with ngram!!
# input: """select
# docid,
# array_agg(cand_word_id order by varid, candid, wordid) as arr_cand_word_id,
# array_agg(candidate_id order by varid, candid, wordid) as arr_candidate_id,
# array_agg(varid order by varid, candid, wordid) as arr_varid,
# array_agg(candid order by varid, candid, wordid) as arr_candid,
# array_agg(pos order by varid, candid, wordid) as arr_feature
# from cand_word
# group by docid
# """
# output_relation: "pos_3gram"
# udf: "pypy "${APP_HOME}"/udf/ext_cand_ngram.py 3"
# parallelism: ${MAX_PARALLELISM}
# before: ${APP_HOME}"/udf/before_pos_3gram.sh"
# after: ${APP_HOME}"/udf/after_pos_3gram.sh"
# input_batch_size: 1
# }
}
inference.factors: {
########## NEW FORMAT FOR INFERENCE RULES #########
# Weight column
# ID for each variables
# label (var) column
# naming convention: select id from
f_naivefeature {
input_query: """
select
cand_word.source || ':' || feature.fname as "feature.fname",
variable.id as "variable.id",
variable.label as "variable.label"
from feature, cand_word, variable
where feature.cand_word_id = cand_word.cand_word_id
AND cand_word.docid || '@' || cand_word.varid = variable.variable_id
AND cand_word.docid = variable.docid
AND cand_word.docid = feature.docid
"""
function: "Multinomial(variable.label)"
weight: "?(feature.fname)"
}
f_nlp_pos {
input_query: """
SELECT
cand_word.source || ':' || pos as pos,
variable.id as "variable.id",
variable.label as "variable.label"
from cand_word, variable
where cand_word.docid || '@' || cand_word.varid = variable.variable_id
AND cand_word.docid = variable.docid
"""
function: "Multinomial(variable.label)"
weight: "?(pos)"
}
# TODO
# f_nlp_pos_2gram {
# }
f_nlp_ner {
input_query: """
SELECT
cand_word.source || ':' || ner as ner,
variable.id as "variable.id",
variable.label as "variable.label"
from cand_word, variable
where cand_word.docid || '@' || cand_word.varid = variable.variable_id
AND cand_word.docid = variable.docid
"""
function: "Multinomial(variable.label)"
weight: "?(ner)"
}
f_ocr_bias {
input_query: """
select
candidate.source as source,
variable.id as "variable.id",
variable.label as "variable.label"
from candidate, variable
WHERE candidate.docid = variable.docid
AND candidate.variable_id = variable.variable_id
"""
function: "Multinomial(variable.label)"
weight: "?(source)"
}
# f_nlp_pos {
# input_query: """
# select
# candidate.source as "candidate.source",
# candidate.id as "candidate.id",
# candidate.label as "candidate.label"
# from candidate
# """
# function: "IsTrue(candidate.label)"
# weight: "?(candidate.source)"
# }
f_constraint {
# Cannot reverse natural join order: id MUST BE cand_label.id!!
# select c1.id as "candidate.c1.id",
# c2.id as "candidate.c2.id",
# ALREADY DISTINCT
input_query: """
select
c1.id as "candidate.c1.id",
c2.id as "candidate.c2.id",
c1.label as "candidate.c1.label",
c2.label as "candidate.c2.label"
from candidate as c1, candidate as c2
where c1.docid = c2.docid
AND c1.variable_id = c2.variable_id
and c1.candidate_id != c2.candidate_id
"""
# function: "Imply(candidate.c1.label, !candidate.c2.label)"
# # weight: "?"
# weight: 30
function: "And(candidate.c1.label, candidate.c2.label)"
weight: "?"
# weight: -20
}
# f_agree_bonus {
# # Different source, same output: both correct.
# More agree, more correct
# }
# Positive: In google ngram
f_1gram_pos {
input_query: """
select
candidate.id as "candidate.id",
candidate.label as "candidate.label"
FROM candidate, cand_word, google_1gram
WHERE google_1gram.gram = cand_word.word
and google_1gram.count > 1000
and cand_word.candidate_id = candidate.candidate_id
and cand_word.docid = candidate.docid
"""
function: "IsTrue(candidate.label)"
weight: "?"
}
# negative: not in google ngram, or too few
f_1gram_neg {
input_query: """
select
candidate.id as "candidate.id",
candidate.label as "candidate.label"
FROM candidate, cand_word
where not exists
(select * from google_1gram
where count > 1000
and cand_word.word = gram
)
and cand_word.candidate_id = candidate.candidate_id
and cand_word.docid = candidate.docid
"""
function: "IsTrue(!candidate.label)"
weight: "?"
}
############### 2gram features #################
f_2gram_each {
input_query: """
SELECT candidate.id as "candidate.id",
candidate.label as "candidate.label",
log(count)::int as logcount
FROM cand_2gram_positive t,
candidate
WHERE t.candidate_id = candidate.candidate_id
AND t.docid = candidate.docid
"""
function: "IsTrue(candidate.label)"
weight: "?(logcount)"
}
f_2gram_allpos {
input_query: """
select
candidate.id as "candidate.id",
candidate.label as "candidate.label"
from candidate
where not exists
(select * from cand_2gram_someneg_candidates t
where candidate.candidate_id = t.candidate_id
and candidate.docid = t.docid)
"""
function: "IsTrue(candidate.label)"
weight: "?"
}
f_2gram_someneg {
input_query: """
select
candidate.id as "candidate.id",
candidate.label as "candidate.label"
from candidate, cand_2gram_someneg_candidates t
where candidate.candidate_id = t.candidate_id
and candidate.docid = t.docid
"""
function: "IsTrue(!candidate.label)"
weight: "?"
}
f_2gram_allneg {
input_query: """
select
candidate.id as "candidate.id",
candidate.label as "candidate.label"
from candidate
where not exists
(select * from cand_2gram_somepos_candidates t
where candidate.candidate_id = t.candidate_id
and candidate.docid = t.docid)
"""
function: "IsTrue(!candidate.label)" # Should be a positive weight
weight: "?"
}
f_2gram_somepos {
input_query: """
select
candidate.id as "candidate.id",
candidate.label as "candidate.label"
from candidate, cand_2gram_somepos_candidates t
where candidate.candidate_id = t.candidate_id
and candidate.docid = t.docid
"""
function: "IsTrue(candidate.label)"
weight: "?"
}
f_char_1gram {
input_query: """
SELECT c.id AS "candidate.id",
c.label AS "candidate.label",
ngram || '-' || source AS feature
FROM candidate c, f_char_1gram f
WHERE c.docid = f.docid
AND c.candidate_id = f.candidate_id
"""
function: "IsTrue(candidate.label)"
weight: "?(feature)"
}
}
calibration {
# holdout_fraction: ${CALI_FRACTION}
holdout_query: """
INSERT INTO dd_graph_variables_holdout(variable_id)
SELECT id
FROM candidate
WHERE docid IN (select docid from eval_docs);"""
}
sampler.sampler_cmd: "util/sampler-dw-linux gibbs"
# sampler.sampler_cmd: "/dfs/rulk/0/czhang/dm2/dimmwitted/dw gibbs"
# sampler.sampler_args: "-l 300 -s 1 -i 300" # Only for May 27 bestball
# sampler.sampler_args: "-l 100 -s 10 -i 100 -t 1"
# sampler.sampler_args: "-l 500 -s 1 -i 1000 --alpha 0.1 -d 0.98" # Which better?
sampler.sampler_args: "-l 300 -s 1 -i 500 -a 0.01"
# sampler.sampler_args: "-l 300 -s 1 -i 500 -a 0.1" # Which better?
# pick a small learning rate to try to learn a correct weight
pipeline.pipelines.empty: []
pipeline.pipelines.bestpick: [
# "ext_prepare_document", "ext_holdout_document",
"ext_eval_orderaware_bestpick",
"ext_eval_orderaware_bestpick_tess",
"ext_eval_orderaware_bestpick_cuni",
# "f_constraint",
]
#####################################################
################## MAIN PIPELINE ####################
#####################################################
pipeline.pipelines.main: [
###############################
########## EXTRACTORS #########
###############################
############## PREPROCESSING #################
### "ext_prepare_variable",
### "ext_prepare_candidate",
### "ext_prepare_document","ext_holdout_document",
############## SUPERVISION #################
# Ngram supervision
### "ext_prepare_supv_ngram", # prepare ngram supervision
### "ext_cand_ngram", # prepare N-gram candidate (long)
# "ext_sup_ngram", # Calculate supervision
#---------- Order-aware supervision --------
### "ext_sup_orderaware",
# "ext_sup_use_orderaware",
########### After cand supervision, update variable labels #####
# "ext_sup_variable_label",
################## FEATURE ####################
### "ext_naivefeature",
###### Domain-corpus Ngram Feature ######
# # PREPROCESS ALL DOCUMENTS (Run only once!)
# # "ext_prepare_domain_1gram",
# # "ext_prepare_domain_2gram",
# # "ext_prepare_domain_3gram",
# "ext_domain_ngram", # Exclude this testset
#########################################
# ngram features
# "ext_cand_2gram",
# "ext_cand_2gram_feature",
# "ext_char_1gram",
# ###############################
# ####### INFERENCE RULES #######
# ###############################
# "f_naivefeature",
# "f_constraint",
# "f_nlp_pos",
# "f_nlp_ner",
"f_ocr_bias",
# "f_1gram_pos",
# "f_1gram_neg",
# "f_2gram_somepos",
# "f_2gram_allneg",
# "f_2gram_someneg", # same AS somepos....
# "f_2gram_allpos",
# "f_2gram_each", # new one
# "f_char_1gram",
]
# pipeline.run: "orderaware"
pipeline.run: "main"
# inference.skip_learning: true
# pipeline.relearn_from: /lfs/madmax/0/zifei/deepdive/out/2014-05-28T154541
}
# Regex to select all rules: " ext|f_.*\{"
# Time:
# 02:31:27 [profiler] INFO ext_prepare_candidate SUCCESS [7261 ms]
# 02:31:27 [profiler] INFO ext_prepare_document SUCCESS [8506 ms]
# 02:31:27 [profiler] INFO ext_naivefeature SUCCESS [63002 ms]
# 02:31:27 [profiler] INFO ext_holdout_document SUCCESS [54690 ms]
# 02:31:27 [profiler] INFO ext_cand_ngram SUCCESS [129908 ms]
# 02:31:27 [profiler] INFO ext_sup_orderaware SUCCESS [1768944 ms]
# 02:31:28 [profiler] INFO ext_cand_2gram SUCCESS [1868929 ms]
# 02:31:28 [profiler] INFO ext_sup_use_orderaware SUCCESS [48940 ms]
# 02:31:28 [profiler] INFO ext_cand_2gram_feature SUCCESS [5936 ms]
# 02:31:28 [profiler] INFO ext_prepare_supv_ngram SUCCESS [1830603 ms]