Skip to content

[docs] Fix BatchEncoding documentation inconsistencies - #47647

Merged
stevhliu merged 3 commits into
huggingface:mainfrom
samyuktahegde:fix-batchencoding-docs
Aug 1, 2026
Merged

[docs] Fix BatchEncoding documentation inconsistencies#47647
stevhliu merged 3 commits into
huggingface:mainfrom
samyuktahegde:fix-batchencoding-docs

Conversation

@samyuktahegde

@samyuktahegde samyuktahegde commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

CI

What does this PR do?

I found a few inconsistencies in the documentation of BatchEncoding class in the file tokenization_utils_base.py. I have updated them as mentioned in the table below.

Changes

Method / Section Change
BatchEncoding.__init__() Corrected the description of n_sequences. It had the description of tensor_type.
tokens(), sequence_ids(), word_ids() Updated the error message to refer to Python based tokenizers(to maintain consistency within the class). In the earlier version of the message, non-fast tokenizers was mentioned with a contradictory example (XxxTokenizerFast).
token_to_sequence() Corrected the return description to indicate that the method returns the "input sequence index" containing the token instead of the "word index".
word_to_tokens() Corrected the parameter reference from batch_or_token_index to batch_or_word_index.
char_to_token() Corrected the parameter reference from batch_or_token_index to batch_or_char_index, replaced "word" with "character" where appropriate.
word_to_chars() Corrected the parameter reference from batch_or_token_index to batch_or_word_index, clarified the CharSpan description, corrected the return type.
char_to_word() Corrected the parameter reference from batch_or_token_index to batch_or_char_index, corrected the return type, and updated the return description to refer to "word" instead of "token".
convert_to_tensors() Corrected the type of prepend_batch_axis from int to bool.
Multiple methods Corrected minor grammatical errors

Fixes # (issue)

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. These often are low-quality, or fix extremely minor issues that occur rarely or never in practice.
As a result, we're instituting a rule that first-time contributors should not use code agents to submit PRs or issues.
We'd also ask autonomous "OpenClaw"-like agents not to open any PRs or issues.

Issues/PRs from first-time contributors that violate this rule will probably just be closed without review, and we
might block you, especially if you open more than one or appear to be deliberately ignoring this. We especially do not
want new contributors to jump in on random issues to contribute an agent-written fix. This creates lots of noise
for reviewers and other users and will almost certainly get you blocked.

For more information, please read CONTRIBUTING.md.

  • (First-time contributors only): I confirm that this PR description and code is not written by an LLM or code agent

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline and the
    Pull Request checks?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes according to the guidelines?
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@Rocketknight1

Copy link
Copy Markdown
Member

cc @stevhliu

@stevhliu stevhliu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Comment thread src/transformers/tokenization_utils_base.py Outdated
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 30700855549:2
Result: success | Jobs: 16 | Tests: 178,177 | Failures: 0 | Duration: 16h 31m

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@stevhliu
stevhliu added this pull request to the merge queue Aug 1, 2026
Merged via the queue into huggingface:main with commit b3a3603 Aug 1, 2026
114 checks passed
@samyuktahegde
samyuktahegde deleted the fix-batchencoding-docs branch August 5, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants