| def clear_text(): | |
| """ | |
| 好像不需要 | |
| """ | |
| import json | |
| from tqdm import tqdm | |
| # dev_manifest = f"{YOUR_DATA_ROOT}/validation/validation_mozilla-foundation_common_voice_11_0_manifest.json" | |
| # test_manifest = f"{YOUR_DATA_ROOT}/test/test_mozilla-foundation_common_voice_11_0_manifest.json" | |
| train_manifest = f"data/common_voice_11_0/ja/train/train_common_voice_11_0_manifest.json" | |
| def compute_char_counts(manifest): | |
| char_counts = {} | |
| with open(manifest, 'r') as fn_in: | |
| for line in tqdm(fn_in, desc="Compute counts.."): | |
| line = line.replace("\n", "") | |
| data = json.loads(line) | |
| text = data["text"] | |
| for word in text.split(): | |
| for char in word: | |
| if char not in char_counts: | |
| char_counts[char] = 1 | |
| else: | |
| char_counts[char] += 1 | |
| return char_counts | |
| char_counts = compute_char_counts(train_manifest) | |
| threshold = 10 | |
| trash_char_list = [] | |
| for char in char_counts: | |
| if char_counts[char] <= threshold: | |
| trash_char_list.append(char) | |
| print(trash_char_list) | |
| if __name__ == "__main__": | |
| # clear_text() | |
| pass | |