Upload Flowformer
Browse files- configuration_flowformer.py +1 -11
- model_flowformer.py +14 -19
configuration_flowformer.py
CHANGED
@@ -2,7 +2,7 @@ from transformers import PretrainedConfig
|
|
2 |
|
3 |
class FlowformerConfig(PretrainedConfig):
|
4 |
r"""
|
5 |
-
This is the configuration class to store the configuration of a
|
6 |
Flowformer model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
7 |
with the defaults will yield a similar configuration to that of out model for ALL data (https://arxiv.org/abs/2108.10072).
|
8 |
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
@@ -22,16 +22,6 @@ class FlowformerConfig(PretrainedConfig):
|
|
22 |
The dimensionality of the input.
|
23 |
markers (`list`, *optional*, defaults to ["TIME", "FSC-A", "FSC-W", "SSC-A", "CD20", "CD10", "CD45", "CD34", "CD19", "CD38", "SY41"]):
|
24 |
The list of markers.
|
25 |
-
Example:
|
26 |
-
```python
|
27 |
-
>>> from transformers import FlowformerConfig, FlowformerModel
|
28 |
-
>>> # Initializing a Flowformer configuration
|
29 |
-
>>> configuration = FlowformerConfig()
|
30 |
-
>>> # Initializing a model (with random weights) from the Flowformer configuration
|
31 |
-
>>> model = FlowformerModel(configuration)
|
32 |
-
>>> # Accessing the model configuration
|
33 |
-
>>> configuration = model.config
|
34 |
-
```
|
35 |
"""
|
36 |
def __init__(self,
|
37 |
dim_hidden: int=32,
|
|
|
2 |
|
3 |
class FlowformerConfig(PretrainedConfig):
|
4 |
r"""
|
5 |
+
This is the configuration class to store the configuration of a `Flowformer`. It is used to instantiate an
|
6 |
Flowformer model according to the specified arguments, defining the model architecture. Instantiating a configuration
|
7 |
with the defaults will yield a similar configuration to that of out model for ALL data (https://arxiv.org/abs/2108.10072).
|
8 |
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
|
|
22 |
The dimensionality of the input.
|
23 |
markers (`list`, *optional*, defaults to ["TIME", "FSC-A", "FSC-W", "SSC-A", "CD20", "CD10", "CD45", "CD34", "CD19", "CD38", "SY41"]):
|
24 |
The list of markers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
"""
|
26 |
def __init__(self,
|
27 |
dim_hidden: int=32,
|
model_flowformer.py
CHANGED
@@ -4,7 +4,6 @@ import torch.nn.functional as F
|
|
4 |
from torch.nn.functional import binary_cross_entropy_with_logits
|
5 |
import math
|
6 |
from transformers import PreTrainedModel
|
7 |
-
from transformers.utils import add_start_docstrings, add_start_docstrings_to_model_forward
|
8 |
from .configuration_flowformer import FlowformerConfig
|
9 |
|
10 |
|
@@ -61,29 +60,17 @@ class ISAB(nn.Module):
|
|
61 |
|
62 |
return self.mab1(X, H)
|
63 |
|
64 |
-
|
|
|
|
|
65 |
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
|
66 |
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
|
67 |
behavior.
|
68 |
Parameters:
|
69 |
-
config (
|
70 |
Initializing with a config file does not load the weights associated with the model, only the
|
71 |
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
72 |
-
"""
|
73 |
-
|
74 |
-
FLOWFORMER_INPUTS_DOCSTRING = r"""
|
75 |
-
Args:
|
76 |
-
tensor (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_markers)`):
|
77 |
-
The sample used as a basis for the prediction.
|
78 |
-
labels (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
79 |
-
Optional ground truth lables for computing the loss.
|
80 |
-
markers (`list` of length `num_markers`):
|
81 |
-
The list of markers in the same order as the last dimension of the input tensor.
|
82 |
-
"""
|
83 |
-
|
84 |
-
|
85 |
-
@add_start_docstrings(FLOWFORMER_START_DOCSTRING)
|
86 |
-
class Flowformer(PreTrainedModel):
|
87 |
def __init__(self, config: FlowformerConfig):
|
88 |
super().__init__(config)
|
89 |
|
@@ -111,8 +98,16 @@ class Flowformer(PreTrainedModel):
|
|
111 |
def markers(self):
|
112 |
return self._pretrained_markers
|
113 |
|
114 |
-
@add_start_docstrings_to_model_forward(FLOWFORMER_INPUTS_DOCSTRING)
|
115 |
def forward(self, tensor: torch.Tensor, labels: torch.Tensor=None, markers: list=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
B, L, M = tensor.shape
|
117 |
if markers is not None:
|
118 |
assert len(markers) == M, "Number of markers in x and markers must be identical"
|
|
|
4 |
from torch.nn.functional import binary_cross_entropy_with_logits
|
5 |
import math
|
6 |
from transformers import PreTrainedModel
|
|
|
7 |
from .configuration_flowformer import FlowformerConfig
|
8 |
|
9 |
|
|
|
60 |
|
61 |
return self.mab1(X, H)
|
62 |
|
63 |
+
|
64 |
+
class Flowformer(PreTrainedModel):
|
65 |
+
r"""
|
66 |
This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it
|
67 |
as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and
|
68 |
behavior.
|
69 |
Parameters:
|
70 |
+
config (`FlowformerConfig`): Model configuration class with all the parameters of the model.
|
71 |
Initializing with a config file does not load the weights associated with the model, only the
|
72 |
configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.
|
73 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
def __init__(self, config: FlowformerConfig):
|
75 |
super().__init__(config)
|
76 |
|
|
|
98 |
def markers(self):
|
99 |
return self._pretrained_markers
|
100 |
|
|
|
101 |
def forward(self, tensor: torch.Tensor, labels: torch.Tensor=None, markers: list=None):
|
102 |
+
r"""
|
103 |
+
Args:
|
104 |
+
tensor (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_markers)`):
|
105 |
+
The sample used as a basis for the prediction.
|
106 |
+
labels (`torch.FloatTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
107 |
+
Optional ground truth lables for computing the loss.
|
108 |
+
markers (`list` of length `num_markers`):
|
109 |
+
The list of markers in the same order as the last dimension of the input tensor.
|
110 |
+
"""
|
111 |
B, L, M = tensor.shape
|
112 |
if markers is not None:
|
113 |
assert len(markers) == M, "Number of markers in x and markers must be identical"
|