我正在尝试使用 Hugging Face 'Transformers' 库提供的不同转换器架构对自定义数据(采用 csv 格式)进行二进制文本分类。我正在使用这篇Tensorflow 博客文章作为参考。
我正在使用以下代码将自定义数据集加载为“tf.data.Dataset”格式:
def get_dataset(file_path, **kwargs):
dataset = tf.data.experimental.make_csv_dataset(
file_path,
batch_size=5, # Artificially small to make examples easier to show.
na_value="",
num_epochs=1,
ignore_errors=True,
**kwargs)
return dataset
Run Code Online (Sandbox Code Playgroud)
在此之后,当我尝试使用“glue_convert_examples_to_features”方法进行标记化时,如下所示:
train_dataset = glue_convert_examples_to_features(
examples = train_data,
tokenizer = tokenizer,
task = None,
label_list = ['0', '1'],
max_length = 128
)
Run Code Online (Sandbox Code Playgroud)
在以下位置引发错误“UnboundLocalError:分配前引用的局部变量‘处理器’”:
if is_tf_dataset:
example = processor.get_example_from_tensor_dict(example)
example = processor.tfds_map(example)
Run Code Online (Sandbox Code Playgroud)
在所有示例中,我看到他们正在使用诸如“mrpc”之类的任务,这些任务是预定义的并且有一个glue_processor 来处理。在源代码中的“第 85 行”处引发错误。
任何人都可以使用“自定义数据”帮助解决此问题吗?
python text-classification tensorflow huggingface-transformers