本文整理匯總了Python中transformers.PreTrainedModel方法的典型用法代碼示例。如果您正苦於以下問題:Python transformers.PreTrainedModel方法的具體用法?Python transformers.PreTrainedModel怎麽用?Python transformers.PreTrainedModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類transformers
的用法示例。
在下文中一共展示了transformers.PreTrainedModel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import transformers [as 別名]
# 或者: from transformers import PreTrainedModel [as 別名]
def __init__(
self,
bert_model: PreTrainedModel,
top_layer_only: bool = False,
max_pieces: int = 512,
num_start_tokens: int = 1,
num_end_tokens: int = 1
) -> None:
super().__init__()
# self.bert_model = bert_model
self.bert_model = deepcopy(bert_model)
self.output_dim = bert_model.config.hidden_size
self.max_pieces = max_pieces
self.num_start_tokens = num_start_tokens
self.num_end_tokens = num_end_tokens
self._scalar_mix = None
示例2: load
# 需要導入模塊: import transformers [as 別名]
# 或者: from transformers import PreTrainedModel [as 別名]
def load(cls, model_name: str, cache_model: bool = True) -> PreTrainedModel:
if model_name in cls._cache:
return PretrainedBertModel._cache[model_name]
model = AutoModel.from_pretrained(model_name)
if cache_model:
cls._cache[model_name] = model
return model