


'''simple docstring'''






import json
import os
import unittest

from transformers.models.xlm.tokenization_xlm import VOCAB_FILES_NAMES, XLMTokenizer
from transformers.testing_utils import slow

from ...test_tokenization_common import TokenizerTesterMixin




class 						a__							(				a__							,							unittest.TestCase    ):





							'''simple docstring'''






							lowercase__     :  List[str]      		= XLMTokenizer
							lowercase__     :  Optional[int]      		= False







							def     __SCREAMING_SNAKE_CASE				(						self  )			->				List[Any]:
														super().setUp()

														# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
														lowerCAmelCase__			  =      [
														    '''l''',
														    '''o''',
														    '''w''',
														    '''e''',
														    '''r''',
														    '''s''',
														    '''t''',
														    '''i''',
														    '''d''',
														    '''n''',
														    '''w</w>''',
														    '''r</w>''',
														    '''t</w>''',
														    '''lo''',
														    '''low''',
														    '''er</w>''',
														    '''low</w>''',
														    '''lowest</w>''',
														    '''newer</w>''',
														    '''wider</w>''',
														    '''<unk>''',
														]
														lowerCAmelCase__			  =      dict(zip(lowerCamelCase_   ,       range(len(lowerCamelCase_  )  )  )  )
														lowerCAmelCase__			  =      ['''l o 123''', '''lo w 1456''', '''e r</w> 1789''', '''''']

														lowerCAmelCase__			  =      os.path.join(self.tmpdirname   ,       VOCAB_FILES_NAMES['''vocab_file''']  )
														lowerCAmelCase__			  =      os.path.join(self.tmpdirname   ,       VOCAB_FILES_NAMES['''merges_file''']  )
														with open(self.vocab_file   ,       '''w'''  ) as fp:
																					fp.write(json.dumps(lowerCamelCase_  )  )
														with open(self.merges_file   ,       '''w'''  ) as fp:
																					fp.write('''\n'''.join(lowerCamelCase_  )  )







							def     __SCREAMING_SNAKE_CASE				(						self   ,       lowerCamelCase_  )			->				Optional[Any]:
														lowerCAmelCase__			  =      '''lower newer'''
														lowerCAmelCase__			  =      '''lower newer'''
														return input_text, output_text







							def     __SCREAMING_SNAKE_CASE				(						self  )			->				List[Any]:
														lowerCAmelCase__			  =      XLMTokenizer(self.vocab_file   ,       self.merges_file  )

														lowerCAmelCase__			  =      '''lower'''
														lowerCAmelCase__			  =      ['''low''', '''er</w>''']
														lowerCAmelCase__			  =      tokenizer.tokenize(lowerCamelCase_  )
														self.assertListEqual(lowerCamelCase_   ,       lowerCamelCase_  )

														lowerCAmelCase__			  =      tokens + ['''<unk>''']
														lowerCAmelCase__			  =      [14, 15, 20]
														self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase_  )   ,       lowerCamelCase_  )







							@slow
							def     __SCREAMING_SNAKE_CASE				(						self  )			->				Optional[Any]:
														lowerCAmelCase__			  =      XLMTokenizer.from_pretrained('''xlm-mlm-en-2048'''  )

														lowerCAmelCase__			  =      tokenizer.encode('''sequence builders'''   ,       add_special_tokens=lowerCamelCase_  )
														lowerCAmelCase__			  =      tokenizer.encode('''multi-sequence build'''   ,       add_special_tokens=lowerCamelCase_  )

														lowerCAmelCase__			  =      tokenizer.build_inputs_with_special_tokens(lowerCamelCase_  )
														lowerCAmelCase__			  =      tokenizer.build_inputs_with_special_tokens(lowerCamelCase_   ,       lowerCamelCase_  )

														assert encoded_sentence == [0] + text + [1]
														assert encoded_pair == [0] + text + [1] + text_a + [1]



"""simple docstring"""
import numpy as np

def 				_snake_case      (   __snake_case							:      np.ndarray   ):




   """simple docstring"""







   return 1 / (1 + np.exp(-vector   ))

def 				_snake_case      (   __snake_case							:      np.ndarray   ):




   """simple docstring"""







   return vector * sigmoid(__snake_case   )


if __name__ == "__main__":
 import doctest

 doctest.testmod()

