Skip to content

Commit 2494e39

Browse files
committed
Fix error in CompleteFullGraph class.
1 parent 9b8d9b3 commit 2494e39

File tree

9 files changed

+46
-24
lines changed

9 files changed

+46
-24
lines changed

create_screens_german.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
screen -dmS "cle_1" ./start-cle_automated_german.sh 1 m_e-1 p_e-1 e_e-1
4+
screen -dmS "cle_2" ./start-cle_automated_german.sh 10 m_e-10 p_e-10 e_e-10
5+
screen -dmS "cle_3" ./start-cle_automated_german.sh 10 m_e-10_da p_e-10_da e_e-10_da -decrease-alpha
6+
screen -dmS "cle_4" ./start-cle_automated_german.sh 10 m_e-10_ss p_e-10_ss e_e-10_ss -shuffle-sentences
7+
screen -dmS "cle_5" ./start-cle_automated_german.sh 10 m_e-10_da_ss p_e-10_da_ss e_e-10_da_ss -decrease-alpha -shuffle-sentences

dependency-parser.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def save(file_name, model):
4141

4242

4343
def train(args):
44-
4544
start = time.time()
4645
print "\tCreating feature map..."
4746

@@ -90,7 +89,7 @@ def train(args):
9089
for head in sparse_graph:
9190
for arc in sparse_graph[head]:
9291
if arc.feat_vec:
93-
if int(arc.head) == 0:
92+
if arc.head == 0:
9493
if len(arc.feat_vec) != 10:
9594
print "Length of arc feature vector is wrong."
9695
print arc.feat_vec
@@ -150,7 +149,6 @@ def train(args):
150149
stop = time.time()
151150
print "\t\tDone, " + str(stop - start) + " sec"
152151

153-
154152
def test(args):
155153

156154
# load classifier vectors (model) and feature vector from file:
@@ -200,11 +198,6 @@ def test(args):
200198
stop = time.time()
201199
print "\t\tDone, " + str(stop - start) + " sec"
202200

203-
def write_to_file(token, file_obj):
204-
print >> file_obj, str(token.id) + "\t" + str(token.form) + "\t" + str(token.lemma) + "\t" + str(
205-
token.pos) + "\t" + "_" + "\t" + "_" + "\t" + str(token.head) + "\t" + str(token.rel) + "\t" + "_" + "\t" + "_"
206-
207-
208201
if __name__ == '__main__':
209202

210203
t0 = time.time()

modules/featmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def fm (infile):
88
for sentence in sentences(codecs.open(infile,encoding='utf-8')):
99
local_features=[]
1010
for token1 in sentence:
11-
if int(token1.head) == 0:
11+
if token1.head == 0:
1212
# at this point ROOT is the head and token1 is the dependent
1313

1414
# unigram features

modules/graphs.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
class SparseArc: # sparse representation of an arc
55
def __init__(self, head, dependent, s=0.0):
6-
self.head = int(head)
7-
self.dependent = int(dependent)
6+
self.head = head
7+
self.dependent = dependent
88
self.score = s
99
self.feat_vec = []
1010

@@ -15,8 +15,8 @@ def __init__(self, head, dependent, s=0.0):
1515
class FullArc: # full representation of an arc
1616
def __init__(self, head, dependent, head_form, dependent_form, head_lemma, dependent_lemma, head_pos,
1717
dependent_pos, dependent_rel, s=0.0):
18-
self.head = int(head)
19-
self.dependent = int(dependent)
18+
self.head = head
19+
self.dependent = dependent
2020
self.score = s
2121
self.feat_vec = []
2222

@@ -59,7 +59,7 @@ def __init__(self, tokens):
5959
new_arc = SparseArc(token1.id, token2.id)
6060
dependents.append(new_arc)
6161
if dependents:
62-
self.heads[int(token1.id)] = dependents
62+
self.heads[token1.id] = dependents
6363

6464

6565
class FullGraph: # full representation of a graph (keys: heads, values: FullArc objects)
@@ -77,7 +77,7 @@ def __init__(self, tokens):
7777
token1.pos, token2.pos, token2.rel)
7878
dependents.append(new_arc)
7979
if dependents:
80-
self.heads[int(token1.id)] = dependents
80+
self.heads[token1.id] = dependents
8181

8282

8383
class CompleteFullGraph: # complete, full representation of a graph (keys: heads, values: FullArc objects)
@@ -90,12 +90,12 @@ def __init__(self, tokens):
9090
self.heads[0].append(new_arc)
9191
for token1 in tokens:
9292
dependents = []
93-
for token2 in tokens:
93+
for token2 in (token2 for token2 in tokens if token2.head == token1.id):
9494
new_arc = FullArc(token1.id, token2.id, token1.form, token2.form, token1.lemma, token2.lemma, \
9595
token1.pos, token2.pos, token2.rel)
9696
dependents.append(new_arc)
9797
if dependents:
98-
self.heads[int(token1.id)] = dependents
98+
self.heads[token1.id] = dependents
9999

