Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pythainlp/spell/words_spelling_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def _load_embeddings(self) -> tuple[list[str], NDArray[np.float32]]:
"""Loads embeddings matrix and vocabulary list."""
import numpy as np

input_matrix = np.load(os.path.join(self.model_dir, "embeddings.npy"))
input_matrix = np.load(
os.path.join(self.model_dir, "embeddings.npy"), allow_pickle=False
)
words = []
vocab_path = os.path.join(self.model_dir, "vocabulary.txt")
with open(vocab_path, encoding="utf-8") as f:
Expand Down
50 changes: 15 additions & 35 deletions pythainlp/transliterate/w2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Thai_W2P:
p2idx: dict[str, int]
idx2p: dict[int, str]
checkpoint: Optional[str]
variables: "NDArray"
enc_emb: "NDArray"
enc_w_ih: "NDArray"
enc_w_hh: "NDArray"
Expand Down Expand Up @@ -101,52 +100,33 @@ def _load_variables(self) -> None:

if self.checkpoint is None:
raise RuntimeError("checkpoint path is not set")
self.variables: "NDArray" = np.load(self.checkpoint, allow_pickle=False)
# (29, 64). (len(graphemes), emb)
self.enc_emb: "NDArray" = self.variables.item().get(
"encoder.emb.weight"
variables: "np.lib.npyio.NpzFile" = np.load(
self.checkpoint, allow_pickle=False
)
# (29, 64). (len(graphemes), emb)
self.enc_emb: "NDArray" = variables["encoder.emb.weight"]
# (3*128, 64)
self.enc_w_ih: "NDArray" = self.variables.item().get(
"encoder.rnn.weight_ih_l0"
)
self.enc_w_ih: "NDArray" = variables["encoder.rnn.weight_ih_l0"]
# (3*128, 128)
self.enc_w_hh: "NDArray" = self.variables.item().get(
"encoder.rnn.weight_hh_l0"
)
self.enc_w_hh: "NDArray" = variables["encoder.rnn.weight_hh_l0"]
# (3*128,)
self.enc_b_ih: "NDArray" = self.variables.item().get(
"encoder.rnn.bias_ih_l0"
)
self.enc_b_ih: "NDArray" = variables["encoder.rnn.bias_ih_l0"]
# (3*128,)
self.enc_b_hh: "NDArray" = self.variables.item().get(
"encoder.rnn.bias_hh_l0"
)

self.enc_b_hh: "NDArray" = variables["encoder.rnn.bias_hh_l0"]
# (74, 64). (len(phonemes), emb)
self.dec_emb: "NDArray" = self.variables.item().get(
"decoder.emb.weight"
)
self.dec_emb: "NDArray" = variables["decoder.emb.weight"]
# (3*128, 64)
self.dec_w_ih: "NDArray" = self.variables.item().get(
"decoder.rnn.weight_ih_l0"
)
self.dec_w_ih: "NDArray" = variables["decoder.rnn.weight_ih_l0"]
# (3*128, 128)
self.dec_w_hh: "NDArray" = self.variables.item().get(
"decoder.rnn.weight_hh_l0"
)
self.dec_w_hh: "NDArray" = variables["decoder.rnn.weight_hh_l0"]
# (3*128,)
self.dec_b_ih: "NDArray" = self.variables.item().get(
"decoder.rnn.bias_ih_l0"
)
self.dec_b_ih: "NDArray" = variables["decoder.rnn.bias_ih_l0"]
# (3*128,)
self.dec_b_hh: "NDArray" = self.variables.item().get(
"decoder.rnn.bias_hh_l0"
)
self.dec_b_hh: "NDArray" = variables["decoder.rnn.bias_hh_l0"]
# (74, 128)
self.fc_w: "NDArray" = self.variables.item().get("decoder.fc.weight")
self.fc_w: "NDArray" = variables["decoder.fc.weight"]
# (74,)
self.fc_b: "NDArray" = self.variables.item().get("decoder.fc.bias")
self.fc_b: "NDArray" = variables["decoder.fc.bias"]

def _sigmoid(self, x: "np.ndarray") -> "np.ndarray":
import numpy as np
Expand Down