Skip to content

Fix end position bug #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions td/learning/constrained_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,19 @@ def feed_token(self, token: int, probs=None):
self._current_start = self._token_positions_to_real[
self._tokenizer.token_to_position(token)
]
self._current_end = self._edit_spans[self._current_start]
self._decode_state = DecoderState.States.TOKEN
position_rule = self._position_rule(self._current_start)
self._interactive_parser = self._grammar._lark_parser_for_start[
position_rule
].parse_interactive(start=position_rule)
self._recompute_mask()

# Find the correct end position based on the selected rule
for node in self._position_to_nodes[self._current_start]:
if self._node_rule(node) == position_rule:
self._current_end = node.meta.end_pos
break
else:
self._current_end = self._edit_spans[self._current_start]
elif self._decode_state == DecoderState.States.TOKEN:
token_str = self._tokenizer._index_to_token[token]
token_name = self._grammar.rev_vocabulary_map[token_str]
Expand Down