Skip to content
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

Fix typo in bpe.py #97

Open
wants to merge 1 commit into
base: master
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
8 changes: 4 additions & 4 deletions mingpt/bpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ def bpe(self, token):
break # no more bigrams are eligible to be merged
first, second = bigram

# we will now replace all occurences of (first, second) in the list of current
# we will now replace all occurrence of (first, second) in the list of current
# words into one merged token first_second, in the output list new_words
new_word = []
i = 0
while i < len(word):

# find the next occurence of first in the sequence of current words
# find the next occurrence of first in the sequence of current words
try:
j = word.index(first, i)
new_word.extend(word[i:j])
Expand All @@ -133,15 +133,15 @@ def bpe(self, token):
new_word.extend(word[i:])
break

# if this occurence is also followed by second, then merge them into one
# if this occurrence is also followed by second, then merge them into one
if word[i] == first and i < len(word)-1 and word[i+1] == second:
new_word.append(first+second)
i += 2
else:
new_word.append(word[i])
i += 1

# all occurences of (first, second) have been merged to first_second
# all occurrence of (first, second) have been merged to first_second
new_word = tuple(new_word)
word = new_word
if len(word) == 1:
Expand Down