【发布时间】:2021-05-23 21:48:20
【问题描述】:
我遵循了下面给出的基本示例,来自:https://huggingface.co/transformers/training.html
from transformers import TFBertForSequenceClassification, TFTrainer, TFTrainingArguments
model = TFBertForSequenceClassification.from_pretrained("bert-large-uncased")
training_args = TFTrainingArguments(
output_dir='./results', # output directory
num_train_epochs=3, # total # of training epochs
per_device_train_batch_size=16, # batch size per device during training
per_device_eval_batch_size=64, # batch size for evaluation
warmup_steps=500, # number of warmup steps for learning rate scheduler
weight_decay=0.01, # strength of weight decay
logging_dir='./logs', # directory for storing logs
)
trainer = TFTrainer(
model=model, # the instantiated ???? Transformers model to be trained
args=training_args, # training arguments, defined above
train_dataset=tfds_train_dataset, # tensorflow_datasets training dataset
eval_dataset=tfds_test_dataset # tensorflow_datasets evaluation dataset
)
trainer.train()
但似乎没有办法为分类器指定损失函数。 For-ex,如果我对二元分类问题进行微调,我会使用
tf.keras.losses.BinaryCrossentropy(from_logits=True)
否则我会使用
tf.keras.losses.CategoricalCrossentropy(from_logits=True)
我的设置如下:
transformers==4.3.2
tensorflow==2.3.1
python==3.6.12
【问题讨论】:
标签: python-3.x tensorflow nlp huggingface-transformers