class_docstr: Basic tests on the util functions in TorchAgent.
class_docstr_tok: ["Basic","tests","on","the","util","functions","in","TorchAgent","."]
docstr: Test _vectorize_text and its different options.
docstr_tok: ["Test","_vectorize_text","and","its","different","options","."]
code: def test__vectorize_text(self):
      """
      Test _vectorize_text and its different options.
      """
      agent = get_agent()
      text = "I'm sorry, Dave"
  
      # test add_start and add_end
      vec = agent._vectorize_text(text, add_start=False, add_end=False)
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [1, 2, 3])
      vec = agent._vectorize_text(text, add_start=True, add_end=False)
      self.assertEqual(len(vec), 4)
      self.assertEqual(vec.tolist(), [MockDict.BEG_IDX, 1, 2, 3])
      vec = agent._vectorize_text(text, add_start=False, add_end=True)
      self.assertEqual(len(vec), 4)
      self.assertEqual(vec.tolist(), [1, 2, 3, MockDict.END_IDX])
      vec = agent._vectorize_text(text, add_start=True, add_end=True)
      self.assertEqual(len(vec), 5)
      self.assertEqual(
          vec.tolist(), [MockDict.BEG_IDX, 1, 2, 3, MockDict.END_IDX]
      )
  
      # now do it again with truncation=3
      vec = agent._vectorize_text(
          text, add_start=False, add_end=False, truncate=3
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [1, 2, 3])
      vec = agent._vectorize_text(
          text, add_start=True, add_end=False, truncate=3
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [1, 2, 3])
      vec = agent._vectorize_text(
          text, add_start=False, add_end=True, truncate=3
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [2, 3, MockDict.END_IDX])
      vec = agent._vectorize_text(
          text, add_start=True, add_end=True, truncate=3
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [2, 3, MockDict.END_IDX])
  
      # now do it again with truncation=2
      vec = agent._vectorize_text(
          text, add_start=False, add_end=False, truncate=2
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [2, 3])
      vec = agent._vectorize_text(
          text, add_start=True, add_end=False, truncate=2
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [2, 3])
      vec = agent._vectorize_text(
          text, add_start=False, add_end=True, truncate=2
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [3, MockDict.END_IDX])
      vec = agent._vectorize_text(
          text, add_start=True, add_end=True, truncate=2
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [3, MockDict.END_IDX])
  
      # now do it again with truncation=2, don't truncate_left
      vec = agent._vectorize_text(
          text,
          add_start=False,
          add_end=False,
          truncate=2,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [1, 2])
      vec = agent._vectorize_text(
          text,
          add_start=True,
          add_end=False,
          truncate=2,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [MockDict.BEG_IDX, 1])
      vec = agent._vectorize_text(
          text,
          add_start=False,
          add_end=True,
          truncate=2,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [1, 2])
      vec = agent._vectorize_text(
          text,
          add_start=True,
          add_end=True,
          truncate=2,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 2)
      self.assertEqual(vec.tolist(), [MockDict.BEG_IDX, 1])
  
      # now do it again with truncation=3, don't truncate_left
      vec = agent._vectorize_text(
          text,
          add_start=False,
          add_end=False,
          truncate=3,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [1, 2, 3])
      vec = agent._vectorize_text(
          text,
          add_start=True,
          add_end=False,
          truncate=3,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [MockDict.BEG_IDX, 1, 2])
      vec = agent._vectorize_text(
          text,
          add_start=False,
          add_end=True,
          truncate=3,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [1, 2, 3])
      vec = agent._vectorize_text(
          text,
          add_start=True,
          add_end=True,
          truncate=3,
          truncate_left=False,
      )
      self.assertEqual(len(vec), 3)
      self.assertEqual(vec.tolist(), [MockDict.BEG_IDX, 1, 2])
  
imports: import os
  import unittest
  from parlai.core.agents import create_agent_from_shared
  from parlai.utils.testing import tempdir
  from parlai.utils.misc import Message
label_desc: Use image node_id 3 for calling the TestTorchAgent obj's underlying member method code with example usage: obj.test__vectorize_text() without return types