initial_coverage is always zeros of shape [encoder_length], which shape must be determined programmatically dureing network computation. This method also sets self.coverage_weights, a separate transform of encoder_outputs which is used to determine coverage
(self, model)
| 1281 | return self.decoder_cell.prepare_input(model, input_blob) |
| 1282 | |
| 1283 | def build_initial_coverage(self, model): |
| 1284 | """ |
| 1285 | initial_coverage is always zeros of shape [encoder_length], |
| 1286 | which shape must be determined programmatically dureing network |
| 1287 | computation. |
| 1288 | |
| 1289 | This method also sets self.coverage_weights, a separate transform |
| 1290 | of encoder_outputs which is used to determine coverage contribution |
| 1291 | tp attention. |
| 1292 | """ |
| 1293 | assert self.attention_type == AttentionType.SoftCoverage |
| 1294 | |
| 1295 | # [encoder_length, batch_size, encoder_output_dim] |
| 1296 | self.coverage_weights = brew.fc( |
| 1297 | model, |
| 1298 | self.encoder_outputs, |
| 1299 | self.scope('coverage_weights'), |
| 1300 | dim_in=self.encoder_output_dim, |
| 1301 | dim_out=self.encoder_output_dim, |
| 1302 | axis=2, |
| 1303 | ) |
| 1304 | |
| 1305 | encoder_length = model.net.Slice( |
| 1306 | model.net.Shape(self.encoder_outputs), |
| 1307 | starts=[0], |
| 1308 | ends=[1], |
| 1309 | ) |
| 1310 | if ( |
| 1311 | scope.CurrentDeviceScope() is not None and |
| 1312 | core.IsGPUDeviceType(scope.CurrentDeviceScope().device_type) |
| 1313 | ): |
| 1314 | encoder_length = model.net.CopyGPUToCPU( |
| 1315 | encoder_length, |
| 1316 | 'encoder_length_cpu', |
| 1317 | ) |
| 1318 | # total attention weight applied across decoding steps_per_checkpoint |
| 1319 | # shape: [encoder_length] |
| 1320 | initial_coverage = model.net.ConstantFill( |
| 1321 | encoder_length, |
| 1322 | self.scope('initial_coverage'), |
| 1323 | value=0.0, |
| 1324 | input_as_shape=1, |
| 1325 | ) |
| 1326 | return initial_coverage |
| 1327 | |
| 1328 | def get_state_names(self): |
| 1329 | state_names = list(self.decoder_cell.get_state_names()) |
no test coverage detected