code: def test_lstm_over_lstm_thought_vectors_2(device_id):
      dev = cntk_device(device_id)
      input_vocab_size = 3
      emb_dim = 2
      hidden_dim = 2
      num_labels = 2
      utterances_input = C.sequence.input_variable(
          (input_vocab_size), is_sparse=True, name="utterances"
      )
      conversation_lengths_input = C.input_variable(
          (), name="conversation_sequence_lengths"
      )
      label_input = C.sequence.input_variable(
          num_labels,
          is_sparse=True,
          sequence_axis=C.Axis("label_sequence"),
          name="labels",
      )
      with C.default_options(initial_state=0.1):
          model = C.layers.Embedding(emb_dim, name="embed")(
              utterances_input
          )
          model = C.layers.Recurrence(
              C.layers.LSTM(hidden_dim), go_backwards=False
          )(model)
          model = C.sequence.last(model)
          model = C.user_function(
              UtteranceBatchReshape(model, conversation_lengths_input)
          )
          model = C.to_sequence_like(model, label_input)
          model = C.layers.Recurrence(
              C.layers.LSTM(hidden_dim), go_backwards=False
          )(model)
          model = C.layers.Dense(num_labels, name="classify")(model)
  
      z = model
      ce = C.cross_entropy_with_softmax(z, label_input)
  
      sentinel_utt_data = C.NDArrayView.from_csr(
          _to_csr([[0, 0, 1]]), device=C.cpu()
      )
      c1_utt1_data = C.NDArrayView.from_csr(
          _to_csr([[0, 1, 1], [0, 1, 0], [1, 0, 0]]), device=C.cpu()
      )
      c1_utt2_data = C.NDArrayView.from_csr(
          _to_csr([[0, 1, 0], [0, 1, 1]]), device=C.cpu()
      )
      c1_utt3_data = C.NDArrayView.from_csr(
          _to_csr([[0, 1, 1], [0, 1, 0]]), device=C.cpu()
      )
      c2_utt1_data = C.NDArrayView.from_csr(
          _to_csr([[0, 1, 1]]), device=C.cpu()
      )
      c3_utt1_data = C.NDArrayView.from_csr(
          _to_csr([[0, 1, 0], [0, 1, 1], [1, 0, 0]]), device=C.cpu()
      )
      c3_utt2_data = C.NDArrayView.from_csr(
          _to_csr([[0, 1, 0]]), device=C.cpu()
      )
  
      all_utt_data = C.Value.create(
          C.sequence.input_variable((input_vocab_size), is_sparse=True),
          [
              c1_utt1_data,
              c1_utt2_data,
              c1_utt3_data,
              c2_utt1_data,
              sentinel_utt_data,
              sentinel_utt_data,
              c3_utt1_data,
              c3_utt2_data,
              sentinel_utt_data,
          ],
          device=C.cpu(),
      ).data
      conversation_lengths_data = np.asarray(
          [3, 1, 2], dtype=np.float32
      )
      seq1_label_data = [[0, 1], [0, 1], [1, 0]]
      seq2_label_data = [[1, 0]]
      seq3_label_data = [[1, 0], [0, 1]]
      label_data = [
          _to_csr(seq1_label_data),
          _to_csr(seq2_label_data),
          _to_csr(seq3_label_data),
      ]
      param_grads, loss_result = ce.grad(
          {
              utterances_input: all_utt_data,
              label_input: label_data,
              conversation_lengths_input: conversation_lengths_data,
          },
          wrt=ce.parameters,
          outputs=[ce],
          as_numpy=False,
      )
  
      loss_result = loss_result.as_sequences()
  
      absolute_tolerance = 0.01
      assert np.allclose(
          loss_result[0],
          [[0.678914], [0.668076], [0.728129]],
          atol=absolute_tolerance,
      )
      assert np.allclose(
          loss_result[1], [[0.679029]], atol=absolute_tolerance
      )
      assert np.allclose(
          loss_result[2],
          [[0.705393], [0.674243]],
          atol=absolute_tolerance,
      )
  
imports: from __future__ import division
  import numpy
  import pytest
  import cntk
  from .ops_test_utils import cntk_device
  from cntk.tests.test_utils import _to_dense, _to_csr
  from .ops_test_utils import unittest_helper, _test_unary_op, _test_binary_op, AA, precision, PRECISION_TO_TYPE, cntk_device
  from cntk import Value
  from cntk.axis import Axis
  from cntk.internal import sanitize_dtype_cntk
  from ..None import constant
label_desc: Use image node_id 2 for calling a global function with example usage: test_lstm_over_lstm_thought_vectors_2(device_id) without return types