File size: 1,255 Bytes
fb65c78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/env python

"""
According to model,
vocab_size: 32128

But it actually caps out at 32099
"""


from transformers import T5Tokenizer,T5EncoderModel
import torch
import charade

T="mcmonkey/google_t5-v1_1-xxl_encoderonly"

tokenizer = T5Tokenizer.from_pretrained(T)

startword= tokenizer.convert_ids_to_tokens(3)
#print (startword)

# id should be a numeral
def print_token_from_id(id):
    decoded_tokens = tokenizer.convert_ids_to_tokens(id)
    print(decoded_tokens+" : " + str(id))

# print if it has the marker indicating it is a standalone word,
# not just a building block
def print_if_word(id):
    decoded_tokens = tokenizer.convert_ids_to_tokens(id)
    if decoded_tokens.startswith(startword):
        print(decoded_tokens[1:] +" : " + str(id))

# standalone word, AND doesnt have any foreign non-ascii7 chars
def print_if_asciiword(id):
    decoded_tokens = tokenizer.convert_ids_to_tokens(id)
    if decoded_tokens.startswith(startword):
        aword=decoded_tokens[1:]
        if len(aword) <1:
            return
        estr=str(aword.encode())
        if '\\x' in estr:
            return

        print(aword +" : " , id)

for id in range(4,32099):
    #print_token_from_id(id)
    #print_if_word(id)
    print_if_asciiword(id)