ljw20180420 commited on
Commit
4dc7091
·
verified ·
1 Parent(s): 66376de

Upload folder using huggingface_hub

Browse files
inDelphi_model/README.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags:
4
+ - generated_from_trainer
5
+ datasets:
6
+ - crispr_data
7
+ model-index:
8
+ - name: SX_ispymac_inDelphi
9
+ results: []
10
+ ---
11
+
12
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
13
+ should probably proofread and complete it, then remove this comment. -->
14
+
15
+ # SX_ispymac_inDelphi
16
+
17
+ This model is a fine-tuned version of [](https://huggingface.co/) on the crispr_data dataset.
18
+ It achieves the following results on the evaluation set:
19
+ - Loss: -100.9903
20
+
21
+ ## Model description
22
+
23
+ More information needed
24
+
25
+ ## Intended uses & limitations
26
+
27
+ More information needed
28
+
29
+ ## Training and evaluation data
30
+
31
+ More information needed
32
+
33
+ ## Training procedure
34
+
35
+ ### Training hyperparameters
36
+
37
+ The following hyperparameters were used during training:
38
+ - learning_rate: 0.001
39
+ - train_batch_size: 100
40
+ - eval_batch_size: 100
41
+ - seed: 63036
42
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
43
+ - lr_scheduler_type: linear
44
+ - lr_scheduler_warmup_ratio: 0.05
45
+ - num_epochs: 30.0
46
+
47
+ ### Training results
48
+
49
+ | Training Loss | Epoch | Step | Validation Loss |
50
+ |:-------------:|:-----:|:----:|:---------------:|
51
+ | -79.5476 | 1.0 | 326 | -92.0552 |
52
+ | -99.7202 | 2.0 | 652 | -100.0530 |
53
+ | -101.9133 | 3.0 | 978 | -100.5825 |
54
+ | -102.2183 | 4.0 | 1304 | -100.7356 |
55
+ | -102.3128 | 5.0 | 1630 | -100.6958 |
56
+ | -102.3754 | 6.0 | 1956 | -100.9292 |
57
+ | -102.4144 | 7.0 | 2282 | -100.9071 |
58
+ | -102.422 | 8.0 | 2608 | -100.9715 |
59
+ | -102.4247 | 9.0 | 2934 | -100.7776 |
60
+ | -102.4267 | 10.0 | 3260 | -100.8441 |
61
+ | -102.4171 | 11.0 | 3586 | -100.9532 |
62
+ | -102.4438 | 12.0 | 3912 | -100.9826 |
63
+ | -102.4623 | 13.0 | 4238 | -100.9485 |
64
+ | -102.4658 | 14.0 | 4564 | -100.9664 |
65
+ | -102.4692 | 15.0 | 4890 | -100.9808 |
66
+ | -102.4732 | 16.0 | 5216 | -100.9686 |
67
+ | -102.468 | 17.0 | 5542 | -100.9455 |
68
+ | -102.4662 | 18.0 | 5868 | -100.9530 |
69
+ | -102.4805 | 19.0 | 6194 | -100.9872 |
70
+ | -102.4865 | 20.0 | 6520 | -100.8664 |
71
+ | -102.4719 | 21.0 | 6846 | -100.9966 |
72
+ | -102.4959 | 22.0 | 7172 | -100.9938 |
73
+ | -102.4963 | 23.0 | 7498 | -100.9695 |
74
+ | -102.4953 | 24.0 | 7824 | -100.9951 |
75
+ | -102.5011 | 25.0 | 8150 | -100.9904 |
76
+ | -102.5003 | 26.0 | 8476 | -100.9612 |
77
+ | -102.5097 | 27.0 | 8802 | -100.9850 |
78
+ | -102.5167 | 28.0 | 9128 | -100.9925 |
79
+ | -102.5139 | 29.0 | 9454 | -100.9887 |
80
+ | -102.517 | 30.0 | 9780 | -100.9903 |
81
+
82
+
83
+ ### Framework versions
84
+
85
+ - Transformers 4.44.2
86
+ - Pytorch 2.4.0+cu124
87
+ - Datasets 2.21.0
88
+ - Tokenizers 0.19.1
inDelphi_model/config.json CHANGED
@@ -1,6 +1,5 @@
1
  {
2
  "DELLEN_LIMIT": 60,
3
- "_name_or_path": "/home/ljw/sdc1/CRISPR_results/inDelphi/SX_ispymac_inDelphi",
4
  "architectures": [
5
  "inDelphiModel"
6
  ],
 
1
  {
2
  "DELLEN_LIMIT": 60,
 
3
  "architectures": [
4
  "inDelphiModel"
5
  ],
inDelphi_model/insertion_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:83f2cf9363b2a32d6e8267bf5df06ac9bbc7e6a231996bcbbd243eaa3768d3d3
3
+ size 2868606
inDelphi_model/model.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig, PreTrainedModel
2
+ import torch
3
+ import torch.nn.functional as F
4
+ import torch.nn as nn
5
+
6
+ class inDelphiConfig(PretrainedConfig):
7
+ model_type = "inDelphi"
8
+ label_names = ["genotype_count", "total_del_len_count"]
9
+
10
+ def __init__(
11
+ self,
12
+ DELLEN_LIMIT = 60, # the upper limit of deletion length (strictly less than DELLEN_LIMIT)
13
+ mid_dim = 16, # the size of middle layer of MLP
14
+ seed = 63036, # random seed for intialization
15
+ **kwargs,
16
+ ):
17
+ self.DELLEN_LIMIT = DELLEN_LIMIT
18
+ self.mid_dim = mid_dim
19
+ self.seed = seed
20
+ super().__init__(**kwargs)
21
+
22
+ class inDelphiModel(PreTrainedModel):
23
+ config_class = inDelphiConfig
24
+
25
+ def __init__(self, config):
26
+ super().__init__(config)
27
+ # In more recent versions of PyTorch, you no longer need to explicitly register_parameter, it's enough to set a member of your nn.Module with nn.Parameter to "notify" pytorch that this variable should be treated as a trainable parameter (https://stackoverflow.com/questions/59234238/how-to-add-parameters-in-module-class-in-pytorch-custom-model).
28
+ self.generator = torch.Generator().manual_seed(config.seed)
29
+ self.DELLEN_LIMIT = config.DELLEN_LIMIT
30
+ self.register_buffer('del_lens', torch.arange(1, config.DELLEN_LIMIT, dtype=torch.float32))
31
+ self.mh_in_layer = nn.Linear(in_features=2, out_features=config.mid_dim)
32
+ self.mh_mid_layer = nn.Linear(in_features=config.mid_dim, out_features=config.mid_dim)
33
+ self.mh_out_layer = nn.Linear(in_features=config.mid_dim, out_features=1)
34
+ self.mhless_in_layer = nn.Linear(in_features=1, out_features=config.mid_dim)
35
+ self.mhless_mid_layer = nn.Linear(in_features=config.mid_dim, out_features=config.mid_dim)
36
+ self.mhless_out_layer = nn.Linear(in_features=config.mid_dim, out_features=1)
37
+ self.mid_active = self.sigmoid
38
+ self.out_active = self.logit_to_weight
39
+ self.initialize_weights()
40
+
41
+ def initialize_weights(self):
42
+ for m in self.modules():
43
+ if isinstance(m, nn.Linear):
44
+ nn.init.normal_(m.weight, mean=0, std=1, generator=self.generator)
45
+ if m.bias is not None:
46
+ nn.init.constant_(m.bias, 0)
47
+
48
+ def forward(self, mh_input, mh_del_len, genotype_count=None, total_del_len_count=None):
49
+ batch_size = mh_input.shape[0]
50
+ mh_weight = self.mh_in_layer(mh_input)
51
+ mh_weight = self.mid_active(mh_weight)
52
+ mh_weight = self.mh_mid_layer(mh_weight)
53
+ mh_weight = self.mid_active(mh_weight)
54
+ mh_weight = self.mh_out_layer(mh_weight)
55
+ mh_weight = self.out_active(mh_weight, mh_del_len)
56
+
57
+ mhless_weight = self.mhless_in_layer(self.del_lens[:, None])
58
+ mhless_weight = self.mid_active(mhless_weight)
59
+ mhless_weight = self.mhless_mid_layer(mhless_weight)
60
+ mhless_weight = self.mid_active(mhless_weight)
61
+ mhless_weight = self.mhless_out_layer(mhless_weight)
62
+ mhless_weight = self.out_active(mhless_weight, self.del_lens)
63
+
64
+ total_del_len_weight = torch.zeros(batch_size, mhless_weight.shape[0] + 1, dtype=mh_weight.dtype, device=mh_weight.device).scatter_add(dim=1, index=mh_del_len - 1, src=mh_weight)[:, :-1] + mhless_weight
65
+ if genotype_count is not None and total_del_len_count is not None:
66
+ loss = self.negative_correlation(mh_weight, mhless_weight, total_del_len_weight, genotype_count, total_del_len_count)
67
+ return {
68
+ "mh_weight": mh_weight,
69
+ "mhless_weight": mhless_weight,
70
+ "total_del_len_weight": total_del_len_weight,
71
+ "loss": loss
72
+ }
73
+ return {
74
+ "mh_weight": mh_weight,
75
+ "mhless_weight": mhless_weight,
76
+ "total_del_len_weight": total_del_len_weight
77
+ }
78
+
79
+ def logit_to_weight(self, logits, del_lens):
80
+ return torch.exp(logits.squeeze() - 0.25 * del_lens) * (del_lens < self.DELLEN_LIMIT)
81
+
82
+ def sigmoid(self, x):
83
+ return 0.5 * (F.tanh(x) + 1)
84
+
85
+ def negative_correlation(self, mh_weight, mhless_weight, total_del_len_weight, genotype_count, total_del_len_count):
86
+ batch_size = mh_weight.shape[0]
87
+ genotype_pearson = (
88
+ F.normalize(
89
+ torch.cat(
90
+ (mh_weight, mhless_weight.expand(batch_size, -1)),
91
+ dim = 1
92
+ ),
93
+ p=2.0,
94
+ dim=1
95
+ ) *
96
+ F.normalize(genotype_count, p=2.0, dim=1)
97
+ ).sum()
98
+
99
+ total_del_len_pearson = (
100
+ F.normalize(total_del_len_weight, p=2.0, dim=1) *
101
+ F.normalize(total_del_len_count, p=2.0, dim=1)
102
+ ).sum()
103
+
104
+ return -genotype_pearson - total_del_len_pearson
inDelphi_model/runs/Nov20_09-57-19_ljw-System-Product-Name/events.out.tfevents.1732067840.ljw-System-Product-Name.1186644.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b607194c1fbfaf19b662444c2a98ed15bc1e83486249d67666d55ea1ba1362d
3
+ size 19414
inDelphi_model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b8b1e3b72b95617cf6e0f5e9723ac37039c4f7f61f2f73f8cf461633a17b0a4b
3
+ size 5304