

import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin





class 					__lowerCAmelCase	(   SCREAMING_SNAKE_CASE     ,     unittest.TestCase				):
  _a		     =    ProphetNetTokenizer
  _a		     =    False




  def     A__	(							self   )    ->					Tuple:
        '''simple docstring'''






        super().setUp()

        _lowercase      			=[
            '[UNK]',
            '[CLS]',
            '[SEP]',
            '[PAD]',
            '[MASK]',
            'want',
            '##want',
            '##ed',
            'wa',
            'un',
            'runn',
            '##ing',
            ',',
            'low',
            'lowest',
        ]
        _lowercase      			=os.path.join(self.tmpdirname				,  VOCAB_FILES_NAMES['vocab_file']   )
        with open(self.vocab_file				,  'w'				,  encoding='utf-8'   ) as vocab_writer:
              vocab_writer.write(''.join([x + '\n' for x in vocab_tokens]   )   )




  def     A__	(							self				,  lowerCAmelCase   )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			='UNwant\u00E9d,running'
        _lowercase      			='unwanted, running'
        return input_text, output_text




  def     A__	(							self   )    ->					str:
        '''simple docstring'''






        _lowercase      			=self.tokenizer_class(self.vocab_file   )

        _lowercase      			=tokenizer.tokenize('UNwant\u00E9d,running'   )
        self.assertListEqual(lowerCAmelCase				,  ['un', '##want', '##ed', ',', 'runn', '##ing']   )
        self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase   )				,  [9, 6, 7, 12, 10, 11]   )




  def     A__	(							self   )    ->					Union[str, Any]:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer()

        self.assertListEqual(tokenizer.tokenize('ah\u535A\u63A8zz'   )				,  ['ah', '\u535A', '\u63A8', 'zz']   )




  def     A__	(							self   )    ->					Tuple:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '   )				,  ['hello', '!', 'how', 'are', 'you', '?']   )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )				,  ['hello']   )




  def     A__	(							self   )    ->					Optional[Any]:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase				,  strip_accents=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )				,  ['hällo', '!', 'how', 'are', 'you', '?']   )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )				,  ['h\u00E9llo']   )




  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase				,  strip_accents=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )				,  ['hallo', '!', 'how', 'are', 'you', '?']   )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )				,  ['hello']   )




  def     A__	(							self   )    ->					Any:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )				,  ['hallo', '!', 'how', 'are', 'you', '?']   )
        self.assertListEqual(tokenizer.tokenize('H\u00E9llo'   )				,  ['hello']   )




  def     A__	(							self   )    ->					str:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU?  '   )				,  ['HeLLo', '!', 'how', 'Are', 'yoU', '?']   )




  def     A__	(							self   )    ->					int:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase				,  strip_accents=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )				,  ['HäLLo', '!', 'how', 'Are', 'yoU', '?']   )




  def     A__	(							self   )    ->					Union[str, Any]:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase				,  strip_accents=lowerCAmelCase   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHäLLo!how  \n Are yoU?  '   )				,  ['HaLLo', '!', 'how', 'Are', 'yoU', '?']   )




  def     A__	(							self   )    ->					List[Any]:
        '''simple docstring'''






        _lowercase      			=BasicTokenizer(do_lower_case=lowerCAmelCase				,  never_split=['[UNK]']   )

        self.assertListEqual(
            tokenizer.tokenize(' \tHeLLo!how  \n Are yoU? [UNK]'   )				,  ['HeLLo', '!', 'how', 'Are', 'yoU', '?', '[UNK]']   )




  def     A__	(							self   )    ->					Optional[Any]:
        '''simple docstring'''






        _lowercase      			=['[UNK]', '[CLS]', '[SEP]', 'want', '##want', '##ed', 'wa', 'un', 'runn', '##ing']

        _lowercase      			={}
        for i, token in enumerate(lowerCAmelCase   ):
              _lowercase      			=i
        _lowercase      			=WordpieceTokenizer(vocab=lowerCAmelCase				,  unk_token='[UNK]'   )

        self.assertListEqual(tokenizer.tokenize(''   )				,  []   )

        self.assertListEqual(tokenizer.tokenize('unwanted running'   )				,  ['un', '##want', '##ed', 'runn', '##ing']   )

        self.assertListEqual(tokenizer.tokenize('unwantedX running'   )				,  ['[UNK]', 'runn', '##ing']   )




  @require_torch
  def     A__	(							self   )    ->					str:
        '''simple docstring'''






        _lowercase      			=self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'   )

        _lowercase      			=['A long paragraph for summarization.', 'Another paragraph for summarization.']
        _lowercase      			=[1_037, 2_146, 20_423, 2_005, 7_680, 7_849, 3_989, 1_012, 102]
        _lowercase      			=tokenizer(lowerCAmelCase				,  padding=lowerCAmelCase				,  return_tensors='pt'   )
        self.assertIsInstance(lowerCAmelCase				,  lowerCAmelCase   )
        _lowercase      			=list(batch.input_ids.numpy()[0]   )
        self.assertListEqual(lowerCAmelCase				,  lowerCAmelCase   )

        self.assertEqual((2, 9)				,  batch.input_ids.shape   )
        self.assertEqual((2, 9)				,  batch.attention_mask.shape   )




  def     A__	(							self   )    ->					Any:
        '''simple docstring'''






        self.assertTrue(_is_whitespace(' '   )   )
        self.assertTrue(_is_whitespace('\t'   )   )
        self.assertTrue(_is_whitespace('\r'   )   )
        self.assertTrue(_is_whitespace('\n'   )   )
        self.assertTrue(_is_whitespace('\u00A0'   )   )

        self.assertFalse(_is_whitespace('A'   )   )
        self.assertFalse(_is_whitespace('-'   )   )




  def     A__	(							self   )    ->					Optional[Any]:
        '''simple docstring'''






        self.assertTrue(_is_control('\u0005'   )   )

        self.assertFalse(_is_control('A'   )   )
        self.assertFalse(_is_control(' '   )   )
        self.assertFalse(_is_control('\t'   )   )
        self.assertFalse(_is_control('\r'   )   )




  def     A__	(							self   )    ->					Tuple:
        '''simple docstring'''






        self.assertTrue(_is_punctuation('-'   )   )
        self.assertTrue(_is_punctuation('$'   )   )
        self.assertTrue(_is_punctuation('`'   )   )
        self.assertTrue(_is_punctuation('.'   )   )

        self.assertFalse(_is_punctuation('A'   )   )
        self.assertFalse(_is_punctuation(' '   )   )




  @slow
  def     A__	(							self   )    ->					Optional[int]:
        '''simple docstring'''






        _lowercase      			=self.tokenizer_class.from_pretrained('microsoft/prophetnet-large-uncased'   )

        _lowercase      			=tokenizer.encode('sequence builders'				,  add_special_tokens=lowerCAmelCase   )
        _lowercase      			=tokenizer.encode('multi-sequence build'				,  add_special_tokens=lowerCAmelCase   )

        _lowercase      			=tokenizer.build_inputs_with_special_tokens(lowerCAmelCase   )
        _lowercase      			=tokenizer.build_inputs_with_special_tokens(lowerCAmelCase				,  lowerCAmelCase   )

        assert encoded_sentence == text + [102]
        assert encoded_pair == text + [102] + text_a + [102]





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowercase_   							=  '\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'





