Skip to content

Commit

Permalink
🐞 fix(tok.py): 修复模型加载路径
Browse files Browse the repository at this point in the history
修复模型加载路径,避免安装非当前目录时无法加载
  • Loading branch information
yansh97 committed Jun 3, 2024
1 parent 2902878 commit f9fc4ab
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions jieba3/tok.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class ModelParams(BaseModel):


BASE_MODEL_PARAMS: Final[ModelParams] = ModelParams.model_validate_json(
json_data=Path("jieba3/model.base.json").read_text()
json_data=(Path(__file__).parent / "model.base.json").read_text()
)
BASE_MODEL_FREQ: Final[dict[str, int]] = BASE_MODEL_PARAMS.freq
BASE_MODEL_TOTAL: Final[int] = BASE_MODEL_PARAMS.total

SMALL_MODEL_PARAMS: Final[ModelParams] = ModelParams.model_validate_json(
json_data=Path("jieba3/model.small.json").read_text()
json_data=(Path(__file__).parent / "model.small.json").read_text()
)
SMALL_MODEL_FREQ: Final[dict[str, int]] = SMALL_MODEL_PARAMS.freq
SMALL_MODEL_TOTAL: Final[int] = SMALL_MODEL_PARAMS.total

LARGE_MODEL_PARAMS: Final[ModelParams] = ModelParams.model_validate_json(
json_data=Path("jieba3/model.large.json").read_text()
json_data=(Path(__file__).parent / "model.large.json").read_text()
)
LARGE_MODEL_FREQ: Final[dict[str, int]] = LARGE_MODEL_PARAMS.freq
LARGE_MODEL_TOTAL: Final[int] = LARGE_MODEL_PARAMS.total
Expand All @@ -53,7 +53,7 @@ class HMMParams(BaseModel):


HMM_PARAMS: Final[HMMParams] = HMMParams.model_validate_json(
json_data=Path("jieba3/hmm.json").read_text()
json_data=(Path(__file__).parent / "hmm.json").read_text()
)

HMM_STATE_PROB: Final[dict[State, float]] = HMM_PARAMS.state_prob
Expand Down

0 comments on commit f9fc4ab

Please sign in to comment.