huseinzol05 commited on
Commit
f0ea66b
·
verified ·
1 Parent(s): 7a7a525

Upload ConformerEncoder

Browse files
Files changed (3) hide show
  1. config.json +21 -0
  2. conformer.py +40 -0
  3. model.safetensors +3 -0
config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ConformerEncoder"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "conformer.ConformerConfig",
7
+ "AutoModel": "conformer.ConformerEncoder"
8
+ },
9
+ "conformer_depthwise_conv_kernel_size": 31,
10
+ "conformer_dropout": 0.1,
11
+ "conformer_ffn_dim": 576,
12
+ "conformer_input_dim": 144,
13
+ "conformer_num_heads": 4,
14
+ "conformer_num_layers": 8,
15
+ "input_dim": 80,
16
+ "model_type": "conformer",
17
+ "output_dim": 40,
18
+ "time_reduction_stride": 4,
19
+ "torch_dtype": "float32",
20
+ "transformers_version": "4.35.2"
21
+ }
conformer.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torchaudio.models import Conformer
2
+ from torchaudio.models.rnnt import _TimeReduction
3
+ from transformers import PretrainedConfig, PreTrainedModel
4
+ import torch
5
+ from typing import List, Tuple, Optional
6
+
7
+
8
+ class ConformerConfig(PretrainedConfig):
9
+ model_type = 'conformer'
10
+
11
+
12
+ class ConformerEncoder(PreTrainedModel):
13
+ def __init__(
14
+ self,
15
+ config,
16
+ ) -> None:
17
+ super().__init__(config)
18
+ self.time_reduction = _TimeReduction(config.time_reduction_stride)
19
+ self.input_linear = torch.nn.Linear(
20
+ config.input_dim * config.time_reduction_stride,
21
+ config.conformer_input_dim)
22
+ self.conformer = Conformer(
23
+ num_layers=config.conformer_num_layers,
24
+ input_dim=config.conformer_input_dim,
25
+ ffn_dim=config.conformer_ffn_dim,
26
+ num_heads=config.conformer_num_heads,
27
+ depthwise_conv_kernel_size=config.conformer_depthwise_conv_kernel_size,
28
+ dropout=config.conformer_dropout,
29
+ use_group_norm=True,
30
+ convolution_first=True,
31
+ )
32
+ self.output_linear = torch.nn.Linear(config.conformer_input_dim, config.output_dim)
33
+
34
+ def forward(self, input: torch.Tensor,
35
+ lengths: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
36
+ time_reduction_out, time_reduction_lengths = self.time_reduction(input, lengths)
37
+ input_linear_out = self.input_linear(time_reduction_out)
38
+ x, lengths = self.conformer(input_linear_out, time_reduction_lengths)
39
+ output_linear_out = self.output_linear(x)
40
+ return output_linear_out, lengths
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98b344ee3d7122a46057f410108a03413a6bb69cbe78496c4a3c35a50c5fc1c0
3
+ size 15780592