Wrong BPE algorithm implementation?
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 379
- Avg merge
- 3h 30m
- Merged PRs (30d)
- 8
Description
In file master/tensorflow_text/tools/wordpiece_vocab/wordpiece_tokenizer_learner_lib.py, the algorithm about choosing vocabulary is different from toturial here.
The count of all prefixes of a word should be subtract only if the word is selected (count of word surpass the threshold), but the current implementation subtract the count of all prefixes of a word whether the word is selected into next step or not.
I think current implementation is wrong. For example, I have (hell, 200), (hello, 50), (helle, 50), (hella, 50), and threshold is 100, obviously, word hell should be selected into next stage, but with current implementation(following code), after processing (hello, 50), (helle, 50), (hella, 50), word hell only has count 50 and will be discard.
# Get all tokens that have a count above the threshold.
for length in range(params.max_token_length, 0, -1):
for token, count in subtokens[length].items():
if count >= thresh:
next_tokens[token] = count
# Decrement the count of all prefixes.
if len(token) > length: # This token includes the joiner.
joiner_len = len(params.joiner)
for i in range(1 + joiner_len, length + joiner_len):
prefix = token[0:i]
if prefix in subtokens[i - joiner_len]:
subtokens[i - joiner_len][prefix] -= count
else:
for i in range(1, length):
prefix = token[0:i]
if prefix in subtokens[i]:
subtokens[i][prefix] -= count
It seems if len(token) > length: should be in if count >= thresh:.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in master/tensorflow_text/tools/wordpiece_vocab/wordpiece_tokenizer_learner_lib.py and compare the vocabulary-selection loop with the linked tutorial's algorithm. Reproduce the hell/hello/helle/hella example, then verify that prefix counts are decremented only for selected words and that the resulting vocabulary matches the documented behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100