original_docstring:  Collect tensor parts associated to active instances. 
docstring: Collect tensor parts associated to active instances.
docstring_tokens: Collect tensor parts associated to active instances .
code: def collect_active_part(beamed_tensor, curr_active_inst_idx, n_prev_active_inst, n_bm, layer=False):
              ''' Collect tensor parts associated to active instances. '''
              tmp_beamed_tensor = beamed_tensor[0] if layer else beamed_tensor
              _, *d_hs = tmp_beamed_tensor.size()
  
              n_curr_active_inst = len(curr_active_inst_idx)
              new_shape = (n_curr_active_inst * n_bm, *d_hs)
  
              beamed_tensor = beamed_tensor if layer else [beamed_tensor]
  
              beamed_tensor = [layer_b_tensor.view(n_prev_active_inst, -1) for layer_b_tensor in beamed_tensor]
              beamed_tensor = [layer_b_tensor.index_select(0, curr_active_inst_idx) for layer_b_tensor in beamed_tensor]
              beamed_tensor = [layer_b_tensor.view(*new_shape) for layer_b_tensor in beamed_tensor]
              
              beamed_tensor = beamed_tensor if layer else beamed_tensor[0]
              
              return beamed_tensor
code_tokens: def collect_active_part ( beamed_tensor , curr_active_inst_idx , n_prev_active_inst , n_bm , layer = False ) : tmp_beamed_tensor = beamed_tensor [ 0 ] if layer else beamed_tensor _ , * d_hs = tmp_beamed_tensor . size ( ) n_curr_active_inst = len ( curr_active_inst_idx ) new_shape = ( n_curr_active_inst * n_bm , * d_hs ) beamed_tensor = beamed_tensor if layer else [ beamed_tensor ] beamed_tensor = [ layer_b_tensor . view ( n_prev_active_inst , - 1 ) for layer_b_tensor in beamed_tensor ] beamed_tensor = [ layer_b_tensor . index_select ( 0 , curr_active_inst_idx ) for layer_b_tensor in beamed_tensor ] beamed_tensor = [ layer_b_tensor . view ( * new_shape ) for layer_b_tensor in beamed_tensor ] beamed_tensor = beamed_tensor if layer else beamed_tensor [ 0 ] return beamed_tensor
short_docstring: Collect tensor parts associated to active instances.
short_docstring_tokens: Collect tensor parts associated to active instances .
comment: ''' Collect tensor parts associated to active instances. '''