8000 Ensure unicode support, strip carriage returns from vocab by ArtanisTheOne · Pull Request #215 · eole-nlp/eole · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ensure unicode support, strip carriage returns from vocab #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 12, 2025
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: 2 additions & 2 deletions eole/bin/model/average_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ def run(cls, args):

# this maybe better implemented using model_saver classes
# config
with open(os.path.join(args.output, "config.json"), "w") as f:
with open(os.path.join(args.output, "config.json"), "w", encoding="utf-8") as f:
json.dump(
recursive_model_fields_set(final["config"]),
f,
indent=2,
ensure_ascii=False,
)
# vocab
with open(os.path.join(args.output, "vocab.json"), "w") as f:
with open(os.path.join(args.output, "vocab.json"), "w", encoding="utf-8") as f:
json.dump(final["vocab"], f, indent=2, ensure_ascii=False)
# optimizer
torch.save(final["optim"], os.path.join(args.output, "optimizer.pt"))
Expand Down
4 changes: 2 additions & 2 deletions eole/bin/run/build_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ def build_vocab_main(config):

def save_counter(counter, save_path):
check_path(save_path, exist_ok=config.overwrite, log=logger.warning)
with open(save_path, "w", encoding="utf8") as fo:
with open(save_path, "wb") as fo:
for tok, count in counter.most_common():
fo.write(tok + "\t" + str(count) + "\n")
fo.write(f"{tok}\t{str(count)}\n".encode("utf-8"))

if config.share_vocab:
src_counter += tgt_counter
Expand Down
2 changes: 1 addition & 1 deletion eole/bin/tools/embeddings_to_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def get_vocabs(model_path):
# model = torch.load(dict_path, map_location=torch.device("cpu"))
vocabs_path = os.path.join(model_path, "vocab.json")
with open(vocabs_path) as f:
with open(vocabs_path, encoding="utf-8") as f:
vocabs_dict = json.load(f)
vocabs = dict_to_vocabs(vocabs_dict)

Expand Down
2 changes: 1 addition & 1 deletion eole/bin/tools/run_mmlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def evaluate(args, data_dir):

run_results = compute_metric(run_results)

with open(output_filename, "w") as f:
with open(output_filename, "w", encoding="utf-8") as f:
json.dump(run_results, f, ensure_ascii=False, indent=2)

end_time = time.time()
Expand Down
2 changes: 1 addition & 1 deletion eole/inputters/inputter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _read_vocab_file(vocab_path, min_count):
lines = lines[:-1]

first_line = lines[0].split(None, 1)
has_count = len(first_line) == 2 and first_line[-1].isdigit()
has_count = len(first_line) == 2 and first_line[-1].strip().isdigit()
if has_count:
vocab = []
for line in lines:
Expand Down
6 changes: 3 additions & 3 deletions eole/models/model_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def load_checkpoint(model_path):
raise FileNotFoundError(f"{model_path} does not contain config.json")
vocab_path = os.path.join(model_path, "vocab.json")
if os.path.exists(vocab_path):
with open(vocab_path) as f:
with open(vocab_path, encoding="utf-8") as f:
checkpoint["vocab"] = json.load(f)
# use default specials if not specified
if "specials" not in checkpoint["vocab"].keys():
Expand Down Expand Up @@ -241,14 +241,14 @@ def _save_weights(self, model_state_dict):
def _save_vocab(self):
vocab_data = vocabs_to_dict(self.vocabs)
vocab_path = os.path.join(self.model_path, self.step_dir, "vocab.json")
with open(vocab_path, "w") as f:
with open(vocab_path, "w", encoding="utf-8") as f:
json.dump(vocab_data, f, indent=2, ensure_ascii=False)
self._make_symlink("vocab.json")

def _save_config(self):
config_data = recursive_model_fields_set(self.config)
config_path = os.path.join(self.model_path, self.step_dir, "config.json")
with open(config_path, "w") as f:
with open(config_path, "w", encoding="utf-8") as f:
json.dump(config_data, f, indent=2, ensure_ascii=False)
self._make_symlink("config.json")

Expand Down
0