mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-12 15:25:47 +03:00
Use get_aligned_parse in ArcEager
This commit is contained in:
parent
87f5348e17
commit
ecf192aa70
|
@ -75,31 +75,20 @@ cdef GoldParseStateC create_gold_state(Pool mem, StateClass stcls, Example examp
|
||||||
gs.n_kids_in_buffer = <int32_t*>mem.alloc(gs.length, sizeof(gs.n_kids_in_buffer[0]))
|
gs.n_kids_in_buffer = <int32_t*>mem.alloc(gs.length, sizeof(gs.n_kids_in_buffer[0]))
|
||||||
gs.n_kids_in_stack = <int32_t*>mem.alloc(gs.length, sizeof(gs.n_kids_in_stack[0]))
|
gs.n_kids_in_stack = <int32_t*>mem.alloc(gs.length, sizeof(gs.n_kids_in_stack[0]))
|
||||||
|
|
||||||
cand_to_gold = example.alignment.cand_to_gold
|
heads, labels = example.get_aligned_parse(projectivize=True)
|
||||||
gold_to_cand = example.alignment.cand_to_gold
|
|
||||||
cdef TokenC ref_tok
|
cdef TokenC ref_tok
|
||||||
for cand_i in range(example.x.length):
|
for i, (head, label) in enumerate(zip(heads, labels)):
|
||||||
gold_i = cand_to_gold[cand_i]
|
if head is not None:
|
||||||
if gold_i is not None: # Alignment found
|
gs.heads[i] = head
|
||||||
ref_tok = example.y.c[gold_i]
|
gs.labels[i] = example.x.vocab.strings.add(label)
|
||||||
gold_head = gold_to_cand[gold_i + ref_tok.head]
|
gs.state_bits[i] = set_state_flag(
|
||||||
if gold_head is not None:
|
gs.state_bits[i],
|
||||||
gs.heads[cand_i] = gold_head
|
|
||||||
gs.labels[cand_i] = ref_tok.dep
|
|
||||||
gs.state_bits[cand_i] = set_state_flag(
|
|
||||||
gs.state_bits[cand_i],
|
|
||||||
HEAD_UNKNOWN,
|
HEAD_UNKNOWN,
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
gs.state_bits[cand_i] = set_state_flag(
|
gs.state_bits[i] = set_state_flag(
|
||||||
gs.state_bits[cand_i],
|
gs.state_bits[i],
|
||||||
HEAD_UNKNOWN,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
gs.state_bits[cand_i] = set_state_flag(
|
|
||||||
gs.state_bits[cand_i],
|
|
||||||
HEAD_UNKNOWN,
|
HEAD_UNKNOWN,
|
||||||
1
|
1
|
||||||
)
|
)
|
||||||
|
@ -529,10 +518,11 @@ cdef class ArcEager(TransitionSystem):
|
||||||
for label in kwargs.get('right_labels', []):
|
for label in kwargs.get('right_labels', []):
|
||||||
actions[RIGHT][label] = 1
|
actions[RIGHT][label] = 1
|
||||||
actions[REDUCE][label] = 1
|
actions[REDUCE][label] = 1
|
||||||
for example in kwargs.get('gold_parses', []):
|
for example in kwargs.get('examples', []):
|
||||||
heads, labels = nonproj.projectivize(example.get_aligned("HEAD"),
|
heads, labels = example.get_aligned_parse(projectivize=True)
|
||||||
example.get_aligned("DEP"))
|
for child, (head, label) in enumerate(zip(heads, labels)):
|
||||||
for child, head, label in zip(example.get_aligned("ID"), heads, labels):
|
if head is None or label is None:
|
||||||
|
continue
|
||||||
if label.upper() == 'ROOT' :
|
if label.upper() == 'ROOT' :
|
||||||
label = 'ROOT'
|
label = 'ROOT'
|
||||||
if head == child:
|
if head == child:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user