タイトルのエラーが発生します
関係があるところのコードをのせます
python
1 2tokenizer_cmd = ['./tokenizer.perl', '-l', 'en', '-q', '-'] 3 4 5def tokenize(sentences): 6 7 print('Tokenizing..', end=' ') 8 text = "\n".join(sentences) 9 tokenizer = Popen(tokenizer_cmd, stdin=PIPE, stdout=PIPE, shell=True) 10 tok_text = tokenizer.communicate(text) #もともとはtok_text, _ 11 toks = tok_text.split('\n')[:-1] 12 print('Done') 13 14 return toks 15 16def build_dict(path): 17 sentences = [] 18 currdir = os.getcwd() 19 os.chdir('%s/pos/' %path) 20 for ff in glob.glob("*.txt"): 21 with open(ff, 'r') as f: 22 sentences.append(f.readline().strip()) 23 os.chdir('%s/neg/' %path) 24 for ff in glob.glob("*.txt"): 25 with open(ff, 'r') as f: 26 sentences.append(f.readline().strip()) 27 os.chdir(currdir) 28 29 sentences = tokenize(sentences) 30 31 32def main(): 33 path = dataset_path 34 dictionary = build_dict(os.path.join(path, 'train')) 35 36if __name__ == '__main__': 37 main()
エラーは以下の通りです
python
1Traceback (most recent call last): 2 File "imdb_preprocess.py", line 134, in <module> 3 main() 4 File "imdb_preprocess.py", line 112, in main 5 dictionary = build_dict(os.path.join(path, 'train')) 6 File "imdb_preprocess.py", line 64, in build_dict 7 sentences = tokenize(sentences) 8 File "imdb_preprocess.py", line 44, in tokenize 9 tok_text = tokenizer.communicate(text) #もともとtok_text, _ 10 File "C:\Users\ユーザ名\Anaconda3\envs\py3.5\lib\subprocess.py", line 803, in communicate 11 stdout, stderr = self._communicate(input, endtime, timeout) 12 File "C:\Users\ユーザ名\Anaconda3\envs\py3.5\lib\subprocess.py", line 1039, in _communicate 13'.' は、内部コマンドまたは外部コマンド、 14操作可能なプログラムまたはバッチ ファイルとして認識されていません。 15 self._stdin_write(input) 16 File "C:\Users\ユーザ名\Anaconda3\envs\py3.5\lib\subprocess.py", line 741, in _stdin_write 17 self.stdin.write(input) 18TypeError: a bytes-like object is required, not 'str'
読み込みの仕方を変えたりしたのですが、いまいちわかりませんでした
教えていただければ幸いです
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/24 15:08
2018/05/25 05:19