Skip to content

Instantly share code, notes, and snippets.

@sanjibnarzary
Last active September 8, 2023 16:27
Show Gist options
  • Save sanjibnarzary/f34d51bcaca17cf449d0456485904174 to your computer and use it in GitHub Desktop.
Save sanjibnarzary/f34d51bcaca17cf449d0456485904174 to your computer and use it in GitHub Desktop.
Testing script in Python fairseq machine translation model
import sys
if len(sys.argv) <3:
print("python test.py checkpoint_path data-bin bpe_code")
sys.exit(0)
else:
path=sys.argv[1]
db=sys.argv[2]
code=sys.argv[3]
from fairseq.models.transformer import TransformerModel
eng2brx = TransformerModel.from_pretrained(
path,
checkpoint_file='checkpoint_last.pt',
data_name_or_path=db,
bpe='subword_nmt',
bpe_codes=code
)
eng=input('English text: ')
brx=eng2brx.translate(eng)
print(eng)
print(brx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment