-
Notifications
You must be signed in to change notification settings - Fork 536
/
Copy pathapp.ddlog
88 lines (68 loc) · 1.8 KB
/
app.ddlog
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
chunk?(
@key sent_id bigint,
@key word_id bigint,
tag text
).
tags(tag text).
# input data ##################################################################
words(
sent_id bigint,
word_id bigint,
word text,
pos text,
true_tag text
).
word_embedding(
word text,
vec float[]
).
vec_dims(idx int).
word_vec(wid, vec):-
words(s, wid, word, pos, true_tag),
word_embedding(word_lower, vec),
word_lower = lower(word).
# supervision / scope of tags #################################################
chunk(s, word, tag) = (
if tag = true_tag then TRUE else FALSE end
) :-
words(s, word, _, pos, true_tag),
tags(tag).
# unigram features ###############################################################
@name("current word")
@weight(tag, word)
chunk(s, w, tag) :-
words(s, w, word, pos, _).
@name("current pos tag")
@weight(tag, pos)
chunk(s, w, tag) :-
words(s, w, word, pos, _).
@name("current and next pos")
@weight(tag, pos1, pos2)
chunk(s, w1, tag) :-
w2 = w1 + 1,
words(s, w1, word1, pos1, _),
words(s, w2, word2, pos2, _).
@name("current and prev pos")
@weight(tag, pos1, pos2)
chunk(s, w2, tag) :-
w2 = w1 + 1,
words(s, w1, word1, pos1, _),
words(s, w2, word2, pos2, _).
# bigram features ###############################################################
@name("linear chain")
@weight(tag1, tag2)
chunk(s, w1, tag1) ^ chunk(s, w2, tag2) :- w2 = w1 + 1.
@name("linear chain by pos")
@weight(tag1, tag2, pos1, pos2)
chunk(s, w1, tag1) ^ chunk(s, w2, tag2) :-
w2 = w1 + 1,
words(s, w1, word1, pos1, _),
words(s, w2, word2, pos2, _).
# word embedding features ###############################################################
@name("word embedding")
@weight(tag, k)
@feature_value(vec[k])
chunk(s, w, tag) :-
words(s, w, word, pos, _),
word_vec(s, vec),
vec_dims(k).