candace_Li
candace_Li

Reputation: 31

When i use tensorflow 2.8.0 to fine-tune bert meet this bug: hub.KerasLayer(tfhub_handle_preprocess) 'CaseFoldUTF8'?

my code follows:

bert_model_name = 'small_bert/bert_en_uncased_L-4_H-512_A-8'
map_name_to_handle = {'small_bert/bert_en_uncased_L-4_H-512_A-8':
        'https://tfhub.dev/tensorflow/small_bert/bert_en_uncased_L-4_H-512_A-8/1'}
map_model_to_preprocess = { 'small_bert/bert_en_uncased_L-4_H-512_A-8':
        'https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/3'}
tfhub_handle_encoder = map_name_to_handle[bert_model_name]
tfhub_handle_preprocess = map_model_to_preprocess[bert_model_name]
print(f'BERT model selected           : {tfhub_handle_encoder}')
print(f'Preprocess model auto-selected: {tfhub_handle_preprocess}')

bert_preprocess_model = hub.KerasLayer(tfhub_handle_preprocess) # here encounter bugs

KeyError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/ops.py in _get_op_def(self, type) 4176 if name: -> 4177 if isinstance(name, compat.bytes_or_text_types): 4178 name = compat.as_str(name)

KeyError: 'CaseFoldUTF8'

Upvotes: 1

Views: 854

Answers (1)

candace_Li
candace_Li

Reputation: 31

This problem is caused by tensorflow_text. You need to import tensorflow_text as text in the top of your code. Like:

import os
import shutil
import tensorflow as tf
import tensorflow_hub as hub
import matplotlib.pyplot as plt

import tensorflow_text as text

If there's no tensorflow_text in your environment,you need to install it. Use:

pip install -q -U "tensorflow-text==2.8.*"

Upvotes: 2

Related Questions