





import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.bert.modeling_bert import (
    BERT_INPUTS_DOCSTRING,
    BERT_START_DOCSTRING,
    BertEmbeddings,
    BertLayer,
    BertPooler,
    BertPreTrainedModel,
)


def     SCREAMING_SNAKE_CASE			(      lowerCAmelCase					)     ->   int:
       _UpperCamelCase              =						torch.exp(lowerCAmelCase					)
       _UpperCamelCase              =						torch.sum(lowerCAmelCase    ,       dim=1					)  # sum of exp(x_i)
       _UpperCamelCase              =						torch.sum(x * exp_x    ,       dim=1					)  # sum of x_i * exp(x_i)
       return torch.log(lowerCAmelCase					) - B / A

class  __A(						nn.Module ):

     def __init__(      self,       A      ):





            """simple docstring"""

            super().__init__()
            _UpperCamelCase              =						config.output_attentions
            _UpperCamelCase              =						config.output_hidden_states
            _UpperCamelCase              =						nn.ModuleList([BertLayer(A      ) for _ in range(config.num_hidden_layers      )]      )
            _UpperCamelCase              =						nn.ModuleList([BertHighway(A      ) for _ in range(config.num_hidden_layers      )]      )

            _UpperCamelCase              =						[-1 for _ in range(config.num_hidden_layers      )]

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            if (type(A      ) is float) or (type(A      ) is int):
                   for i in range(len(self.early_exit_entropy      )      ):
                          _UpperCamelCase              =						x
            else:
                   _UpperCamelCase              =						x

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						pooler.state_dict()
            for highway in self.highway:
                   for name, param in highway.pooler.state_dict().items():
                          param.copy_(loaded_model[name]      )



     def 	_UpperCamelCase     (      self,       A,       A=None,       A=None,       A=None,       A=None,       ):





            """simple docstring"""

            _UpperCamelCase              =						()
            _UpperCamelCase              =						()
            _UpperCamelCase              =						()
            for i, layer_module in enumerate(self.layer      ):
                   if self.output_hidden_states:
                          _UpperCamelCase              =						all_hidden_states + (hidden_states,)

                   _UpperCamelCase              =						layer_module(
                       A,       A,       head_mask[i],       A,       A      )
                   _UpperCamelCase              =						layer_outputs[0]

                   if self.output_attentions:
                          _UpperCamelCase              =						all_attentions + (layer_outputs[1],)

                   _UpperCamelCase              =						(hidden_states,)
                   if self.output_hidden_states:
                          _UpperCamelCase              =						current_outputs + (all_hidden_states,)
                   if self.output_attentions:
                          _UpperCamelCase              =						current_outputs + (all_attentions,)

                   _UpperCamelCase              =						self.highway[i](A      )
                   # logits, pooled_output

                   if not self.training:
                          _UpperCamelCase              =						highway_exit[0]
                          _UpperCamelCase              =						entropy(A      )
                          _UpperCamelCase              =						highway_exit + (highway_entropy,)  # logits, hidden_states(?), entropy
                          _UpperCamelCase              =						all_highway_exits + (highway_exit,)

                          if highway_entropy < self.early_exit_entropy[i]:
                                 _UpperCamelCase              =						(highway_logits,) + current_outputs[1:] + (all_highway_exits,)
                                 raise HighwayException(A,       i + 1      )
                   else:
                          _UpperCamelCase              =						all_highway_exits + (highway_exit,)

        # Add last layer
            if self.output_hidden_states:
                   _UpperCamelCase              =						all_hidden_states + (hidden_states,)

            _UpperCamelCase              =						(hidden_states,)
            if self.output_hidden_states:
                   _UpperCamelCase              =						outputs + (all_hidden_states,)
            if self.output_attentions:
                   _UpperCamelCase              =						outputs + (all_attentions,)

            _UpperCamelCase              =						outputs + (all_highway_exits,)
            return outputs  # last-layer hidden state, (all hidden states), (all attentions), all highway exits






@add_start_docstrings(
    "The Bert Model transformer with early exiting (DeeBERT). "						,			__UpperCAmelCase						,			)
