# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # This file was automatically generated from src/transformers/models/videoprism/modular_videoprism.py. # Do NOT edit this file manually as any edits will be overwritten by the generation of # the file from the modular. If any change should be done, please apply the change to the # modular_videoprism.py file directly. One of our CI enforces this. # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 # Copyright 2026 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import re from tokenizers import Tokenizer, decoders, normalizers, pre_tokenizers from tokenizers.models import Unigram from ...tokenization_utils_tokenizers import TokenizersBackend VOCAB_FILES_NAMES = {"vocab_file": "spiece.model", "tokenizer_file": "tokenizer.json"} class VideoPrismTokenizer(TokenizersBackend): r""" Constructs a VideoPrism tokenizer, which is essentially a T5 tokenizer without its postprocessor (appending an EOS token at the end of the sequence). This tokenizer inherits from [`T5Tokenizer`] which contains most of the main methods. Users should refer to this superclass for more information regarding those methods. """ vocab_files_names = VOCAB_FILES_NAMES model_input_names = ["input_ids", "attention_mask"] model = Unigram def __init__( self, vocab: str | list[tuple[str, float]] | None = None, eos_token="", unk_token="", pad_token="", _spm_precompiled_charsmap=None, extra_ids=100, additional_special_tokens=None, **kwargs, ): self._extra_ids = extra_ids # Handle extra_ids and additional_special_tokens if additional_special_tokens is not None: extra_tokens = [x for x in additional_special_tokens if "" for i in range(extra_ids)] elif extra_ids > 0 and extra_ids != len(extra_tokens): raise ValueError( f"Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are" " provided to VideoPrismTokenizer. In this case the additional_special_tokens must include the extra_ids" " tokens" ) else: extra_tokens = [f"" for i in range(extra_ids)] additional_special_tokens = extra_tokens # VIDEOPRISM vocab structure: =0, =1, =2, then regular vocab, then extra_ids in reverse if vocab is not None: self._vocab_scores = vocab else: self._vocab_scores = [ (str(pad_token), 0.0), (str(eos_token), 0.0), (str(unk_token), 0.0), ("▁", -2.0), # Space token ] for i in range(extra_ids - 1, -1, -1): self._vocab_scores.append((f"", 0.0)) self._tokenizer = Tokenizer( Unigram( self._vocab_scores, unk_id=2, byte_fallback=False, ) ) if _spm_precompiled_charsmap is not None: self._tokenizer.normalizer = normalizers.Precompiled(_spm_precompiled_charsmap) self._tokenizer.pre_tokenizer = pre_tokenizers.Sequence( [ pre_tokenizers.WhitespaceSplit(), pre_tokenizers.Metaspace(replacement="▁", prepend_scheme="always", split=True), ] ) self._tokenizer.decoder = decoders.Metaspace(replacement="▁", prepend_scheme="always", split=True) super().__init__( eos_token=eos_token, unk_token=unk_token, pad_token=pad_token, extra_ids=extra_ids, additional_special_tokens=additional_special_tokens, **kwargs, ) def get_sentinel_tokens(self): """Get the list of sentinel tokens (extra_id tokens) from additional_special_tokens.""" return list( set(filter(lambda x: bool(re.search(r"", x)) is not None, self.additional_special_tokens)) ) def get_sentinel_token_ids(self): """Get the token IDs for sentinel tokens.""" return [self.convert_tokens_to_ids(token) for token in self.get_sentinel_tokens()] __all__ = ["VideoPrismTokenizer"]