Skip to content

Commit

Permalink
update toy example to BPE use same representation again as learn_bpe.py
Browse files Browse the repository at this point in the history
learn_bpe.py was changed in commit a749a7 to make end-of-word representation more consistent.
  • Loading branch information
rsennrich committed Oct 5, 2017
1 parent 8ba000d commit 3d28265
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bpe_toy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ def merge_vocab(pair, v_in):
v_out[w_out] = v_in[word]
return v_out

vocab = {'l o w </w>' : 5, 'l o w e r </w>' : 2,
'n e w e s t </w>' : 6, 'w i d e s t </w>' : 3}
vocab = {'l o w</w>' : 5, 'l o w e r</w>' : 2,
'n e w e s t</w>' : 6, 'w i d e s t</w>' : 3}
num_merges = 15
for i in range(num_merges):
pairs = get_stats(vocab)
best = max(pairs, key=pairs.get)
try:
best = max(pairs, key=pairs.get)
except ValueError:
break
if pairs[best] < 2:
sys.stderr.write('no pair has frequency > 1. Stopping\n')
break
Expand Down

0 comments on commit 3d28265

Please sign in to comment.