class  __A(						__UpperCAmelCase ):

     def __init__(      self,       A      ):





            """simple docstring"""

            super().__init__(A      )
            _UpperCamelCase              =						config

            _UpperCamelCase              =						BertEmbeddings(A      )
            _UpperCamelCase              =						DeeBertEncoder(A      )
            _UpperCamelCase              =						BertPooler(A      )

            self.init_weights()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            self.encoder.init_highway_pooler(self.pooler      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return self.embeddings.word_embeddings

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						value

     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            for layer, heads in heads_to_prune.items():
                   self.encoder.layer[layer].attention.prune_heads(A      )



     @add_start_docstrings_to_model_forward(A      )
     def 	_UpperCamelCase     (      self,       A=None,       A=None,       A=None,       A=None,       A=None,       A=None,       A=None,       A=None,       ):





            """simple docstring"""

            if input_ids is not None and inputs_embeds is not None:
                   raise ValueError('''You cannot specify both input_ids and inputs_embeds at the same time'''      )
            elif input_ids is not None:
                   _UpperCamelCase              =						input_ids.size()
            elif inputs_embeds is not None:
                   _UpperCamelCase              =						inputs_embeds.size()[:-1]
            else:
                   raise ValueError('''You have to specify either input_ids or inputs_embeds'''      )

            _UpperCamelCase              =						input_ids.device if input_ids is not None else inputs_embeds.device

            if attention_mask is None:
                   _UpperCamelCase              =						torch.ones(A,       device=A      )
            if encoder_attention_mask is None:
                   _UpperCamelCase              =						torch.ones(A,       device=A      )
            if token_type_ids is None:
                   _UpperCamelCase              =						torch.zeros(A,       dtype=torch.long,       device=A      )

            # We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
            # ourselves in which case we just need to make it broadcastable to all heads.
            _UpperCamelCase              =						self.get_extended_attention_mask(A,       A,       A      )

            # If a 2D ou 3D attention mask is provided for the cross-attention
            # we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
            if encoder_attention_mask.dim() == 3:
                   _UpperCamelCase              =						encoder_attention_mask[:, None, :, :]
            if encoder_attention_mask.dim() == 2:
                   _UpperCamelCase              =						encoder_attention_mask[:, None, None, :]

            _UpperCamelCase              =						encoder_extended_attention_mask.to(
                dtype=next(self.parameters()      ).dtype      )  # fp16 compatibility
            _UpperCamelCase              =						(1.0 - encoder_extended_attention_mask) * -1_0000.0

            # Prepare head mask if needed
            # 1.0 in head_mask indicate we keep the head
            # attention_probs has shape bsz x n_heads x N x N
            # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
            # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
            _UpperCamelCase              =						self.get_head_mask(A,       self.config.num_hidden_layers      )

            _UpperCamelCase              =						self.embeddings(
                input_ids=A,       position_ids=A,       token_type_ids=A,       inputs_embeds=A      )
            _UpperCamelCase              =						self.encoder(
                A,       attention_mask=A,       head_mask=A,       encoder_hidden_states=A,       encoder_attention_mask=A,       )
            _UpperCamelCase              =						encoder_outputs[0]
            _UpperCamelCase              =						self.pooler(A      )

            _UpperCamelCase              =						(
                sequence_output,
                pooled_output,
            ) + encoder_outputs[
                1:
            ]  # add hidden_states and attentions if they are here
            return outputs  # sequence_output, pooled_output, (hidden_states), (attentions), highway exits






class  __A(						__UpperCAmelCase ):

     def __init__(      self,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						message
            _UpperCamelCase              =						exit_layer  # start from 1!






class  __A(						nn.Module ):

     def __init__(      self,       A      ):





            """simple docstring"""

            super().__init__()
            _UpperCamelCase              =						BertPooler(A      )
            _UpperCamelCase              =						nn.Dropout(config.hidden_dropout_prob      )
            _UpperCamelCase              =						nn.Linear(config.hidden_size,       config.num_labels      )



     def 	_UpperCamelCase     (      self,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						encoder_outputs[0]
            _UpperCamelCase              =						self.pooler(A      )
            # "return" pooler_output

            # BertModel
            _UpperCamelCase              =						(pooler_input, pooler_output) + encoder_outputs[1:]
            # "return" bmodel_output

            # Dropout and classification
            _UpperCamelCase              =						bmodel_output[1]

            _UpperCamelCase              =						self.dropout(A      )
            _UpperCamelCase              =						self.classifier(A      )

            return logits, pooled_output






@add_start_docstrings(
    "Bert Model (with early exiting - DeeBERT) with a classifier on top,\n    also takes care of multi-layer training. "						,			__UpperCAmelCase						,			)
class  __A(						__UpperCAmelCase ):

     def __init__(      self,       A      ):





            """simple docstring"""

            super().__init__(A      )
            _UpperCamelCase              =						config.num_labels
            _UpperCamelCase              =						config.num_hidden_layers

            _UpperCamelCase              =						DeeBertModel(A      )
            _UpperCamelCase              =						nn.Dropout(config.hidden_dropout_prob      )
            _UpperCamelCase              =						nn.Linear(config.hidden_size,       self.config.num_labels      )

            self.init_weights()



     @add_start_docstrings_to_model_forward(A      )
     def 	_UpperCamelCase     (      self,       A=None,       A=None,       A=None,       A=None,       A=None,       A=None,       A=None,       A=-1,       A=False,       ):





            """simple docstring"""

            _UpperCamelCase              =						self.num_layers
            try:
                   _UpperCamelCase              =						self.bert(
                       A,       attention_mask=A,       token_type_ids=A,       position_ids=A,       head_mask=A,       inputs_embeds=A,       )
                   # sequence_output, pooled_output, (hidden_states), (attentions), highway exits

                   _UpperCamelCase              =						outputs[1]

                   _UpperCamelCase              =						self.dropout(A      )
                   _UpperCamelCase              =						self.classifier(A      )
                   _UpperCamelCase              =						(logits,) + outputs[2:]  # add hidden states and attention if they are here
            except HighwayException as e:
                   _UpperCamelCase              =						e.message
                   _UpperCamelCase              =						e.exit_layer
                   _UpperCamelCase              =						outputs[0]

            if not self.training:
                   _UpperCamelCase              =						entropy(A      )
                   _UpperCamelCase              =						[]
                   _UpperCamelCase              =						[]
            if labels is not None:
                   if self.num_labels == 1:
                          #  We are doing regression
                          _UpperCamelCase              =						MSELoss()
                          _UpperCamelCase              =						loss_fct(logits.view(-1      ),       labels.view(-1      )      )
                   else:
                          _UpperCamelCase              =						CrossEntropyLoss()
                          _UpperCamelCase              =						loss_fct(logits.view(-1,       self.num_labels      ),       labels.view(-1      )      )

                   # work with highway exits
                   _UpperCamelCase              =						[]
                   for highway_exit in outputs[-1]:
                          _UpperCamelCase              =						highway_exit[0]
                          if not self.training:
                                 highway_logits_all.append(A      )
                                 highway_entropy.append(highway_exit[2]      )
                          if self.num_labels == 1:
                                 #  We are doing regression
                                 _UpperCamelCase              =						MSELoss()
                                 _UpperCamelCase              =						loss_fct(highway_logits.view(-1      ),       labels.view(-1      )      )
                          else:
                                 _UpperCamelCase              =						CrossEntropyLoss()
                                 _UpperCamelCase              =						loss_fct(highway_logits.view(-1,       self.num_labels      ),       labels.view(-1      )      )
                          highway_losses.append(A      )

                   if train_highway:
                          _UpperCamelCase              =						(sum(highway_losses[:-1]      ),) + outputs
                          # exclude the final highway, of course
                   else:
                          _UpperCamelCase              =						(loss,) + outputs
            if not self.training:
                   _UpperCamelCase              =						outputs + ((original_entropy, highway_entropy), exit_layer)
                   if output_layer >= 0:
                          _UpperCamelCase              =						(
                              (outputs[0],) + (highway_logits_all[output_layer],) + outputs[2:]
                          )  # use the highway of the last layer

            return outputs  # (loss), logits, (hidden_states), (attentions), (highway_exits)













import os
import sys
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from huggingface_hub import HfFolder, delete_repo
from huggingface_hub.file_download import http_get
from requests.exceptions import HTTPError

from transformers import (
    AlbertTokenizer,
    AutoTokenizer,
    BertTokenizer,
    BertTokenizerFast,
    GPTaTokenizerFast,
    is_tokenizers_available,
)
from transformers.testing_utils import TOKEN, USER, is_staging_test, require_tokenizers
from transformers.tokenization_utils import Trie


sys.path.append(str(Path(__file__).parent.parent / """utils"""))

from test_module.custom_tokenization import CustomTokenizer  # noqa E402


if is_tokenizers_available():
       from test_module.custom_tokenization_fast import CustomTokenizerFast

class  __A(						unittest.TestCase ):

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						mock.Mock()
            _UpperCamelCase              =						500
            _UpperCamelCase              =						{}
            _UpperCamelCase              =						HTTPError
            _UpperCamelCase              =						{}

            # Download this model to make sure it's in the cache.
            _UpperCamelCase              =						BertTokenizer.from_pretrained('''hf-internal-testing/tiny-random-bert'''      )

            # Under the mock environment we get a 500 error when trying to reach the tokenizer.
            with mock.patch('''requests.Session.request''',       return_value=A      ) as mock_head:
                   _UpperCamelCase              =						BertTokenizer.from_pretrained('''hf-internal-testing/tiny-random-bert'''      )
                   # This check we did call the fake head request
                   mock_head.assert_called()

     @require_tokenizers
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						mock.Mock()
            _UpperCamelCase              =						500
            _UpperCamelCase              =						{}
            _UpperCamelCase              =						HTTPError
            _UpperCamelCase              =						{}

            # Download this model to make sure it's in the cache.
            _UpperCamelCase              =						GPTaTokenizerFast.from_pretrained('''gpt2'''      )

            # Under the mock environment we get a 500 error when trying to reach the tokenizer.
            with mock.patch('''requests.Session.request''',       return_value=A      ) as mock_head:
                   _UpperCamelCase              =						GPTaTokenizerFast.from_pretrained('''gpt2'''      )
                   # This check we did call the fake head request
                   mock_head.assert_called()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            try:
                   _UpperCamelCase              =						tempfile.mktemp()
                   with open(A,       '''wb'''      ) as f:
                          http_get('''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',       A      )

                   _UpperCamelCase              =						AlbertTokenizer.from_pretrained(A      )
            finally:
                   os.remove(A      )

            # Supporting this legacy load introduced a weird bug where the tokenizer would load local files if they are in
            # the current folder and have the right name.
            if os.path.isfile('''tokenizer.json'''      ):
                   # We skip the test if the user has a `tokenizer.json` in this folder to avoid deleting it.
                   return
            try:
                   with open('''tokenizer.json''',       '''wb'''      ) as f:
                          http_get('''https://huggingface.co/hf-internal-testing/tiny-random-bert/blob/main/tokenizer.json''',       A      )
                   _UpperCamelCase              =						AutoTokenizer.from_pretrained('''hf-internal-testing/tiny-random-gpt2'''      )
                   # The tiny random BERT has a vocab size of 1024, tiny gpt2 as a vocab size of 1000
                   self.assertEqual(tokenizer.vocab_size,       1000      )
                   # Tokenizer should depend on the remote checkpoint, not the local tokenizer.json file.

            finally:
                   os.remove('''tokenizer.json'''      )



     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						AlbertTokenizer.from_pretrained('''https://huggingface.co/albert-base-v1/resolve/main/spiece.model'''      )






@is_staging_test
class  __A(						unittest.TestCase ):
     __A	  =       ["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]", "bla", "blou"]

     @classmethod
     def 	_UpperCamelCase     (      cls      ):





            """simple docstring"""

            _UpperCamelCase              =						TOKEN
            HfFolder.save_token(A      )

     @classmethod
     def 	_UpperCamelCase     (      cls      ):





            """simple docstring"""

            try:
                   delete_repo(token=cls._token,       repo_id='''test-tokenizer'''      )
            except HTTPError:
                   pass

            try:
                   delete_repo(token=cls._token,       repo_id='''valid_org/test-tokenizer-org'''      )
            except HTTPError:
                   pass

            try:
                   delete_repo(token=cls._token,       repo_id='''test-dynamic-tokenizer'''      )
            except HTTPError:
                   pass

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            with tempfile.TemporaryDirectory() as tmp_dir:
                   _UpperCamelCase              =						os.path.join(A,       '''vocab.txt'''      )
                   with open(A,       '''w''',       encoding='''utf-8'''      ) as vocab_writer:
                          vocab_writer.write(''''''.join([x + '''\n''' for x in self.vocab_tokens]      )      )
                   _UpperCamelCase              =						BertTokenizer(A      )

            tokenizer.push_to_hub('''test-tokenizer''',       use_auth_token=self._token      )
            _UpperCamelCase              =						BertTokenizer.from_pretrained(F'''{USER}/test-tokenizer'''      )
            self.assertDictEqual(new_tokenizer.vocab,       tokenizer.vocab      )

            # Reset repo
            delete_repo(token=self._token,       repo_id='''test-tokenizer'''      )

            # Push to hub via save_pretrained
            with tempfile.TemporaryDirectory() as tmp_dir:
                   tokenizer.save_pretrained(A,       repo_id='''test-tokenizer''',       push_to_hub=A,       use_auth_token=self._token      )

            _UpperCamelCase              =						BertTokenizer.from_pretrained(F'''{USER}/test-tokenizer'''      )
            self.assertDictEqual(new_tokenizer.vocab,       tokenizer.vocab      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            with tempfile.TemporaryDirectory() as tmp_dir:
                   _UpperCamelCase              =						os.path.join(A,       '''vocab.txt'''      )
                   with open(A,       '''w''',       encoding='''utf-8'''      ) as vocab_writer:
                          vocab_writer.write(''''''.join([x + '''\n''' for x in self.vocab_tokens]      )      )
                   _UpperCamelCase              =						BertTokenizer(A      )

            tokenizer.push_to_hub('''valid_org/test-tokenizer-org''',       use_auth_token=self._token      )
            _UpperCamelCase              =						BertTokenizer.from_pretrained('''valid_org/test-tokenizer-org'''      )
            self.assertDictEqual(new_tokenizer.vocab,       tokenizer.vocab      )

            # Reset repo
            delete_repo(token=self._token,       repo_id='''valid_org/test-tokenizer-org'''      )

            # Push to hub via save_pretrained
            with tempfile.TemporaryDirectory() as tmp_dir:
                   tokenizer.save_pretrained(
                       A,       repo_id='''valid_org/test-tokenizer-org''',       push_to_hub=A,       use_auth_token=self._token      )

            _UpperCamelCase              =						BertTokenizer.from_pretrained('''valid_org/test-tokenizer-org'''      )
            self.assertDictEqual(new_tokenizer.vocab,       tokenizer.vocab      )



     @require_tokenizers
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            CustomTokenizer.register_for_auto_class()
            with tempfile.TemporaryDirectory() as tmp_dir:
                   _UpperCamelCase              =						os.path.join(A,       '''vocab.txt'''      )
                   with open(A,       '''w''',       encoding='''utf-8'''      ) as vocab_writer:
                          vocab_writer.write(''''''.join([x + '''\n''' for x in self.vocab_tokens]      )      )
                   _UpperCamelCase              =						CustomTokenizer(A      )

            # No fast custom tokenizer
            tokenizer.push_to_hub('''test-dynamic-tokenizer''',       use_auth_token=self._token      )

            _UpperCamelCase              =						AutoTokenizer.from_pretrained(F'''{USER}/test-dynamic-tokenizer''',       trust_remote_code=A      )
            # Can't make an isinstance check because the new_model.config is from the CustomTokenizer class of a dynamic module
            self.assertEqual(tokenizer.__class__.__name__,       '''CustomTokenizer'''      )

            # Fast and slow custom tokenizer
            CustomTokenizerFast.register_for_auto_class()
            with tempfile.TemporaryDirectory() as tmp_dir:
                   _UpperCamelCase              =						os.path.join(A,       '''vocab.txt'''      )
                   with open(A,       '''w''',       encoding='''utf-8'''      ) as vocab_writer:
                          vocab_writer.write(''''''.join([x + '''\n''' for x in self.vocab_tokens]      )      )

                   _UpperCamelCase              =						BertTokenizerFast.from_pretrained(A      )
                   bert_tokenizer.save_pretrained(A      )
                   _UpperCamelCase              =						CustomTokenizerFast.from_pretrained(A      )

            tokenizer.push_to_hub('''test-dynamic-tokenizer''',       use_auth_token=self._token      )

            _UpperCamelCase              =						AutoTokenizer.from_pretrained(F'''{USER}/test-dynamic-tokenizer''',       trust_remote_code=A      )
            # Can't make an isinstance check because the new_model.config is from the FakeConfig class of a dynamic module
            self.assertEqual(tokenizer.__class__.__name__,       '''CustomTokenizerFast'''      )
            _UpperCamelCase              =						AutoTokenizer.from_pretrained(
                F'''{USER}/test-dynamic-tokenizer''',       use_fast=A,       trust_remote_code=A      )
            # Can't make an isinstance check because the new_model.config is from the FakeConfig class of a dynamic module
            self.assertEqual(tokenizer.__class__.__name__,       '''CustomTokenizer'''      )






class  __A(						unittest.TestCase ):

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            trie.add('''Hello 友達'''      )
            self.assertEqual(trie.data,       {'''H''': {'''e''': {'''l''': {'''l''': {'''o''': {''' ''': {'''友''': {'''達''': {'''''': 1}}}}}}}}}      )
            trie.add('''Hello'''      )
            trie.data
            self.assertEqual(trie.data,       {'''H''': {'''e''': {'''l''': {'''l''': {'''o''': {'''''': 1, ''' ''': {'''友''': {'''達''': {'''''': 1}}}}}}}}}      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            self.assertEqual(trie.split('''[CLS] This is a extra_id_100'''      ),       ['''[CLS] This is a extra_id_100''']      )
            trie.add('''[CLS]'''      )
            trie.add('''extra_id_1'''      )
            trie.add('''extra_id_100'''      )
            self.assertEqual(trie.split('''[CLS] This is a extra_id_100'''      ),       ['''[CLS]''', ''' This is a ''', '''extra_id_100''']      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            trie.add('''A'''      )
            self.assertEqual(trie.split('''ABC'''      ),       ['''A''', '''BC''']      )
            self.assertEqual(trie.split('''BCA'''      ),       ['''BC''', '''A''']      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            trie.add('''TOKEN]'''      )
            trie.add('''[SPECIAL_TOKEN]'''      )
            self.assertEqual(trie.split('''This is something [SPECIAL_TOKEN]'''      ),       ['''This is something ''', '''[SPECIAL_TOKEN]''']      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            trie.add('''A'''      )
            trie.add('''P'''      )
            trie.add('''[SPECIAL_TOKEN]'''      )
            self.assertEqual(trie.split('''This is something [SPECIAL_TOKEN]'''      ),       ['''This is something ''', '''[SPECIAL_TOKEN]''']      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            trie.add('''AB'''      )
            trie.add('''B'''      )
            trie.add('''C'''      )
            self.assertEqual(trie.split('''ABC'''      ),       ['''AB''', '''C''']      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            trie.add('''ABC'''      )
            trie.add('''B'''      )
            trie.add('''CD'''      )
            self.assertEqual(trie.split('''ABCD'''      ),       ['''ABC''', '''D''']      )



     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						Trie()
            _UpperCamelCase              =						trie.cut_text('''ABC''',       [0, 0, 2, 1, 2, 3]      )
            self.assertEqual(A,       ['''AB''', '''C''']      )






