edugp commited on
Commit
9ec7b19
1 Parent(s): a86046b

Remove corrupt KenLM model files.

Browse files
Files changed (1) hide show
  1. perplexity_lenses/perplexity.py +5 -1
perplexity_lenses/perplexity.py CHANGED
@@ -7,7 +7,11 @@ import kenlm
7
  class KenlmModel:
8
  def __init__(self, language):
9
  download_kenlm_model(language)
10
- self.model = kenlm.Model(f"{language}.arpa.bin")
 
 
 
 
11
 
12
  @classmethod
13
  def from_pretrained(cls, language: str):
 
7
  class KenlmModel:
8
  def __init__(self, language):
9
  download_kenlm_model(language)
10
+ try:
11
+ self.model = kenlm.Model(f"{language}.arpa.bin")
12
+ except OSError:
13
+ os.remove(f"{language}.arpa.bin")
14
+ raise OSError("File was corrupt and should have been removed. Please, retry.")
15
 
16
  @classmethod
17
  def from_pretrained(cls, language: str):