class_docstr: Test case for SentencePieceProcessor
class_docstr_tok: ["Test","case","for","SentencePieceProcessor"]
code: def test_nbest(self):
      sp = self.sp_
      text = "hello world"
      text2 = "I have a pen."
  
      for out_type in [str, int, "serialized_proto", "immutable_proto"]:
          results = sp.nbest_encode(
              text, nbest_size=10, out_type=out_type
          )
          self.assertEqual(
              results,
              sp.NBestEncode(text, nbest_size=10, out_type=out_type),
          )
  
          if out_type in [str, int]:
              for n in results:
                  self.assertEqual(sp.decode(n), text)
  
              for n in sp.decode(results):
                  self.assertEqual(n, text)
  
          # batch test
          results = sp.nbest_encode(
              [text, text2], nbest_size=10, out_type=out_type
          )
          self.assertEqual(
              results,
              sp.NBestEncode(
                  [text, text2], nbest_size=10, out_type=out_type
              ),
          )
          self.assertEqual(len(results), 2)
  
          if out_type in [str, int]:
              for n in results[0]:
                  self.assertEqual(sp.decode(n), text)
  
              for n in results[1]:
                  self.assertEqual(sp.decode(n), text2)
  
              decoded = sp.decode(results[0])
              self.assertEqual(len(decoded), 10)
              for n in decoded:
                  self.assertEqual(n, text)
              decoded = sp.decode(results[1])
              self.assertEqual(len(decoded), 10)
              for n in decoded:
                  self.assertEqual(n, text2)
  
      self.assertEqual(
          sp.nbest_encode(text, nbest_size=10, out_type=str),
          sp.nbest_encode_as_pieces(text, nbest_size=10),
      )
      self.assertEqual(
          sp.nbest_encode(text, nbest_size=10, out_type=int),
          sp.nbest_encode_as_ids(text, nbest_size=10),
      )
      self.assertEqual(
          sp.nbest_encode(
              text, nbest_size=10, out_type="serialized_proto"
          ),
          sp.nbest_encode_as_serialized_proto(text, nbest_size=10),
      )
      self.assertEqual(
          sp.nbest_encode(
              text, nbest_size=10, out_type="immutable_proto"
          ),
          sp.nbest_encode_as_immutable_proto(text, nbest_size=10),
      )
  
imports: from collections import defaultdict
  import io
  import os
  import pickle
  import sys
  import unittest
  import sentencepiece
label_desc: Use image node_id 14 for calling the TestSentencepieceProcessor obj's underlying member method code with example usage: obj.test_nbest() without return types