Skip to content

Commit 0618360

Browse files
Merge pull request #36 from k00ni/fix/array-slice-truncate-helper
PretrainedTokenizer::truncateHelper: prevent array_slice() error for flawed text input (summarization)
2 parents fb2e91b + b70d108 commit 0618360

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/PretrainedTokenizers/PretrainedTokenizer.php

+4
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ function truncateHelper(array &$item, int $length): void
468468
// Setting .length to a lower value truncates the array in-place.
469469
// Note: In PHP, arrays automatically adjust their size, so we don't need to explicitly set the length.
470470
foreach (array_keys($item) as $key) {
471+
if (false == $item[$key]) {
472+
continue;
473+
}
474+
471475
$item[$key] = array_slice($item[$key], 0, $length);
472476
}
473477
}

0 commit comments

Comments
 (0)