|
11 | 11 |
|
12 | 12 | __all__: list[str] = ["gen_sentence"] |
13 | 13 |
|
14 | | -import pickle |
| 14 | +import json |
15 | 15 | import random |
16 | 16 | from typing import TYPE_CHECKING, Any, Union |
17 | 17 |
|
|
58 | 58 | thwiki: dict[str, Any] = THWIKI_LSTM |
59 | 59 |
|
60 | 60 | # Validate that corpus files are available |
61 | | -if thwiki["itos_fname"] is None or thwiki["wgts_fname"] is None: |
| 61 | +if thwiki["json_itos_fname"] is None or thwiki["wgts_fname"] is None: |
62 | 62 | raise FileNotFoundError( |
63 | 63 | "corpus-not-found names=['wiki_lm_lstm', 'wiki_itos_lstm']\n" |
64 | 64 | " Thai2fit model files not found.\n" |
65 | 65 | " Python: pythainlp.corpus.download('wiki_lm_lstm')\n" |
66 | 66 | " CLI: thainlp data get wiki_lm_lstm\n" |
67 | | - " Python: pythainlp.corpus.download('wiki_itos_lstm')\n" |
68 | | - " CLI: thainlp data get wiki_itos_lstm" |
| 67 | + " Python: pythainlp.corpus.download('json_itos_fname')\n" |
| 68 | + " CLI: thainlp data get json_itos_fname" |
69 | 69 | ) |
70 | 70 |
|
71 | | -# Loads a pickle file from PyThaiNLP's official repository with MD5 verification. |
72 | | -# WARNING: |
73 | | -# Pickle deserialization can execute arbitrary code if the file is malicious. |
74 | | -# Users should only use files from trusted sources. |
75 | | -with open(thwiki["itos_fname"], "rb") as f: |
76 | | - thwiki_itos: list[str] = pickle.load(f) # noqa: S301 |
| 71 | +with open(thwiki["json_itos_fname"], "r") as f: |
| 72 | + thwiki_itos: list[str] = json.load(f) |
77 | 73 | thwiki_vocab: "Vocab" = fastai.text.transform.Vocab(thwiki_itos) |
78 | 74 |
|
79 | 75 | # dummy databunch |
|
0 commit comments