當前位置: 首頁>>代碼示例>>Python>>正文


Python modeling_bert.BertModel方法代碼示例

本文整理匯總了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() 
開發者ID:padeoe,項目名稱:cail2019,代碼行數:8,代碼來源:model.py

示例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() 
開發者ID:ThilinaRajapakse,項目名稱:simpletransformers,代碼行數:12,代碼來源:bert_model.py

示例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() 
開發者ID:howardhsu,項目名稱:BERT-for-RRC-ABSA,代碼行數:9,代碼來源:modeling.py

示例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() 
開發者ID:ThilinaRajapakse,項目名稱:simpletransformers,代碼行數:13,代碼來源:bert_model.py

示例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) 
開發者ID:monologg,項目名稱:JointBERT,代碼行數:14,代碼來源:modeling_jointbert.py

示例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() 
開發者ID:lonePatient,項目名稱:Bert-Multi-Label-Text-Classification,代碼行數:8,代碼來源:bert_for_multi_label.py

示例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() 
開發者ID:aisolab,項目名稱:nlp_classification,代碼行數:9,代碼來源:net.py

示例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() 
開發者ID:aisolab,項目名稱:nlp_classification,代碼行數:9,代碼來源:net.py


注:本文中的transformers.modeling_bert.BertModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。