Multilayer RNN via the composition of RNNCell instance. It is the responsibility of calling code to ensure the compatibility of the successive layers in terms of input/output dimensiality, etc., and to ensure that their blobs do not have name conflicts, typically by creating th
| 904 | |
| 905 | |
| 906 | class MultiRNNCell(RNNCell): |
| 907 | ''' |
| 908 | Multilayer RNN via the composition of RNNCell instance. |
| 909 | |
| 910 | It is the responsibility of calling code to ensure the compatibility |
| 911 | of the successive layers in terms of input/output dimensiality, etc., |
| 912 | and to ensure that their blobs do not have name conflicts, typically by |
| 913 | creating the cells with names that specify layer number. |
| 914 | |
| 915 | Assumes first state (recurrent output) for each layer should be the input |
| 916 | to the next layer. |
| 917 | ''' |
| 918 | |
| 919 | def __init__(self, cells, residual_output_layers=None, **kwargs): |
| 920 | ''' |
| 921 | cells: list of RNNCell instances, from input to output side. |
| 922 | |
| 923 | name: string designating network component (for scoping) |
| 924 | |
| 925 | residual_output_layers: list of indices of layers whose input will |
| 926 | be added elementwise to their output elementwise. (It is the |
| 927 | responsibility of the client code to ensure shape compatibility.) |
| 928 | Note that layer 0 (zero) cannot have residual output because of the |
| 929 | timing of prepare_input(). |
| 930 | |
| 931 | forward_only: used to construct inference-only network. |
| 932 | ''' |
| 933 | super().__init__(**kwargs) |
| 934 | self.cells = cells |
| 935 | |
| 936 | if residual_output_layers is None: |
| 937 | self.residual_output_layers = [] |
| 938 | else: |
| 939 | self.residual_output_layers = residual_output_layers |
| 940 | |
| 941 | output_index_per_layer = [] |
| 942 | base_index = 0 |
| 943 | for cell in self.cells: |
| 944 | output_index_per_layer.append( |
| 945 | base_index + cell.get_output_state_index(), |
| 946 | ) |
| 947 | base_index += len(cell.get_state_names()) |
| 948 | |
| 949 | self.output_connected_layers = [] |
| 950 | self.output_indices = [] |
| 951 | for i in range(len(self.cells) - 1): |
| 952 | if (i + 1) in self.residual_output_layers: |
| 953 | self.output_connected_layers.append(i) |
| 954 | self.output_indices.append(output_index_per_layer[i]) |
| 955 | else: |
| 956 | self.output_connected_layers = [] |
| 957 | self.output_indices = [] |
| 958 | self.output_connected_layers.append(len(self.cells) - 1) |
| 959 | self.output_indices.append(output_index_per_layer[-1]) |
| 960 | |
| 961 | self.state_names = [] |
| 962 | for i, cell in enumerate(self.cells): |
| 963 | self.state_names.extend( |
no outgoing calls
no test coverage detected
searching dependent graphs…