Instructions to use morpheushoc/test_bert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use morpheushoc/test_bert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="morpheushoc/test_bert", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("morpheushoc/test_bert", trust_remote_code=True) model = AutoModel.from_pretrained("morpheushoc/test_bert", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
| from torch import nn | |
| from easydict import EasyDict as MyEasyDict | |
| from transformers import BertModel, PreTrainedModel, BertConfig, PretrainedConfig | |
| class BertConfig(PretrainedConfig): | |
| model_type = "bert" | |
| def __init__( | |
| self, | |
| model_config=None, | |
| **kwargs): | |
| super().__init__(**kwargs) | |
| self.model_config = MyEasyDict(model_config) | |
| class BERTClassifier(PreTrainedModel): | |
| config_class = BertConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.bert = BertModel(config) | |
| self.dropout = nn.Dropout(0.1) | |
| self.fc = nn.Linear(self.bert.config.hidden_size, 16) | |
| def forward(self, input_ids, attention_mask): | |
| outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask) | |
| pooled_output = outputs.pooler_output | |
| x = self.dropout(pooled_output) | |
| logits = self.fc(x) | |
| return logits | |
| def print_test(self, x): | |
| return "lmao" | |
| if __name__ == "__main__": | |
| from transformers import BertConfig, BertModel, BertForMaskedLM, AutoConfig | |
| # Initializing a BERT google-bert/bert-base-uncased style configuration | |
| config = AutoConfig.from_pretrained('google-bert/bert-base-uncased', trust_remote_code=True) | |
| model = BERTClassifier(config) |