Args: inputs: (seq_len, batch_size, dim_input) input used to compute attention context_vectors: (num_chars, batch_size, dim_context) can be onehot encoding or embeddings init_means: (batch_size, num_mixtures) or (1, batch_s
(
self,
inputs: torch.Tensor,
context_vectors: torch.Tensor,
init_means: torch.Tensor = None,
extra_chars: int = 0,
)
| 93 | return torch.zeros(batch_size, self.num_mixtures, device=device) |
| 94 | |
| 95 | def forward( |
| 96 | self, |
| 97 | inputs: torch.Tensor, |
| 98 | context_vectors: torch.Tensor, |
| 99 | init_means: torch.Tensor = None, |
| 100 | extra_chars: int = 0, |
| 101 | ): |
| 102 | """ |
| 103 | Args: |
| 104 | inputs: (seq_len, batch_size, dim_input) |
| 105 | input used to compute attention |
| 106 | context_vectors: (num_chars, batch_size, dim_context) |
| 107 | can be onehot encoding or embeddings |
| 108 | init_means: (batch_size, num_mixtures) or (1, batch_size, num_mixtures) |
| 109 | current means of the gaussians (None: all zeros) |
| 110 | extra_chars: |
| 111 | how many extra char_idx to calculate |
| 112 | |
| 113 | Returns: |
| 114 | attn_contexts (seq_len, batch_size, dim_context) |
| 115 | one for each time step |
| 116 | attn_weights (seq_len, batch_size, total_char) |
| 117 | one for each time step, total_char = num_char + extra_chars |
| 118 | means (seq_len, batch_size, num_mixtures) |
| 119 | mean of each gaussian window |
| 120 | vars (seq_len, batch_size, num_mixtures) |
| 121 | variance of each gaussian window |
| 122 | weights (seq_len, batch_size, num_mixtures) |
| 123 | weights of each gaussian window |
| 124 | """ |
| 125 | seq_len = inputs.size(0) |
| 126 | batch_size = inputs.size(1) |
| 127 | num_char = context_vectors.size(0) |
| 128 | dim_context = context_vectors.size(2) |
| 129 | |
| 130 | total_char = num_char + extra_chars |
| 131 | |
| 132 | attn_weight_dict = self.compute_attn_weights( |
| 133 | inputs=inputs, |
| 134 | total_char=total_char, |
| 135 | init_means=init_means, |
| 136 | ) |
| 137 | |
| 138 | attn_contexts = self.compute_attn_contexts( |
| 139 | attn_weights=attn_weight_dict['attn_weights'], |
| 140 | context_vectors=context_vectors, |
| 141 | ) |
| 142 | |
| 143 | return ( |
| 144 | attn_contexts, |
| 145 | attn_weight_dict['attn_weights'], |
| 146 | attn_weight_dict['means'], |
| 147 | attn_weight_dict['vars'], |
| 148 | attn_weight_dict['weights'], |
| 149 | ) |
| 150 | |
| 151 | # if init_means is None: |
| 152 | # init_means = self.get_init_means(batch_size, device=inputs.device) # (batch_size,num_mixtures) |
nothing calls this directly
no test coverage detected