




"""simple docstring"""




import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad






class     __magic_name__							(       unittest.TestCase				):






				'''simple docstring'''





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					10





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					[1, 2, 3, 4]
							lowerCamelCase			      =					[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
							self.assertEqual(truncate_or_pad(_a		, self.block_size		, 0 )		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
							lowerCamelCase			      =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
							self.assertEqual(truncate_or_pad(_a		, self.block_size		, 0 )		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
							lowerCamelCase			      =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
							self.assertEqual(truncate_or_pad(_a		, self.block_size		, 0 )		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					"""It was the year of Our Lord one thousand seven hundred and
        seventy-five.\n\nSpiritual revelations were conceded to England at that
        favoured period, as at this."""
							lowerCamelCase      ,   lowerCamelCase			      =					process_story(_a )
							self.assertEqual(_a		, [] )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					""""""
							lowerCamelCase      ,   lowerCamelCase			      =					process_story(_a )
							self.assertEqual(_a		, [] )
							self.assertEqual(_a		, [] )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					(
							    """It was the year of Our Lord one thousand seven hundred and """
							    """seventy-five\n\nSpiritual revelations were conceded to England """
							    """at that favoured period, as at this.\n@highlight\n\nIt was the best of times"""
							)
							lowerCamelCase      ,   lowerCamelCase			      =					process_story(_a )

							lowerCamelCase			      =					[
							    """It was the year of Our Lord one thousand seven hundred and seventy-five.""",
							    """Spiritual revelations were conceded to England at that favoured period, as at this.""",
							]
							self.assertEqual(_a		, _a )

							lowerCamelCase			      =					["""It was the best of times."""]
							self.assertEqual(_a		, _a )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					torch.tensor([1, 2, 3, 4] )
							lowerCamelCase			      =					torch.tensor([1, 1, 1, 1] )
							np.testing.assert_array_equal(build_mask(_a		, 0 ).numpy()		, expected.numpy() )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					torch.tensor([1, 2, 3, 4, 23, 23, 23] )
							lowerCamelCase			      =					torch.tensor([1, 1, 1, 1, 0, 0, 0] )
							np.testing.assert_array_equal(build_mask(_a		, 23 ).numpy()		, expected.numpy() )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					torch.tensor([8, 2, 3, 4, 1, 1, 1] )
							lowerCamelCase			      =					torch.tensor([1, 1, 1, 1, 0, 0, 0] )
							np.testing.assert_array_equal(build_mask(_a		, 1 ).numpy()		, expected.numpy() )





				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					101
							lowerCamelCase			      =					torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]] )
							lowerCamelCase			      =					torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]] )

							lowerCamelCase			      =					compute_token_type_ids(_a		, _a )
							np.testing.assert_array_equal(_a		, _a )









"""simple docstring"""




import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
					import torch






@is_pipeline_test
class     __magic_name__							(       unittest.TestCase				):






				'''simple docstring'''
				__UpperCamelCase			  =						MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
				__UpperCamelCase			  =						TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING





				def    _lowerCAmelCase				(       self		, _a		, _a		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					TextaTextGenerationPipeline(model=_a		, tokenizer=_a )
							return generator, ["Something to write", "Something else"]





				def    _lowerCAmelCase				(       self		, _a		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					generator("""Something there""" )
							self.assertEqual(_a		, [{"""generated_text""": ANY(_a )}] )
							# These are encoder decoder, they don't just append to incoming string
							self.assertFalse(outputs[0]["""generated_text"""].startswith("""Something there""" ) )

							lowerCamelCase			      =					generator(["""This is great !""", """Something else"""]		, num_return_sequences=2		, do_sample=_a )
							self.assertEqual(
							    _a		, [
							        [{"""generated_text""": ANY(_a )}, {"""generated_text""": ANY(_a )}],
							        [{"""generated_text""": ANY(_a )}, {"""generated_text""": ANY(_a )}],
							    ]		, )

							lowerCamelCase			      =					generator(
							    ["""This is great !""", """Something else"""]		, num_return_sequences=2		, batch_size=2		, do_sample=_a )
							self.assertEqual(
							    _a		, [
							        [{"""generated_text""": ANY(_a )}, {"""generated_text""": ANY(_a )}],
							        [{"""generated_text""": ANY(_a )}, {"""generated_text""": ANY(_a )}],
							    ]		, )

							with self.assertRaises(_a ):
										generator(4 )





				@require_torch
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					pipeline("""text2text-generation"""		, model="""patrickvonplaten/t5-tiny-random"""		, framework="""pt""" )
							# do_sample=False necessary for reproducibility
							lowerCamelCase			      =					generator("""Something there"""		, do_sample=_a )
							self.assertEqual(_a		, [{"""generated_text""": """"""}] )

							lowerCamelCase			      =					3
							lowerCamelCase			      =					generator(
							    """Something there"""		, num_return_sequences=_a		, num_beams=_a		, )
							lowerCamelCase			      =					[
							    {"""generated_text""": """Beide Beide Beide Beide Beide Beide Beide Beide Beide"""},
							    {"""generated_text""": """Beide Beide Beide Beide Beide Beide Beide Beide"""},
							    {"""generated_text""": """"""},
							]
							self.assertEqual(_a		, _a )

							lowerCamelCase			      =					generator("""This is a test"""		, do_sample=_a		, num_return_sequences=2		, return_tensors=_a )
							self.assertEqual(
							    _a		, [
							        {"""generated_token_ids""": ANY(torch.Tensor )},
							        {"""generated_token_ids""": ANY(torch.Tensor )},
							    ]		, )
							lowerCamelCase			      =					generator.model.config.eos_token_id
							lowerCamelCase			      =					"""<pad>"""
							lowerCamelCase			      =					generator(
							    ["""This is a test""", """This is a second test"""]		, do_sample=_a		, num_return_sequences=2		, batch_size=2		, return_tensors=_a		, )
							self.assertEqual(
							    _a		, [
							        [
							            {"""generated_token_ids""": ANY(torch.Tensor )},
							            {"""generated_token_ids""": ANY(torch.Tensor )},
							        ],
							        [
							            {"""generated_token_ids""": ANY(torch.Tensor )},
							            {"""generated_token_ids""": ANY(torch.Tensor )},
							        ],
							    ]		, )





				@require_tf
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					pipeline("""text2text-generation"""		, model="""patrickvonplaten/t5-tiny-random"""		, framework="""tf""" )
							# do_sample=False necessary for reproducibility
							lowerCamelCase			      =					generator("""Something there"""		, do_sample=_a )
							self.assertEqual(_a		, [{"""generated_text""": """"""}] )



