有没有办法在没有配置文件的情况下使用预训练的变压器模型?
Is there a way to use a pre-trained transformers model without the configuration file?
我想在问答系统上微调预训练的变形金刚模型。该模型在大型工程和科学相关语料库上进行了预训练。
我得到了一个包含模型权重的“checkpoint.pt”文件。他们还为我提供了一个“bert_config.json”文件,但我不确定这是否是正确的配置文件。
from transformers import AutoModel, AutoTokenizer, AutoConfig
MODEL_PATH = "./checkpoint.pt"
config = AutoConfig.from_pretrained("./bert_config.json")
model = AutoModel.from_pretrained(MODEL_PATH, config=config)
我认为 bert_config.json 与“./checkpoint.pt”文件不匹配的原因是,当我使用上面的代码加载模型时,出现如下错误.
Some weights of the model checkpoint at ./aerobert/phase2_ckpt_4302592.pt were not used when initializing BertModel: ['files', 'optimizer', 'model', 'master params']
- This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of BertModel were not initialized from the model checkpoint at ./aerobert/phase2_ckpt_4302592.pt and are newly initialized: ['encoder.layer.2.attention.output.LayerNorm.weight', 'encoder.layer.6.output.LayerNorm.bias', 'encoder.layer.7.intermediate.dense.bias', 'encoder.layer.2.output.LayerNorm.bias', 'encoder.layer.21.attention.self.value.bias', 'encoder.layer.11.attention.self.value.bias', ............
如果我假设“bert_config.json”不是正确的是正确的,有没有办法在没有 config.json 文件的情况下正确加载此模型?
有没有办法从 checkpoint.pt 文件保存的权重中查看模型架构?
这是一条警告消息而不是错误。
表示预训练模型在某些任务(如问答、传销等)中预训练,如果你自己的微调任务与预训练任务相同,那么不是预期的;除非这 是预期的 因为一些预训练模型的 pooler 不会在微调中使用。
但此消息并不意味着 bert_config.json
不正确。您可以在 huggingface's official colab notebook
上进行测试
您可以在此 issue 中找到更多信息。
我想在问答系统上微调预训练的变形金刚模型。该模型在大型工程和科学相关语料库上进行了预训练。
我得到了一个包含模型权重的“checkpoint.pt”文件。他们还为我提供了一个“bert_config.json”文件,但我不确定这是否是正确的配置文件。
from transformers import AutoModel, AutoTokenizer, AutoConfig
MODEL_PATH = "./checkpoint.pt"
config = AutoConfig.from_pretrained("./bert_config.json")
model = AutoModel.from_pretrained(MODEL_PATH, config=config)
我认为 bert_config.json 与“./checkpoint.pt”文件不匹配的原因是,当我使用上面的代码加载模型时,出现如下错误.
Some weights of the model checkpoint at ./aerobert/phase2_ckpt_4302592.pt were not used when initializing BertModel: ['files', 'optimizer', 'model', 'master params']
- This IS expected if you are initializing BertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing BertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model). Some weights of BertModel were not initialized from the model checkpoint at ./aerobert/phase2_ckpt_4302592.pt and are newly initialized: ['encoder.layer.2.attention.output.LayerNorm.weight', 'encoder.layer.6.output.LayerNorm.bias', 'encoder.layer.7.intermediate.dense.bias', 'encoder.layer.2.output.LayerNorm.bias', 'encoder.layer.21.attention.self.value.bias', 'encoder.layer.11.attention.self.value.bias', ............
如果我假设“bert_config.json”不是正确的是正确的,有没有办法在没有 config.json 文件的情况下正确加载此模型?
有没有办法从 checkpoint.pt 文件保存的权重中查看模型架构?
这是一条警告消息而不是错误。
表示预训练模型在某些任务(如问答、传销等)中预训练,如果你自己的微调任务与预训练任务相同,那么不是预期的;除非这 是预期的 因为一些预训练模型的 pooler 不会在微调中使用。
但此消息并不意味着 bert_config.json
不正确。您可以在 huggingface's official colab notebook
您可以在此 issue 中找到更多信息。