code: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  from __future__ import annotations
  
  import unittest
  
  from transformers import OpenAIGPTConfig, is_tf_available
  from transformers.testing_utils import require_tf, slow
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_tf_available():
  	import tensorflow as tf
  
  	from transformers.models.openai.modeling_tf_openai import (
  	    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
  	    TFOpenAIGPTDoubleHeadsModel,
  	    TFOpenAIGPTForSequenceClassification,
  	    TFOpenAIGPTLMHeadModel,
  	    TFOpenAIGPTModel,
  	)
  
  
  
  
  
  class 					_UpperCAmelCase							:
  		def __init__(						self,__SCREAMING_SNAKE_CASE,):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       parent
  					__lowerCAmelCase      		=       13
  					__lowerCAmelCase      		=       7
  					__lowerCAmelCase      		=       True
  					__lowerCAmelCase      		=       True
  					__lowerCAmelCase      		=       True
  					__lowerCAmelCase      		=       True
  					__lowerCAmelCase      		=       True
  					__lowerCAmelCase      		=       99
  					__lowerCAmelCase      		=       32
  					__lowerCAmelCase      		=       2
  					__lowerCAmelCase      		=       4
  					__lowerCAmelCase      		=       37
  					__lowerCAmelCase      		=       """gelu"""
  					__lowerCAmelCase      		=       0.1
  					__lowerCAmelCase      		=       0.1
  					__lowerCAmelCase      		=       5_12
  					__lowerCAmelCase      		=       16
  					__lowerCAmelCase      		=       2
  					__lowerCAmelCase      		=       0.02
  					__lowerCAmelCase      		=       3
  					__lowerCAmelCase      		=       4
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       self.vocab_size - 1
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       ids_tensor([self.batch_size, self.seq_length],self.vocab_size    )
  
  					__lowerCAmelCase      		=       None
  					if self.use_input_mask:
  								__lowerCAmelCase      		=       random_attention_mask([self.batch_size, self.seq_length]    )
  
  					__lowerCAmelCase      		=       None
  					if self.use_token_type_ids:
  								__lowerCAmelCase      		=       ids_tensor([self.batch_size, self.seq_length],self.type_vocab_size    )
  
  					__lowerCAmelCase      		=       None
  					if self.use_mc_token_ids:
  								__lowerCAmelCase      		=       ids_tensor([self.batch_size, self.num_choices],self.seq_length    )
  
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       None
  					__lowerCAmelCase      		=       None
  					if self.use_labels:
  								__lowerCAmelCase      		=       ids_tensor([self.batch_size],self.type_sequence_label_size    )
  								__lowerCAmelCase      		=       ids_tensor([self.batch_size, self.seq_length],self.num_labels    )
  								__lowerCAmelCase      		=       ids_tensor([self.batch_size],self.num_choices    )
  
  					__lowerCAmelCase      		=       OpenAIGPTConfig(
  					    vocab_size=self.vocab_size,n_embd=self.hidden_size,n_layer=self.num_hidden_layers,n_head=self.num_attention_heads,n_positions=self.max_position_embeddings,pad_token_id=self.pad_token_id,)
  
  					__lowerCAmelCase      		=       ids_tensor([self.num_hidden_layers, self.num_attention_heads],2    )
  
  					return (
  					    config,
  					    input_ids,
  					    input_mask,
  					    head_mask,
  					    token_type_ids,
  					    mc_token_ids,
  					    sequence_labels,
  					    token_labels,
  					    choice_labels,
  					)
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,*__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       TFOpenAIGPTModel(config=__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
  					__lowerCAmelCase      		=       model(__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       [input_ids, input_mask]
  					__lowerCAmelCase      		=       model(__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       model(__SCREAMING_SNAKE_CASE    )
  
  					self.parent.assertEqual(result.last_hidden_state.shape,(self.batch_size, self.seq_length, self.hidden_size)    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,*__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       TFOpenAIGPTLMHeadModel(config=__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
  					__lowerCAmelCase      		=       model(__SCREAMING_SNAKE_CASE    )
  					self.parent.assertEqual(result.logits.shape,(self.batch_size, self.seq_length, self.vocab_size)    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,*__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       TFOpenAIGPTDoubleHeadsModel(config=__SCREAMING_SNAKE_CASE    )
  
  					__lowerCAmelCase      		=       tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE,1    ),(1, self.num_choices, 1)    )
  					__lowerCAmelCase      		=       tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE,1    ),(1, self.num_choices, 1)    )
  					__lowerCAmelCase      		=       tf.tile(tf.expand_dims(__SCREAMING_SNAKE_CASE,1    ),(1, self.num_choices, 1)    )
  
  					__lowerCAmelCase      		=       {
  					    """input_ids""": multiple_choice_inputs_ids,
  					    """mc_token_ids""": mc_token_ids,
  					    """attention_mask""": multiple_choice_input_mask,
  					    """token_type_ids""": multiple_choice_token_type_ids,
  					}
  					__lowerCAmelCase      		=       model(__SCREAMING_SNAKE_CASE    )
  					self.parent.assertEqual(
  					    result.logits.shape,(self.batch_size, self.num_choices, self.seq_length, self.vocab_size)    )
  					self.parent.assertEqual(result.mc_logits.shape,(self.batch_size, self.num_choices)    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,*__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.num_labels
  					__lowerCAmelCase      		=       ids_tensor([self.batch_size],self.type_sequence_label_size    )
  					__lowerCAmelCase      		=       {
  					    """input_ids""": input_ids,
  					    """attention_mask""": input_mask,
  					    """token_type_ids""": token_type_ids,
  					    """labels""": sequence_labels,
  					}
  					__lowerCAmelCase      		=       TFOpenAIGPTForSequenceClassification(__SCREAMING_SNAKE_CASE    )
  					__lowerCAmelCase      		=       model(__SCREAMING_SNAKE_CASE    )
  					self.parent.assertEqual(result.logits.shape,(self.batch_size, self.num_labels)    )
  
  
  
  
  
  
  
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.prepare_config_and_inputs()
  
  					(
  					    (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, (
  					    __lowerCAmelCase
  					)		, 
  					)      		=       config_and_inputs
  
  					__lowerCAmelCase      		=       {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
  					return config, inputs_dict
  
  
  
  
  
  @require_tf
  class 					_UpperCAmelCase							(		lowerCAmelCase_			,      lowerCAmelCase_			,      unittest.TestCase     ):
  		a     :     Tuple     						=(
  		    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
  		    if is_tf_available()
  		    else ()
  		)
  		a     :     int     						=(
  		    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
  		)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
  		a     :     int     						=(
  		    {
  		        """feature-extraction""": TFOpenAIGPTModel,
  		        """text-classification""": TFOpenAIGPTForSequenceClassification,
  		        """text-generation""": TFOpenAIGPTLMHeadModel,
  		        """zero-shot""": TFOpenAIGPTForSequenceClassification,
  		    }
  		    if is_tf_available()
  		    else {}
  		)
  		a     :     List[str]     						=False
  		a     :     int     						=False
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
  								# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
  								# `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
  								# tiny config could not be created.
  								return True
  
  					return False
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       TFOpenAIGPTModelTester(self    )
  					__lowerCAmelCase      		=       ConfigTester(self,config_class=__SCREAMING_SNAKE_CASE,n_embd=37    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					self.config_tester.run_common_tests()
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_openai_gpt_model(*__SCREAMING_SNAKE_CASE    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_openai_gpt_lm_head(*__SCREAMING_SNAKE_CASE    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_openai_gpt_double_head(*__SCREAMING_SNAKE_CASE    )
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       self.model_tester.prepare_config_and_inputs()
  					self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*__SCREAMING_SNAKE_CASE    )
  
  
  
  
  
  
  
  		@slow
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  								__lowerCAmelCase      		=       TFOpenAIGPTModel.from_pretrained(__SCREAMING_SNAKE_CASE    )
  								self.assertIsNotNone(__SCREAMING_SNAKE_CASE    )
  
  
  
  
  
  @require_tf
  class 					_UpperCAmelCase							(		unittest.TestCase     ):
  		@slow
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       TFOpenAIGPTLMHeadModel.from_pretrained("""openai-gpt"""    )
  					__lowerCAmelCase      		=       tf.convert_to_tensor([[4_81, 47_35, 5_44]],dtype=tf.intaa    )  # the president is
  					__lowerCAmelCase      		=       [
  					    4_81,
  					    47_35,
  					    5_44,
  					    2_46,
  					    9_63,
  					    8_70,
  					    7_62,
  					    2_39,
  					    2_44,
  					    4_04_77,
  					    2_44,
  					    2_49,
  					    7_19,
  					    8_81,
  					    4_87,
  					    5_44,
  					    2_40,
  					    2_44,
  					    6_03,
  					    4_81,
  					]  # the president is a very good man. " \n " i\'m sure he is, " said the
  
  					__lowerCAmelCase      		=       model.generate(__SCREAMING_SNAKE_CASE,do_sample=__SCREAMING_SNAKE_CASE    )
  					self.assertListEqual(output_ids[0].numpy().tolist(),__SCREAMING_SNAKE_CASE    )
  
  
style_context: 
  
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  import itertools
  from dataclasses import dataclass
  from io import StringIO
  from typing import Optional
  
  import pyarrow as pa
  
  import datasets
  from datasets.features.features import require_storage_cast
  from datasets.table import table_cast
  
  
  _a      :				Tuple											=					datasets.utils.logging.get_logger(__name__)
  
  
  
  
  
  @dataclass
  class 					_UpperCAmelCase							(		datasets.BuilderConfig     ):
  		a     :     Optional[datasets.Features]     						=None
  		a     :     str     						="utf-8"
  		a     :     Optional[str]     						=None
  		a     :     int     						=10 << 20  # 10MB
  		a     :     bool     						=False
  		a     :     str     						="line"
  
  
  
  
  
  class 					_UpperCAmelCase							(		datasets.ArrowBasedBuilder     ):
  		a     :     Optional[int]     						=TextConfig
  		def 						lowerCamelCase__    (						self    ):
  
  
  
  					'''simple docstring'''
  
  					return datasets.DatasetInfo(features=self.config.features    )
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					if not self.config.data_files:
  								raise ValueError(f'At least one data file must be specified, but got data_files={self.config.data_files}'    )
  					__lowerCAmelCase      		=       dl_manager.download_and_extract(self.config.data_files    )
  					if isinstance(__SCREAMING_SNAKE_CASE,(str, list, tuple)    ):
  								__lowerCAmelCase      		=       data_files
  								if isinstance(__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    ):
  											__lowerCAmelCase      		=       [files]
  								__lowerCAmelCase      		=       [dl_manager.iter_files(__SCREAMING_SNAKE_CASE    ) for file in files]
  								return [datasets.SplitGenerator(name=datasets.Split.TRAIN,gen_kwargs={"""files""": files}    )]
  					__lowerCAmelCase      		=       []
  					for split_name, files in data_files.items():
  								if isinstance(__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    ):
  											__lowerCAmelCase      		=       [files]
  								__lowerCAmelCase      		=       [dl_manager.iter_files(__SCREAMING_SNAKE_CASE    ) for file in files]
  								splits.append(datasets.SplitGenerator(name=__SCREAMING_SNAKE_CASE,gen_kwargs={"""files""": files}    )    )
  					return splits
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					if self.config.features is not None:
  								__lowerCAmelCase      		=       self.config.features.arrow_schema
  								if all(not require_storage_cast(__SCREAMING_SNAKE_CASE    ) for feature in self.config.features.values()    ):
  											# cheaper cast
  											__lowerCAmelCase      		=       pa_table.cast(__SCREAMING_SNAKE_CASE    )
  								else:
  											# more expensive cast; allows str <-> int/float or str to Audio for example
  											__lowerCAmelCase      		=       table_cast(__SCREAMING_SNAKE_CASE,__SCREAMING_SNAKE_CASE    )
  								return pa_table
  					else:
  								return pa_table.cast(pa.schema({"""text""": pa.string()}    )    )
  
  
  
  
  
  
  
  		def 						lowerCamelCase__    (						self,__SCREAMING_SNAKE_CASE    ):
  
  
  
  					'''simple docstring'''
  
  					__lowerCAmelCase      		=       list(self.config.features    ) if self.config.features is not None else ["""text"""]
  					for file_idx, file in enumerate(itertools.chain.from_iterable(__SCREAMING_SNAKE_CASE    )    ):
  								# open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
  								with open(__SCREAMING_SNAKE_CASE,encoding=self.config.encoding,errors=self.config.errors    ) as f:
  											if self.config.sample_by == "line":
  														__lowerCAmelCase      		=       0
  														while True:
  																	__lowerCAmelCase      		=       f.read(self.config.chunksize    )
  																	if not batch:
  																				break
  																	batch += f.readline()  # finish current line
  																	# StringIO.readlines, by default splits only on "\n" (and keeps line breaks)
  																	__lowerCAmelCase      		=       StringIO(__SCREAMING_SNAKE_CASE    ).readlines()
  																	if not self.config.keep_linebreaks:
  																				__lowerCAmelCase      		=       [line.rstrip("""\n"""    ) for line in batch]
  																	__lowerCAmelCase      		=       pa.Table.from_arrays([pa.array(__SCREAMING_SNAKE_CASE    )],names=__SCREAMING_SNAKE_CASE    )
  																	# Uncomment for debugging (will print the Arrow table size and elements)
  																	# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
  																	# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
  																	yield (file_idx, batch_idx), self._cast_table(__SCREAMING_SNAKE_CASE    )
  																	batch_idx += 1
  											elif self.config.sample_by == "paragraph":
  														__lowerCAmelCase      		=       0
  														__lowerCAmelCase      		=       """"""
  														while True:
  																	__lowerCAmelCase      		=       f.read(self.config.chunksize    )
  																	if not new_batch:
  																				break
  																	batch += new_batch
  																	batch += f.readline()  # finish current line
  																	__lowerCAmelCase      		=       batch.split("""\n\n"""    )
  																	__lowerCAmelCase      		=       pa.Table.from_arrays(
  																	    [pa.array([example for example in batch[:-1] if example]    )],names=__SCREAMING_SNAKE_CASE    )
  																	# Uncomment for debugging (will print the Arrow table size and elements)
  																	# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
  																	# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
  																	yield (file_idx, batch_idx), self._cast_table(__SCREAMING_SNAKE_CASE    )
  																	batch_idx += 1
  																	__lowerCAmelCase      		=       batch[-1]
  														if batch:
  																	__lowerCAmelCase      		=       pa.Table.from_arrays([pa.array([batch]    )],names=__SCREAMING_SNAKE_CASE    )
  																	yield (file_idx, batch_idx), self._cast_table(__SCREAMING_SNAKE_CASE    )
  											elif self.config.sample_by == "document":
  														__lowerCAmelCase      		=       f.read()
  														__lowerCAmelCase      		=       pa.Table.from_arrays([pa.array([text]    )],names=__SCREAMING_SNAKE_CASE    )
  														yield file_idx, self._cast_table(__SCREAMING_SNAKE_CASE    )
  
  