100100

101101
def reverse_head_graph(graph): # reverses a normal graph to a graph where the dependents are the keys

modules/perceptron.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def structured_perceptron(graph, feat_map, rev_feat_map, weight_vector, correct,
4242
errors += 1
4343

4444
if make_graph_compareable(y_predicted) == make_graph_compareable(y_gold):
45+
print "yes"
4546
if tmp_errors < errors:
4647
print "Correct but error, this is not possible"
4748
correct +=1

start-cle.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ EVALUATIONS="evaluations"
1111
#python -u dependency-parser.py -train -i $CORPORA/train/wsj_train.first-5k.conll06 -m model -e 1 -decrease-alpha -shuffle-sentences
1212

1313
#train
14-
#python -u dependency-parser.py -train -i ../dependency-parsing-files/data/english/train/wsj_train.conll06 -m model -e 2 -decrease-alpha -shuffle-sentences
14+
python -u dependency-parser.py -train -i ../dependency-parsing-files/data/english/train/wsj_train.conll06 -m $MODELS/m_e-10_da_ss -e 2 -decrease-alpha -shuffle-sentences
1515

1616
#test
17-
python -u dependency-parser.py -test -i $CORPORA/dev/wsj_dev.conll06 -m model -o predicted.conll06
17+
#python -u dependency-parser.py -test -i $CORPORA/dev/wsj_dev.conll06 -m model -o predicted.conll06
18+
#python -u dependency-parser.py -test -i $CORPORA/train/wsj_train.conll06 -m $MODELS/m_e-10_da_ss -o predicted.conll06
1819

1920
#python -u dependency-parser.py -ev -i predicted.conll06 -g $CORPORA/dev/wsj_dev.conll06 -o evaluation_sentence.txt
2021

start-cle_automated.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PREDICTIONS="predictions"
77
EVALUATIONS="evaluations"
88

99
#train
10-
python -u dependency-parser.py -train -i ${CORPORA}/train/wsj_train.conll06 -m ${MODELS}/$2 -e $1 $5 $6
10+
#python -u dependency-parser.py -train -i ${CORPORA}/train/wsj_train.conll06 -m ${MODELS}/$2 -e $1 $5 $6
1111

1212
#test
1313
python -u dependency-parser.py -test -i ${CORPORA}/dev/wsj_dev.conll06 -m ${MODELS}/$2 -o ${PREDICTIONS}/$3".conll06"

start-cle_automated_german.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
CORPORA="../dependency-parsing-files/data/german"
4+
5+
MODELS="models"
6+
PREDICTIONS="predictions"
7+
EVALUATIONS="evaluations"
8+
9+
#train
10+
python -u dependency-parser.py -train -i ${CORPORA}/train/tiger-2.2.train.conll06 -m ${MODELS}/$2 -e $1 $5 $6
11+
12+
#test
13+
python -u dependency-parser.py -test -i ${CORPORA}/dev/tiger-2.2.dev.conll06 -m ${MODELS}/$2 -o ${PREDICTIONS}/$3".conll06"
14+
15+
# sentence based evaluation
16+
python -u dependency-parser.py -ev -i ${PREDICTIONS}/$3".conll06" -g ${CORPORA}/dev/tiger-2.2.dev.conll06 -o ${EVALUATIONS}/$4"_sentence".txt
17+
18+
#evaluate
19+
./eval07.pl -g ${CORPORA}/dev/tiger-2.2.dev.conll06 -s ${PREDICTIONS}/$3".conll06" >> ${EVALUATIONS}/$4".txt" 2>&1

test-dependency-parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from copy import deepcopy
55

6-
"""
6+
77
a = ManualSparseGraph()
88
a.add_arc(0, SparseArc(0, 1, 10.0))
99
a.add_arc(0, SparseArc(0, 2, 9.0))
@@ -46,7 +46,7 @@
4646
for arc in y[head]:
4747
print str(head) + " --> " + str(arc.dependent) + ", " + str(arc.score)
4848
print "--"
49-
49+
"""
5050
c = ManualSparseGraph()
5151
c.add_arc(33, SparseArc(33, 32, 0))
5252
c.add_arc(4, SparseArc(4, 3, 0))
@@ -85,7 +85,7 @@
8585
c.add_arc(29, SparseArc(29, 30, 0))
8686
8787
print cycle(c.heads)
88-
"""
88+
8989
d = ManualSparseGraph()
9090
# d.add_arc(0, SparseArc(0, 7, 0))
9191
d.add_arc(16, SparseArc(16, 1, 0))
@@ -112,4 +112,5 @@
112112
d.add_arc(20, SparseArc(20, 16, 0))
113113
d.add_arc(7, SparseArc(7, 22, 0))
114114
115-
print cycle(d.heads)
115+
print cycle(d.heads)
116+
"""

0 commit comments

Comments
 (0)