code: def _extract_states(states, batch_sizes):
      h = []
      for i in range(states.shape[1]):
          h.append(states[int(batch_sizes[i] - 1), i])
      h = ivy.expand_dims(ivy.stack(h, axis=0), axis=0)
      return h
  
file_path: ivy/ivy/functional/frontends/torch/nn/functional/layer_functions.py
imports: import ivy
  from ivy.func_wrapper import with_supported_device_and_dtypes, with_supported_dtypes
  from ivy.functional.frontends.torch.func_wrapper import to_ivy_arrays_and_back
label_desc: Use image node_id 1 for calling a global function with example usage: _extract_states(states, batch_sizes) and returns: h