Skip to content

Commit bad9c8a

Browse files
Peter JohnsonPeter Johnson
authored andcommitted
More detailed errors on reading pkl file
1 parent 19dbd9d commit bad9c8a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

evaluation_function/models/shannon_words_ngram.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def get_counts(n=3, dev=False):
3636
try:
3737
with bz2.BZ2File(FILE, "rb") as f:
3838
cache = pickle.load(f)
39+
if not isinstance(cache, dict):
40+
raise RuntimeError(f"Loaded cache is {type(cache)}, not dict — contents: {str(cache)[:300]}")
41+
if n not in cache:
42+
raise RuntimeError(f"Loaded keys={list(cache.keys())[:10]} (len={len(cache)}) — expected {n}")
3943
except Exception as e:
4044
raise RuntimeError(f"Failed to load {FILE}: {e}")
4145
elif dev: # from here the deployed version will not work because the corpora are not bundled (to save space)

0 commit comments

Comments
 (0)