我正在尝试为一个问答项目建立一个TensorFlow微调框架。以拥抱面孔/变形金刚为原型,但无法贯穿训练师。
该实验是在Databricks进行的,加载的预训练模型是基伯特,训练和开发集是从拥抱面孔的示例SQUAD 2.0 https://github.com/huggingface/transformers/tree/master/examples/question-answering
下载的错误日志抱怨意外的关键字参数“ is_impossible ”,这是SQUAD 2数据格式功能。
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')
model = TFAutoModelForQuestionAnswering.from_pretrained('bert-base-uncased')
processor = SquadV2Processor()
train_examples = processor.get_train_examples(data_dir, train_file_name)
eval_examples = processor.get_dev_examples(data_dir, dev_file_name)
train_dataset = (squad_convert_examples_to_features(
examples=train_examples,
tokenizer=tokenizer,
max_seq_length=max_seq_length,
doc_stride=doc_stride,
max_query_length=max_query_length,
is_training=True,
return_dataset="tf"
))
eval_dataset = (squad_convert_examples_to_features(
examples=eval_examples,
tokenizer=tokenizer,
max_seq_length=max_seq_length,
doc_stride=doc_stride,
max_query_length=max_query_length,
is_training=False,
return_dataset="tf"
))
training_args = (TFTrainingArguments(
output_dir=output_dir,
num_train_epochs=2,
do_train=True,
per_device_train_batch_size = 8,
per_device_eval_batch_size = 16,
logging_steps=10,
learning_rate=3e-5))
trainer = TFTrainer(model=model, args=training_args, train_dataset=train_dataset, eval_dataset=eval_dataset)
trainer.train()
TypeError跟踪(最近的呼叫 最后) ----> 1个trainer.train()
/databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py 火车上(个体经营) 410如果self.args.past_index> = 0: 411 self._past = None -> 412为step,enumerate中的training_loss(self._training_steps(train_ds,优化器)): 第413章 414 self.epoch_logging = epoch_iter-1 +(step +1)/ steps_per_epoch
/databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py 在_training_steps(自身,ds,优化程序)中 457通过训练步骤返回生成器(即参数更新)。 458“”“ -> 459 for i,枚举损失(self._accumulate_next_gradients(ds)): 460如果我%self.args.gradient_accumulation_steps == 0: 461 self._apply_gradients(optimizer)
/databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py 在_accumulate_next_gradients(self,ds)中 490而True: 491尝试: -> 492个结果_accumulate_next() 493,除了tf.errors.OutOfRangeError: 494中断
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/def_function.py 在通话中(自己,* args,** kwds) 第566章 第567章 -> 568结果= self._call(* args,** kwds) 569 570如果tracing_count == self._get_tracing_count():
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/def_function.py 在_call(self,* args,** kwds)中 613#这是 call 的第一个调用,因此我们必须进行初始化。 614个初始化器= [] -> 615 self._initialize(args,kwds,add_initializers_to = initializers) 616最后: 617#至此,我们知道初始化已完成(或更少)
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/def_function.py 在_initialize(self,args,kwds,add_initializers_to)中 第495章 496章
pylint:disable =受保护的访问权限
-> 497 * args,** kwds)) 498 499 def invalid_creator_scope(* unused_args,** unused_kwds):
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py 在_get_concrete_function_internal_garbage_collected(self,* args, ** kwargs) 2387 args,kwargs = None,None 2388带self._lock: -> 2389 graph_function,_,_ = self._maybe_define_function(args,kwargs) 2390返回graph_function 2391
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py 在_maybe_define_function(self,args,kwargs)中 2701 2702 self._function_cache.missed.add(call_context_key) -> 2703 graph_function = self._create_graph_function(args,kwargs) 2704 self._function_cache.primary [cache_key] = graph_function 2705返回graph_function,args,kwargs
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py 在_create_graph_function(self,args,kwargs, Override_flat_arg_shapes) 2591 arg_names = arg_names, 2592年 -> 2593 capture_by_value = self._capture_by_value), 2594自我 2595#告诉ConcreteFunction清除图形后,便清除
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/framework/func_graph.py 在func_graph_from_py_func(name,python_func,args,kwargs,签名, func_graph,亲笔签名,autograph_options,add_control_dependencies, arg_names,op_return_value,集合,capture_by_value, Override_flat_arg_shapes) 第976章 977 -> 978 func_outputs = python_func(* func_args,** func_kwargs) 979 980#不变量:
func_outputs
仅包含张量,复合张量/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/eager/def_function.py 在wrapd_fn(* args,** kwds)中 437#包裹允许AutoGraph交换转换后的函数。我们给予 438#函数对自身的弱引用以避免引用循环。 -> 439返回weak_wrapped_fn()。包装(* args,** kwds) (440)第440章 441
/local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/framework/func_graph.py 在包装器中(* args,** kwargs) 966例外,例如e:#pylint:disable = broad-except 967如果hasattr(e,“ ag_error_metadata”): -> 968提高e.ag_error_metadata.to_exception(e) 969其他: 970加薪
TypeError:转换后的代码中:
/databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py:488
_accumulate_next * 返回self._accumulate_gradients(per_replica_features,per_replica_labels) /databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py:498 _accumulate_gradients * per_replica_loss = self.args.strategy.experimental_run_v2( /local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/distribute/one_device_strategy.py:180实验_运行_v2 返回super(OneDeviceStrategy,self).experimental_run_v2(fn,args,kwargs) /databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py:511 _forward * per_example_loss,_ = self._run_model(功能,标签,为True) /databricks/python/lib/python3.7/site-packages/transformers/trainer_tf.py:532 _run_model * 输出= self.model(功能,训练=训练,**标签)[:2] /local_disk0/pythonVirtualEnvDirs/virtualEnv-f56565e5-e45b-447a-b7df-50daf9109495/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py:778 致电 输出= call_fn(cast_inputs,* args,** kwargs)
TypeError: tf__call() got an unexpected keyword argument 'is_impossible'