Instructions to use ctheodoris/Geneformer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ctheodoris/Geneformer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="ctheodoris/Geneformer")# Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("ctheodoris/Geneformer") model = AutoModelForMaskedLM.from_pretrained("ctheodoris/Geneformer") - Inference
- Notebooks
- Google Colab
- Kaggle
Update geneformer/mtl/model.py
Browse fileschange in line 36:
old:
self.bert = BertModel(self.config)
new:
self.bert = BertModel.from_pretrained(pretrained_path)
Reason:
BertModel() is initializing random weights instead of using weights from pretrained model. This results in training from scratch instead of finetuning the model.
BertModel.from_pretrained() initializes the pretrained weights.
Tested with training with MTLClassifier both ways and also via:
pretrained_path = "/Geneformer/Geneformer-V2-104M"
ref = BertModel.from_pretrained(pretrained_path)
mtl = GeneformerMultiTask(pretrained_path, num_labels_list=[2])
print("mtl layer0 q mean:", mtl.bert.encoder.layer[0].attention.self.query.weight.abs().mean().item())
print("ref layer0 q mean:", ref.encoder.layer[0].attention.self.query.weight.abs().mean().item())
- geneformer/mtl/model.py +1 -1
|
@@ -33,7 +33,7 @@ class GeneformerMultiTask(nn.Module):
|
|
| 33 |
):
|
| 34 |
super(GeneformerMultiTask, self).__init__()
|
| 35 |
self.config = BertConfig.from_pretrained(pretrained_path)
|
| 36 |
-
self.bert = BertModel
|
| 37 |
self.num_labels_list = num_labels_list
|
| 38 |
self.use_task_weights = use_task_weights
|
| 39 |
self.dropout = nn.Dropout(dropout_rate)
|
|
|
|
| 33 |
):
|
| 34 |
super(GeneformerMultiTask, self).__init__()
|
| 35 |
self.config = BertConfig.from_pretrained(pretrained_path)
|
| 36 |
+
self.bert = BertModel.from_pretrained(pretrained_path)
|
| 37 |
self.num_labels_list = num_labels_list
|
| 38 |
self.use_task_weights = use_task_weights
|
| 39 |
self.dropout = nn.Dropout(dropout_rate)
|