本文整理匯總了Python中transformers.modeling_bert.BertModel方法的典型用法代碼示例。如果您正苦於以下問題:Python modeling_bert.BertModel方法的具體用法?Python modeling_bert.BertModel怎麽用?Python modeling_bert.BertModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類transformers.modeling_bert
的用法示例。
在下文中一共展示了modeling_bert.BertModel方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config):
super(BertForSimMatchModel, self).__init__(config)
self.bert = BertModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.seq_relationship = nn.Linear(config.hidden_size, 2)
self.init_weights()
示例2: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config, weight=None):
super(BertForSequenceClassification, self).__init__(config)
self.num_labels = config.num_labels
self.bert = BertModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.classifier = nn.Linear(config.hidden_size, self.config.num_labels)
self.weight = weight
self.init_weights()
示例3: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config):
super().__init__(config)
self.bert = BertModel(config)
self.cls = BertOnlyMLMHead(config)
self.loss_fct = CrossEntropyLoss() # -100 index = padding token; initialize once to speed up.
self.init_weights()
示例4: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config, weight=None, sliding_window=False):
super(BertForSequenceClassification, self).__init__(config)
self.num_labels = config.num_labels
self.bert = BertModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.classifier = nn.Linear(config.hidden_size, self.config.num_labels)
self.weight = weight
self.sliding_window = sliding_window
self.init_weights()
示例5: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config, args, intent_label_lst, slot_label_lst):
super(JointBERT, self).__init__(config)
self.args = args
self.num_intent_labels = len(intent_label_lst)
self.num_slot_labels = len(slot_label_lst)
self.bert = BertModel(config=config) # Load pretrained bert
self.intent_classifier = IntentClassifier(config.hidden_size, self.num_intent_labels, args.dropout_rate)
self.slot_classifier = SlotClassifier(config.hidden_size, self.num_slot_labels, args.dropout_rate)
if args.use_crf:
self.crf = CRF(num_tags=self.num_slot_labels, batch_first=True)
示例6: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config):
super(BertForMultiLable, self).__init__(config)
self.bert = BertModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
self.init_weights()
示例7: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config, num_classes, vocab) -> None:
super(PairwiseClassifier, self).__init__(config)
self.bert = BertModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.classifier = nn.Linear(config.hidden_size, num_classes)
self.vocab = vocab
self.init_weights()
示例8: __init__
# 需要導入模塊: from transformers import modeling_bert [as 別名]
# 或者: from transformers.modeling_bert import BertModel [as 別名]
def __init__(self, config, num_classes, vocab) -> None:
super(SentenceClassifier, self).__init__(config)
self.bert = BertModel(config)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
self.classifier = nn.Linear(config.hidden_size, num_classes)
self.vocab = vocab
self.init_weights()