code: def _tokenize(
      texts: Union[str, Sequence[str]],
      tokenizer: Any,
      context_length: int,
      truncate: bool = False,
  ) -> jnp.ndarray:
      """Tokenizes texts using tokenizer."""
      if isinstance(texts, str):
          texts = [texts]
      sot_token = tokenizer.encoder["<|startoftext|>"]
      eot_token = tokenizer.encoder["<|endoftext|>"]
      all_tokens = [
          [sot_token] + tokenizer.encode(text) + [eot_token]
          for text in texts
      ]
      result = np.zeros((len(all_tokens), context_length), dtype=int)
      for i, tokens in enumerate(all_tokens):
          if len(tokens) > context_length:
              if truncate:
                  tokens = tokens[: context_length - 1] + [eot_token]
              else:
                  raise RuntimeError(
                      f"Input {texts[i]} is too long for context length {context_length}"
                  )
  
          result[i, : len(tokens)] = np.asarray(tokens)
      return jnp.asarray(result)
  
file_path: scenic/scenic/projects/baselines/clip/tokenizer.py
imports: from absl import logging
  import functools
  from typing import Any, Callable, Optional, Sequence, Union
  from clip.simple_tokenizer import SimpleTokenizer
  import jax.numpy
  import numpy
  from scenic.projects.baselines.clip import download
label_desc: Use image node_id 1 for calling a global function with example usage: _tokenize(texts, tokenizer, context_length, truncate) and returns: jnp