original_docstring: 
          Forward propagation with dynamic routing as proposed in the original 2017 paper.
          
docstring: Forward propagation with dynamic routing as proposed in the original 2017 paper.
docstring_tokens: Forward propagation with dynamic routing as proposed in the original 2017 paper .
code: def forward(self, x):
          '''
          Forward propagation with dynamic routing as proposed in the original 2017 paper.
          '''
  
          x = x.unsqueeze(dim=2).unsqueeze(dim=4)
  
          u_hat = torch.matmul(self.W, x).squeeze()
  
          u_hat_detached = u_hat.detach()
  
          b_ij = x.new_zeros(size=(x.size()[0], self.input_capsules, self.output_capsules, 1), requires_grad=False).to(self.device)
  
          #Dynamic routing
          for iter_idx in range(self.routing_iter):
  
              c_ij = func.softmax(b_ij, dim=2)
  
              if iter_idx == self.routing_iter - 1:
                  s_j = (c_ij * u_hat).sum(dim=1, keepdim=True) + self.b #multiply with the original u_hat since we want the gradient flow.
                  v_j = squash(s_j, dim=-1)
  
              else:
                  s_j = (c_ij*u_hat_detached).sum(dim=1, keepdim=True) #no gradient flow.
                  v_j = squash(s_j, dim=-1)
                  a_ij = (u_hat_detached * v_j).sum(dim=-1, keepdim=True) #agreement check
                  b_ij = b_ij + a_ij #update the coefficients
  
          return v_j.squeeze()
code_tokens: def forward ( self , x ) : x = x . unsqueeze ( dim = 2 ) . unsqueeze ( dim = 4 ) u_hat = torch . matmul ( self . W , x ) . squeeze ( ) u_hat_detached = u_hat . detach ( ) b_ij = x . new_zeros ( size = ( x . size ( ) [ 0 ] , self . input_capsules , self . output_capsules , 1 ) , requires_grad = False ) . to ( self . device ) for iter_idx in range ( self . routing_iter ) : c_ij = func . softmax ( b_ij , dim = 2 ) if iter_idx == self . routing_iter - 1 : s_j = ( c_ij * u_hat ) . sum ( dim = 1 , keepdim = True ) + self . b v_j = squash ( s_j , dim = - 1 ) else : s_j = ( c_ij * u_hat_detached ) . sum ( dim = 1 , keepdim = True ) v_j = squash ( s_j , dim = - 1 ) a_ij = ( u_hat_detached * v_j ) . sum ( dim = - 1 , keepdim = True ) b_ij = b_ij + a_ij return v_j . squeeze ( )
short_docstring: Forward propagation with dynamic routing as proposed in the original 2017 paper.
short_docstring_tokens: Forward propagation with dynamic routing as proposed in the original 2017 paper .
comment: '''
          Forward propagation with dynamic routing as proposed in the original 2017 paper.
          '''$SEP$#Dynamic routing$SEP$#multiply with the original u_hat since we want the gradient flow.$SEP$#no gradient flow.$SEP$#agreement check$SEP$#update the coefficients