<jupyter_start><jupyter_text>apply bpe to the all lyrics file<jupyter_code>python apply_bpe.py -c ../bpe_codes.txt -i ../../untracked_data_files/all_lyrics_raw.txt -o all_lyrics_bpe.txt<jupyter_output><empty_output><jupyter_text>getting the vocabulary<jupyter_code>from learn_bpe import get_vocabulary
import codecs
infile_bpe = codecs.open('../untracked_data_files/all_lyrics_bpe.txt', encoding='utf-8')
vocab = get_vocabulary(infile_bpe)
infile_bpe.close()
len(vocab.keys())
import json
bpe_string_token_to_int = {}
int_to_bpe_string_token = {}
vkeys = list(vocab.keys())
for i in range(0, len(vkeys)):
    bpe_string_token_to_int[vkeys[i]] = i + 1
    int_to_bpe_string_token[i + 1] = vkeys[i]
with open('bpe_string_token_to_int.json', 'w') as openfile:
    json.dump(bpe_string_token_to_int, openfile)
with open('int_to_bpe_string_token.json', 'w') as openfile:
    json.dump(int_to_bpe_string_token, openfile)  
with open('vocab_bpe_stats.json', 'w') as openfile:
    json.dump(vocab, openfile)  
with open('bpe_string_token_to_int.json') as openfile:
    bpe_string_token_to_int = json.load(openfile)
with open('int_to_bpe_string_token.json') as openfile:
    int_to_bpe_string_token = json.load(openfile)  

for key in bpe_string_token_to_int:
    if str(key) != str(int_to_bpe_string_token[str(bpe_string_token_to_int[str(key)])]):
        print('wrong pairing in bpe_string_token_to_int {}'.format(key))
for key in int_to_bpe_string_token:
    if str(key) != str(bpe_string_token_to_int[str(int_to_bpe_string_token[str(key)])]):
        print('wrong pairing in int_to_bpe_string_token {}'.format(key))
               
int_to_bpe_string_token<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11964285714285715, 'fraction_numerical': 0.002380952380952381, 'mean_word_length': 6.245689655172414, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '588608', 'license': 'MIT', 'n_tokens_mistral': 697, 'n_tokens_neox': 683, 'n_words': 103, 'path': 'running_bpe.ipynb', 'repo_name': 'billyang98/subword-nmt', 'size': '1680'}