Skip to content

Commit

Permalink
Fix #1901: UnicodeEncodeError running export_bpe_vocab.py (#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonrobinson authored Feb 20, 2025
1 parent 4801094 commit 9c810ce
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/export_bpe_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# Please install a version >=0.1.96

import argparse
import codecs
from typing import Dict

try:
Expand Down Expand Up @@ -56,11 +57,11 @@ def main():

sp = spm.SentencePieceProcessor()
sp.Load(model_file)
vocabs = [sp.IdToPiece(id) for id in range(sp.GetPieceSize())]
with open(vocab_file, "w") as vfile:
vocabs = [sp.id_to_piece(id) for id in range(sp.get_piece_size())]
with codecs.open(vocab_file, "w", "utf-8") as vfile:
for v in vocabs:
id = sp.PieceToId(v)
vfile.write(f"{v}\t{sp.GetScore(id)}\n")
id = sp.piece_to_id(v)
vfile.write(f"{v}\t{sp.get_score(id)}\n")
print(f"Vocabulary file is written to {vocab_file}")


Expand Down

0 comments on commit 9c810ce

Please sign in to comment.