Creates a preprocessing function.
(module_handle)
| 35 | |
| 36 | |
| 37 | def get_tf_tokenizer(module_handle): |
| 38 | """Creates a preprocessing function.""" |
| 39 | tokenization_info = get_tokenization_info(module_handle) |
| 40 | |
| 41 | table_initializer = tf.lookup.TextFileInitializer( |
| 42 | filename=tokenization_info["vocab_file"], |
| 43 | key_dtype=tf.string, |
| 44 | key_index=tf.lookup.TextFileIndex.WHOLE_LINE, |
| 45 | value_dtype=tf.int64, |
| 46 | value_index=tf.lookup.TextFileIndex.LINE_NUMBER) |
| 47 | vocab_lookup_table = tf.lookup.StaticVocabularyTable( |
| 48 | initializer=table_initializer, |
| 49 | num_oov_buckets=1, |
| 50 | lookup_key_dtype=tf.string) |
| 51 | |
| 52 | tokenizer = tf_text.BertTokenizer( |
| 53 | vocab_lookup_table=vocab_lookup_table, |
| 54 | lower_case=tokenization_info["do_lower_case"]) |
| 55 | |
| 56 | return tokenizer, vocab_lookup_table |
| 57 | |
| 58 | |
| 59 | def tokenize_with_original_mapping(text_input, tokenizer): |
nothing calls this directly
no test coverage detected
searching dependent graphs…