發現乙個很好用的預訓練模型**:裡面有超級多的預訓練模型,常見的bert,robert,gpt,electra,xlnet等。
使用方法也很簡單,
以bert為例:
載入時只需要兩步
1.from transformers.models.bert.modeling_bert import bertforsequenceclassification,bertfortokenclassification構建乙個bert-ner模型也很方便2.bertfortokenclassification.from_pretrained(pretrained_model_name_or_path=pretrain_model_path,config =self.model_config)
class bert_ner_model(nn.module):def __init__(self,pretrain_model_path):
super(bert_ner_model, self).__init__()
self.model_config = bertconfig.from_pretrained(pretrain_model_path)
# 設定類別數
self.model_config.num_labels = 63
self.bert_model = bertfortokenclassification.from_pretrained(pretrained_model_name_or_path=pretrain_model_path,config =self.model_config)
def forward(self,token_ids,type_token_ids,attention_mask_ids,labels):小夥伴們,趕快使用起來吧。pretrain_features = self.bert_model(token_ids,type_token_ids,attention_mask_ids).logits
loss = f.cross_entropy(pretrain_features,labels.flatten())
predict = torch.argmax(pretrain_features,dim=1)
return loss,predict
預訓練模型
elmo elmo是一種是基於特徵的語言模型,用預訓練好的語言模型,生成更好的特徵。而elmo的主要做法是先訓練乙個完整的語言模型,再用這個語言模型去處理需要訓練的文字,生成相應的詞向量。文字分類實戰 九 elmo 預訓練模型 在nlp領域,使用預訓練模型或元件的監督學習任務被稱為下游任務 bert...
bert預訓練模型解讀 Bert 預訓練小結
最近正在預訓練乙個中文pytorch版本的bert,模型部分 是基於huggingface發布的版本,預訓練過程還是參考google的 值得吐槽的是huggingface之前發布的分支名叫pytorch pretrain bert,後來又加上了gpt2 xlnet一系列當紅模型,結果索性改了個名字叫...
TensorFlow Keras預訓練模型測試
densenet121 densenet169 densenet201 inceptionresnetv2 inceptionv3 mobilenet nasnetlarge nasnetmobile resnet50 vgg16 vgg19 xception 這些人工神經網路模型的類都有各自對應的...