makcedward/nlpaug

File not found in /model/char/keyboard/en.json

ljvmiranda921 opened this issue · 7 comments

Hello! I'm encountering this error when using KeyboardAug:

Minimum Working Environment

import nlpaug.augmenter.char as nac
aug = nac.KeyboardAug()
aug.augment("hello world")

Exception

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-24-c96cc55b7113> in <module>
----> 1 augment(3, nac.KeyboardAug())

~/anaconda3/lib/python3.6/site-packages/nlpaug/augmenter/char/keyboard.py in __init__(self, name, aug_char_min, aug_char_max, aug_char_p, aug_word_p, aug_word_min, aug_word_max, stopwords, tokenizer, reverse_tokenizer, special_char, numeric, upper_case, lang, verbose, stopwords_regex)
     53         self.upper_case = upper_case
     54         self.lang = lang
---> 55         self.model = self.get_model(special_char, numeric, upper_case, lang)
     56 
     57     def skip_aug(self, token_idxes, tokens):

~/anaconda3/lib/python3.6/site-packages/nlpaug/augmenter/char/keyboard.py in get_model(cls, special_char, numeric, upper_case, lang)
     99     @classmethod
    100     def get_model(cls, special_char=True, numeric=True, upper_case=True, lang="en"):
--> 101         return nmc.Keyboard(special_char=special_char, numeric=numeric, upper_case=upper_case, lang=lang)

~/anaconda3/lib/python3.6/site-packages/nlpaug/model/char/keyboard.py in __init__(self, special_char, numeric, upper_case, cache, lang)
     18         self.lang = lang
     19         self.model = self.get_model(
---> 20             model_dir=self.model_dir, special_char=special_char, numeric=numeric, upper_case=upper_case, lang=lang)
     21 
     22     def predict(self, data):

~/anaconda3/lib/python3.6/site-packages/nlpaug/model/char/keyboard.py in get_model(cls, model_dir, special_char, numeric, upper_case, lang)
     31 
     32         model_path = os.path.join(model_dir, lang+'.json')
---> 33         with open(model_path, encoding="utf8") as f:
     34             mapping = json.load(f)
     35 

FileNotFoundError: [Errno 2] No such file or directory: '/home/ljvm/anaconda3/lib/python3.6/site-packages/nlpaug/model/char/../../../model/char/keyboard/en.json'

Thoughts

  • I think that the paths here ../../../ becomes different when running nlpaug as a package.

Thank you!

I think it's fine to just ask for a model_dir parameter when initializing Keyboard aug and just let the users download en.json. This can be handled properly (perhaps) by incorporating the download step in your DownloadUtils

Forget to upload corresponding files. Re-uploaded

@makcedward is there any way we/I can help get this issue's resolution (bundled in #104) pushed to PyPI? Please let me know!

@dataframing
Will work on that asap

pushed to PyPI. Please check.

I think the issue is still not solved and as @ljvmiranda921 stated

paths here ../../../ becomes different when running nlpaug as a package.

Updated to 0.0.13.3 version. It included json file.