Skip to content

Commit

Permalink
towards being pythonic in slicing for character spans, re: Slicing in…
Browse files Browse the repository at this point in the history
… SurprisalArray is not fully Pythonic #6
  • Loading branch information
aalok-sathe committed Nov 15, 2023
1 parent 83ca06d commit c8146dd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion surprisal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def hf_pick_matching_token_ixs(
"""
span_of_interest = slice(
span_of_interest.start or 0,
span_of_interest.stop or len(encoding.ids),
span_of_interest.stop
or (
len(encoding.ids)
if span_type == "word"
else encoding.token_to_chars((len(encoding.ids) - 1)).end
),
span_of_interest.step,
)

Expand Down

0 comments on commit c8146dd

Please sign in to comment.