Skip to content
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

fix: ensure that the entire directory path is created; refactor: don't use same variable name in the parent loop; #294

Open
wants to merge 2 commits into
base: old_gpt_2_chinese_before_2021_4_22
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions generate_texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ def main():
generated += 1
text = tokenizer.convert_ids_to_tokens(out)

for i, item in enumerate(text[:-1]): # 确保英文前后有空格
for idx, item in enumerate(text[:-1]): # 确保英文前后有空格
if is_word(item) and is_word(text[i + 1]):
text[i] = item + ' '
text[idx] = item + ' '

for i, item in enumerate(text):
for idx, item in enumerate(text):
if item == '[MASK]':
text[i] = ''
text[idx] = ''
if item == '[CLS]' or item == '[SEP]':
text[i] = '\n'
text[idx] = '\n'

print("=" * 40 + " SAMPLE " + str(generated) + " " + "=" * 40)
text = ''.join(text).replace('##', '').strip()
Expand Down
2 changes: 1 addition & 1 deletion train_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def build_files(raw_data_path, tokenized_data_path, full_tokenizer, num_pieces):
single = ''.join(lines)
len_single = len(single)
if not os.path.exists(tokenized_data_path):
os.mkdir(tokenized_data_path)
os.makedirs(tokenized_data_path, exist_ok=True)
for i in tqdm(range(num_pieces)):
single_ids = full_tokenizer.convert_tokens_to_ids(
full_tokenizer.tokenize(single[len_single // num_pieces * i: len_single // num_pieces * (i + 1)]))
Expand Down