clab / fast_align

Simple, fast unsupervised word aligner
Apache License 2.0
731 stars 158 forks source link

force_align.py (TypeError: a bytes-like object is required, not 'str') #58

Open ChristineBasta opened 3 years ago

ChristineBasta commented 3 years ago

Hello, we are trying to run force_align after using the fast_align, the fast_align is working fine and we get the model. After running force_align, we get Traceback (most recent call last): File "/home/christine/fast_align/build/force_align.py", line 93, in main() File "/home/christine/fast_align/build/force_align.py", line 87, in main sys.stdout.write('{}\n'.format(aligner.align(line.strip()))) File "/home/christine/fast_align/build/force_align.py", line 30, in align self.fwd_align.stdin.write('{}\n'.format(line)) TypeError: a bytes-like object is required, not 'str'

we are running on python 3.6.9.

we do not know where the problem can be from, we are using the right format of sentence: The mechanic gave the clerk a present because it was his birthday. ||| La mecánica dio al Cirque durargo, porque era su cumpleaños.

please advise!!

lluisg commented 3 years ago

We tried changing to bites with

        self.fwd_align.stdin.write('{}\n'.format(line).encode('utf-8'))

but then the problem persists and gets stuck on the next line

        fwd_line = self.fwd_align.stdout.readline().split('|||')[2].strip()
ttwelve12 commented 3 years ago

Hi, if you use python3, you should set bufsize = 1 and universal_newlines= True in subprocess.Popen . @lluisg @ChristineBasta And you can also set the "encoding" in module subprocess if you meet encode problem

lizongyao123 commented 3 years ago

Python2