(path1: str, path2: str, name1='Tokenizer1', name2='Tokenizer2')
| 7 | |
| 8 | |
| 9 | def main(path1: str, path2: str, name1='Tokenizer1', name2='Tokenizer2'): |
| 10 | tokenizer1 = AutoTokenizer.from_pretrained(path1) |
| 11 | vocabSize1 = len(tokenizer1) |
| 12 | |
| 13 | print('=' * 80) |
| 14 | print(f'Info of tokenizer [{name1}]:') |
| 15 | print('=' * 80) |
| 16 | print(f'Vocab size of [{name1}]: [{vocabSize1}])') |
| 17 | print('-' * 80) |
| 18 | print(tokenizer1) |
| 19 | print('-' * 80) |
| 20 | |
| 21 | lastTenTokenizer1Tokens = [] |
| 22 | for i in range(vocabSize1 - 10, vocabSize1): |
| 23 | lastTenTokenizer1Tokens.append(tokenizer1.convert_ids_to_tokens(i)) |
| 24 | |
| 25 | print(f'Last 10 tokens: {lastTenTokenizer1Tokens}') |
| 26 | print('=' * 80) |
| 27 | |
| 28 | tokenizer2 = AutoTokenizer.from_pretrained(path2) |
| 29 | vocabSize2 = len(tokenizer2) |
| 30 | |
| 31 | print('\n\n') |
| 32 | print('=' * 80) |
| 33 | print(f'Info of tokenizer [{name2}]:') |
| 34 | print('=' * 80) |
| 35 | print(f'Vocab size of [{name2}]: [{vocabSize2}])') |
| 36 | print('-' * 80) |
| 37 | print(tokenizer2) |
| 38 | print('-' * 80) |
| 39 | |
| 40 | lastTenTokenizer2Tokens = [] |
| 41 | |
| 42 | for i in range(vocabSize2 - 10, vocabSize2): |
| 43 | lastTenTokenizer2Tokens.append(tokenizer2.convert_ids_to_tokens(i)) |
| 44 | |
| 45 | print(f'Last 10 tokens: {lastTenTokenizer2Tokens}') |
| 46 | print('=' * 80) |
| 47 | |
| 48 | longerRange = max(vocabSize1, vocabSize2) |
| 49 | |
| 50 | print('\n\n') |
| 51 | print('Diffing the tokenizers...') |
| 52 | print('\n') |
| 53 | |
| 54 | differencesCount = 0 |
| 55 | for i in range(longerRange): |
| 56 | token1 = tokenizer1._convert_id_to_token(i) |
| 57 | token2 = tokenizer2._convert_id_to_token(i) |
| 58 | |
| 59 | if token1 == token2: |
| 60 | continue |
| 61 | |
| 62 | differencesCount += 0 |
| 63 | |
| 64 | message = f'At position [{i}],' |
| 65 | |
| 66 | if token1 is not False: |
nothing calls this directly
no outgoing calls
no test coverage detected