解决nltk的问题
Traceback (most recent call last):
File "D:/pywork/transformer/transformer1.py", line 109, in <module>
train_inputs, train_outputs = segmentation(Path_train_en, Path_train_cn, mode='train')
File "D:/pywork/transformer/transformer1.py", line 101, in segmentation
inputs = get_inputs_nltk(data_en[:train_len])
File "D:/pywork/transformer/transformer1.py", line 80, in get_inputs_nltk
line = word_tokenize(line)
File "D:\F\Anaconda3\envs\pytorch\lib\site-packages\nltk\tokenize\__init__.py", line 129, in word_tokenize
sentences = [text] if preserve_line else sent_tokenize(text, language)
File "D:\F\Anaconda3\envs\pytorch\lib\site-packages\nltk\tokenize\__init__.py", line 106, in sent_tokenize
tokenizer = load("tokenizers/punkt/{0}.pickle".format(language))
File "D:\F\Anaconda3\envs\pytorch\lib\site-packages\nltk\data.py", line 752, in load
opened_resource = _open(resource_url)
File "D:\F\Anaconda3\envs\pytorch\lib\site-packages\nltk\data.py", line 877, in _open
return find(path_, path + [""]).open()
File "D:\F\Anaconda3\envs\pytorch\lib\site-packages\nltk\data.py", line 585, in find
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('punkt')
For more information see: https://www.nltk.org/data.html
Attempted to load tokenizers/punkt/english.pickle
Searched in:
- 'C:\\Users\\49135/nltk_data'
- 'D:\\F\\Anaconda3\\envs\\pytorch\\nltk_data'
- 'D:\\F\\Anaconda3\\envs\\pytorch\\share\\nltk_data'
- 'D:\\F\\Anaconda3\\envs\\pytorch\\lib\\nltk_data'
- 'C:\\Users\\49135\\AppData\\Roaming\\nltk_data'
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- ''
**********************************************************************
解决方法:
下载好nltk之后,解压,放在D:\F\Anaconda3\envs\pytorch\nltk_data目录下,新建一个文件夹tokenizers,然后将解压好的nltk文件夹粘贴过来。
服务器上和本地都可以这样操作。