gpt4 book ai didi

python - 具有 dropout 设置的 Transformers 预训练模型

转载 作者:行者123 更新时间:2023-12-04 03:47:21 37 4
gpt4 key购买 nike

我正在尝试使用 Transformer 的 Huggingface 预训练模型 bert-base-uncased ,但我想增加辍学率。 from_pretrained 中没有提及此内容方法,但 colab 运行下面的对象实例化没有任何问题。我在 classtransformers.BertConfig 中看到了这些 dropout 参数文档。
我是否在以正确的方式使用 bert-base-uncased 和改变 dropout?

model = BertForSequenceClassification.from_pretrained(
pretrained_model_name_or_path='bert-base-uncased',
num_labels=2,
output_attentions = False,
output_hidden_states = False,
attention_probs_dropout_prob=0.5,
hidden_dropout_prob=0.5
)

最佳答案

是的,这是正确的,但请注意有两个 dropout 参数,并且您使用的是特定的 Bert 模型,即 BertForSequenceClassification .
同样按照文档的建议,您可以先定义配置,然后按以下方式定义:

from transformers import BertModel, BertConfig

# Initializing a BERT bert-base-uncased style configuration
configuration = BertConfig()

# Initializing a model from the bert-base-uncased style configuration
model = BertModel(configuration)

# Accessing the model configuration
configuration = model.config

关于python - 具有 dropout 设置的 Transformers 预训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64947064/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com