本文整理汇总了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()