Clean up debugging

This commit is contained in:
Matthew Honnibal 2020-06-22 15:34:34 +02:00
parent b250f6b62f
commit e92be79ffc

View File

@ -61,7 +61,7 @@ cdef class TransitionSystem:
offset += len(doc)
return states
def get_oracle_sequence(self, Example example):
def get_oracle_sequence(self, Example example, _debug=False):
cdef Pool mem = Pool()
# n_moves should not be zero at this point, but make sure to avoid zero-length mem alloc
assert self.n_moves > 0
@ -70,6 +70,8 @@ cdef class TransitionSystem:
cdef StateClass state
states, golds, n_steps = self.init_gold_batch([example])
if not states:
return []
state = states[0]
gold = golds[0]
history = []
@ -82,30 +84,32 @@ cdef class TransitionSystem:
history.append(i)
s0 = state.S(0)
b0 = state.B(0)
debug_log.append(" ".join((
self.get_class_name(i),
"S0=", (example.x[s0].text if s0 >= 0 else "__"),
"B0=", (example.x[b0].text if b0 >= 0 else "__"),
"S0 head?", str(state.has_head(state.S(0))),
)))
if _debug:
debug_log.append(" ".join((
self.get_class_name(i),
"S0=", (example.x[s0].text if s0 >= 0 else "__"),
"B0=", (example.x[b0].text if b0 >= 0 else "__"),
"S0 head?", str(state.has_head(state.S(0))),
)))
action.do(state.c, action.label)
break
else:
print("Actions")
for i in range(self.n_moves):
print(self.get_class_name(i))
print("Gold")
for token in example.y:
print(token.text, token.dep_, token.head.text)
s0 = state.S(0)
b0 = state.B(0)
debug_log.append(" ".join((
"?",
"S0=", (example.x[s0].text if s0 >= 0 else "-"),
"B0=", (example.x[b0].text if b0 >= 0 else "-"),
"S0 head?", str(state.has_head(state.S(0))),
)))
print("\n".join(debug_log))
if _debug:
print("Actions")
for i in range(self.n_moves):
print(self.get_class_name(i))
print("Gold")
for token in example.y:
print(token.text, token.dep_, token.head.text)
s0 = state.S(0)
b0 = state.B(0)
debug_log.append(" ".join((
"?",
"S0=", (example.x[s0].text if s0 >= 0 else "-"),
"B0=", (example.x[b0].text if b0 >= 0 else "-"),
"S0 head?", str(state.has_head(state.S(0))),
)))
print("\n".join(debug_log))
raise ValueError(Errors.E024)
return history