code: def boise_tags_to_offsets(
      token_begin_offsets, token_end_offsets, boise_tags
  ):
      """Converts the token offsets and BOISE tags into span offsets and span type.
  
      In the BOISE scheme there is a set of 5 labels for each type:
        - (B)egin: meaning the beginning of the span type.
        - (O)utside: meaning the token is outside of any span type
        - (I)nside: the token is inside the span
        - (S)ingleton: the entire span consists of this single token.
        - (E)nd: this token is the end of the span.
  
      For example, given the following example string and entity:
  
        content = "Who let the dogs out"
        entity = "dogs"
        tokens = ["Who", "let", "the", "dogs", "out"]
        token_begin_offsets = [0, 4, 8, 12, 17]
        token_end_offsets = [3, 7, 11, 16, 20]
        span_begin_offsets = [12]
        span_end_offsets = [16]
        span_type = ["animal"]
  
        BOISE tags are:
         ["O", "O", "O",  "S-animal", "O"]
           |    |    |        |        |
          Who  let  the      dogs     out
  
      When given the token begin/end offsets and BOISE tags for an input text
      sequence, this function translates them into entity span begin/end offsets
      and span types.
  
      ### Example:
      >>> token_begin_offsets = tf.ragged.constant(
      ...   [[0, 4, 8, 12, 17], [0, 4, 8, 12]])
      >>> token_end_offsets = tf.ragged.constant(
      ...   [[3, 7, 11, 16, 20], [3, 7, 11, 16]])
      >>> boise_tags = tf.ragged.constant(
      ...   [['O', 'B-animal', 'I-animal', 'E-animal', 'O'],
      ...    ['O', 'O', 'O', 'S-loc']])
      >>> (span_begin_offsets, span_end_offsets, span_type) = (
      ...   tf_text.boise_tags_to_offsets(token_begin_offsets, token_end_offsets,
      ...     boise_tags))
      >>> span_begin_offsets
      <tf.RaggedTensor [[4], [12]]>
      >>> span_end_offsets
      <tf.RaggedTensor [[16], [16]]>
      >>> span_type
      <tf.RaggedTensor [[b'animal'], [b'loc']]>
  
      Args:
        token_begin_offsets: A `RaggedTensor` or `Tensor` of token begin byte
          offsets of int32 or int64.
        token_end_offsets: A `RaggedTensor` or `Tensor` of token end byte offsets of
          int32 or int64.
        boise_tags: A `RaggedTensor` of BOISE tag strings in the same dimension as
          the token begin and end offsets.
  
      Returns:
       A tuple containing `span_begin_offsets`, `span_end_offsets` and `span_type`.
       `span_begin_offsets` is a `RaggedTensor` or `Tensor` of span begin byte
          offsets of int32 or int64.
       `span_end_offsets` is a `RaggedTensor` or `Tensor` of span end byte offsets
          of int32 or int64.
       `span_type` is a `RaggedTensor` or `Tensor` of span type strings.
      """
      name = None
      with ops.name_scope(
          name,
          "BoiseTagsToOffsets",
          [
              token_begin_offsets,
              token_end_offsets,
              boise_tags,
          ],
      ):
          (
              token_begin_offsets_tensor
          ) = ragged_tensor.convert_to_tensor_or_ragged_tensor(
              token_begin_offsets
          )
          token_end_offsets_tensor = (
              ragged_tensor.convert_to_tensor_or_ragged_tensor(
                  token_end_offsets
              )
          )
          boise_tags_tensor = (
              ragged_tensor.convert_to_tensor_or_ragged_tensor(
                  boise_tags
              )
          )
  
          _validate_input_has_same_type(
              token_begin_offsets_tensor,
              token_end_offsets_tensor,
              boise_tags_tensor,
          )
  
          token_begin_offsets_tensor = tf.cast(
              token_begin_offsets_tensor, dtype=tf.int32
          )
          token_end_offsets_tensor = tf.cast(
              token_end_offsets_tensor, dtype=tf.int32
          )
  
          if token_begin_offsets_tensor.shape.ndims is None:
              raise ValueError(
                  "Rank of input_tensor must be statically known."
              )
          if ragged_tensor.is_ragged(token_begin_offsets_tensor):
              try:
                  (
                      span_begin_offsets,
                      span_end_offsets,
                      span_type,
                      row_splits,
                  ) = gen_boise_offset_converter.tf_text_boise_tags_to_offsets(
                      input_token_begin_offsets=token_begin_offsets_tensor.flat_values,
                      input_token_end_offsets=token_end_offsets_tensor.flat_values,
                      input_boise_tags=boise_tags_tensor.flat_values,
                      input_token_begin_row_splits=token_begin_offsets_tensor.nested_row_splits[
                          -1
                      ],
                      input_token_end_row_splits=token_end_offsets_tensor.nested_row_splits[
                          -1
                      ],
                      input_boise_tags_row_splits=boise_tags_tensor.nested_row_splits[
                          -1
                      ],
                  )
                  span_begin_offsets = (
                      RaggedTensor.from_nested_row_splits(
                          flat_values=span_begin_offsets,
                          nested_row_splits=[row_splits],
                      )
                  )
                  span_end_offsets = (
                      RaggedTensor.from_nested_row_splits(
                          flat_values=span_end_offsets,
                          nested_row_splits=[row_splits],
                      )
                  )
                  span_type = RaggedTensor.from_nested_row_splits(
                      flat_values=span_type,
                      nested_row_splits=[row_splits],
                  )
                  return span_begin_offsets, span_end_offsets, span_type
              except (
                  tf.errors.InvalidArgumentError,
                  tf.errors.FailedPreconditionError,
              ) as exc:
                  raise ValueError(
                      "Input token and BOISE tags tensor shape don't match."
                  ) from exc
          else:
              if token_begin_offsets_tensor.shape.ndims > 1:
                  return boise_tags_to_offsets(
                      ragged_conversion_ops.from_tensor(
                          token_begin_offsets_tensor
                      ),
                      ragged_conversion_ops.from_tensor(
                          token_end_offsets_tensor
                      ),
                      ragged_conversion_ops.from_tensor(
                          boise_tags_tensor
                      ),
                  )
              elif token_begin_offsets_tensor.shape.ndims == 0:
                  (
                      span_begin_offsets,
                      span_end_offsets,
                      span_type,
                  ) = boise_tags_to_offsets(
                      tf.stack([token_begin_offsets_tensor]),
                      tf.stack([token_end_offsets_tensor]),
                      tf.stack([boise_tags_tensor]),
                  )
                  return (
                      span_begin_offsets[0],
                      span_end_offsets[0],
                      span_type[0],
                  )
              else:
                  (
                      span_begin_offsets,
                      span_end_offsets,
                      span_type,
                  ) = boise_tags_to_offsets(
                      tf.stack([token_begin_offsets_tensor]),
                      tf.stack([token_end_offsets_tensor]),
                      tf.stack([boise_tags_tensor]),
                  )
                  return (
                      span_begin_offsets.merge_dims(0, 1),
                      span_end_offsets.merge_dims(0, 1),
                      span_type.merge_dims(0, 1),
                  )
  
file_path: text/tensorflow_text/python/ops/boise_offset_converter.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import tensorflow
  from tensorflow.python.framework import ops
  from tensorflow.python.ops.ragged import ragged_conversion_ops
  from tensorflow.python.ops.ragged import ragged_tensor
  from tensorflow.python.ops.ragged.ragged_tensor import RaggedTensor
  from tensorflow.python.framework import load_library
  from tensorflow.python.platform import resource_loader
label_desc: Use image node_id 3 for calling a global function with example usage: boise_tags_to_offsets(token_begin_offsets, token_end_offsets, boise_tags) and returns: span_begin_offsets,  span_end_offsets,  span_type, boise_tags_to_offsets, span_begin_offsets,  span_end_offsets,  span_type, span_begin_offsets,  span_end_offsets,  span_type