rsennrich / subword-nmt

Unsupervised Word Segmentation for Neural Machine Translation and Text Generation
MIT License
2.18k stars 464 forks source link

Importing and using learn_bpe and apply_bpe from a Python shell #73

Closed mlforcada closed 5 years ago

mlforcada commented 5 years ago

Hi, Rico: This may be a newbie question, so apologies in advance. An undergrad student of mine and I are putting together a Python script that does a bunch of things. It learns a BPE and applies it to some files (Python is a nice way for things to work both in her Windows laptop and in my GNU/Linux machines). I am currently launching ("subword-nmt apply-bpe" and "subword-nmt learn-bpe") via subprocesses. Is there a way to import this functionality into a Python script? I have seen that from a Python shell I can type "from subword_nmt import learn_bpe, apply_bpe", but then if I try something like infile=open("test.tok.true.es") outfile=open("/tmp/zzz","w") learn_bpe(infile,outfile,10000) I get a "'module' object is not callable" type error. Thanks a million in advance.

rsennrich commented 5 years ago

Hi Mikel,

to import the functions, change your code to:

from subword_nmt.learn_bpe import learn_bpe
from subword_nmt.apply_bpe import apply_bpe

This should then work.