class 					__lowerCAmelCase	(   unittest.TestCase     ,     SCREAMING_SNAKE_CASE				):




  def     A__	(							self   )    ->					Union[str, Any]:
        '''simple docstring'''






        _lowercase      			=load_tool('text-question-answering'   )
        self.tool.setup()
        _lowercase      			=load_tool('text-question-answering'				,  remote=lowerCAmelCase   )




  def     A__	(							self   )    ->					Dict:
        '''simple docstring'''






        _lowercase      			=self.tool(lowerCAmelCase				,  'What did Hugging Face do in April 2021?'   )
        self.assertEqual(lowerCAmelCase				,  'launched the BigScience Research Workshop'   )




  def     A__	(							self   )    ->					Optional[Any]:
        '''simple docstring'''






        _lowercase      			=self.remote_tool(lowerCAmelCase				,  'What did Hugging Face do in April 2021?'   )
        self.assertEqual(lowerCAmelCase				,  'launched the BigScience Research Workshop'   )




  def     A__	(							self   )    ->					Any:
        '''simple docstring'''






        _lowercase      			=self.tool(text=lowerCAmelCase				,  question='What did Hugging Face do in April 2021?'   )
        self.assertEqual(lowerCAmelCase				,  'launched the BigScience Research Workshop'   )




  def     A__	(							self   )    ->					Optional[int]:
        '''simple docstring'''






        _lowercase      			=self.remote_tool(text=lowerCAmelCase				,  question='What did Hugging Face do in April 2021?'   )
        self.assertEqual(lowerCAmelCase				,  'launched the BigScience Research Workshop'   )


