Beispiel #1
0
 def test_vocab_transform(self):
     asset_name = 'vocab_test2.txt'
     asset_path = get_asset_path(asset_name)
     f = open(asset_path, 'r')
     vocab_transform = VocabTransform(vocab_from_file(f))
     self.assertEqual(vocab_transform(['of', 'that', 'new']), [7, 18, 24])
     jit_vocab_transform = torch.jit.script(vocab_transform.to_ivalue())
     self.assertEqual(jit_vocab_transform(['of', 'that', 'new']), [7, 18, 24])
Beispiel #2
0
 def test_vocab_transform(self):
     asset_name = 'vocab_test2.txt'
     asset_path = get_asset_path(asset_name)
     with open(asset_path, 'r') as f:
         vocab_transform = VocabTransform(vocab_from_file(f))
         self.assertEqual(
             vocab_transform([['of', 'that', 'new'],
                              ['of', 'that', 'new', 'that']]),
             [[21, 26, 20], [21, 26, 20, 26]])
         jit_vocab_transform = torch.jit.script(vocab_transform.to_ivalue())
         self.assertEqual(
             jit_vocab_transform([['of', 'that', 'new'],
                                  ['of', 'that', 'new', 'that']]),
             [[21, 26, 20], [21, 26, 20, 26]])