class_docstr: Generic Metadata writer.
  
  Example usage:
  
  For an example model which requires two inputs: image and general feature
  inputs, and generates one output: classification.
  
  with open(model_path, 'rb') as f:
    writer = MetadataWriter.create(f.read())
    model_content, metadata_json_content = writer
        .add_genernal_info('model_name', 'model description')
        .add_image_input()
        .add_feature_input()
        .add_classification_output(Labels().add(['A', 'B']))
        .populate()
class_docstr_tok: ["Generic","Metadata","writer",".","Example","usage",":","For","an","example","model","which","requires","two","inputs",":","image","and","general","feature","inputs",",","and","generates","one","output",":","classification",".","with","open","(","model_path",",","'rb","'",")","as","f",":","writer","=","MetadataWriter.create","(","f.read","(",")",")","model_content",",","metadata_json_content","=","writer",".add_genernal_info","(","'model_name","'",",","'model","description","'",")",".add_image_input","(",")",".add_feature_input","(",")",".add_classification_output","(","Labels","(",")",".add","(","[","'","A","'",",","'","B","'","]",")",")",".populate","(",")"]
docstr: Adds an metadata for the text input with bert / sentencepiece tokenizer.
  
  `ids_name`, `mask_name`, and `segment_name` correspond to the `Tensor.name`
  in the TFLite schema, which help to determine the tensor order when
  populating metadata.
  
  Args:
    tokenizer: information of the tokenizer used to process the input string,
      if any. Supported tokenziers are: `BertTokenizer` [1] and
      `SentencePieceTokenizer` [2].
    ids_name: name of the ids tensor, which represents the tokenized ids of
      the input text.
    mask_name: name of the mask tensor, which represents the mask with `1` for
      real tokens and `0` for padding tokens.
    segment_name: name of the segment ids tensor, where `0` stands for the
      first sequence, and `1` stands for the second sequence if exists.
  
  Returns:
    The MetadataWriter instance, can be used for chained operation.
  
  Raises:
    ValueError: if the type tokenizer is not BertTokenizer or
      SentencePieceTokenizer.
  
  [1]:
    https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L477
  [2]:
    https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L485
code: def add_bert_text_input(
      self,
      tokenizer: Union[BertTokenizer, SentencePieceTokenizer],
      ids_name: str,
      mask_name: str,
      segment_name: str,
  ) -> "MetadataWriter":
      """Adds an metadata for the text input with bert / sentencepiece tokenizer.
  
      `ids_name`, `mask_name`, and `segment_name` correspond to the `Tensor.name`
      in the TFLite schema, which help to determine the tensor order when
      populating metadata.
  
      Args:
        tokenizer: information of the tokenizer used to process the input string,
          if any. Supported tokenziers are: `BertTokenizer` [1] and
          `SentencePieceTokenizer` [2].
        ids_name: name of the ids tensor, which represents the tokenized ids of
          the input text.
        mask_name: name of the mask tensor, which represents the mask with `1` for
          real tokens and `0` for padding tokens.
        segment_name: name of the segment ids tensor, where `0` stands for the
          first sequence, and `1` stands for the second sequence if exists.
  
      Returns:
        The MetadataWriter instance, can be used for chained operation.
  
      Raises:
        ValueError: if the type tokenizer is not BertTokenizer or
          SentencePieceTokenizer.
  
      [1]:
        https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L477
      [2]:
        https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L485
      """
      if isinstance(tokenizer, BertTokenizer):
          tokenizer_md = metadata_info.BertTokenizerMd(
              vocab_file_path=tokenizer.vocab_file_path
          )
      elif isinstance(tokenizer, SentencePieceTokenizer):
          tokenizer_md = metadata_info.SentencePieceTokenizerMd(
              sentence_piece_model_path=tokenizer.sentence_piece_model_path,
              vocab_file_path=tokenizer.vocab_file_path,
          )
      else:
          raise ValueError(
              f"The type of tokenizer, {type(tokenizer)}, is unsupported"
          )
      bert_input_md = metadata_info.BertInputTensorsMd(
          self._model_buffer,
          ids_name,
          mask_name,
          segment_name,
          tokenizer_md=tokenizer_md,
      )
  
      self._input_mds.extend(bert_input_md.input_md)
      self._associated_files.extend(
          bert_input_md.get_tokenizer_associated_files()
      )
      self._input_process_units.extend(
          bert_input_md.create_input_process_unit_metadata()
      )
      return self
  
imports: import collections
  import csv
  import dataclasses
  import os
  import tempfile
  from typing import List, Optional, Tuple, Union
  import flatbuffers
  from mediapipe.tasks.metadata import metadata_schema_py_generated
  from mediapipe.tasks.python.metadata import metadata
  from mediapipe.tasks.python.metadata.metadata_writers import metadata_info
  from mediapipe.tasks.python.metadata.metadata_writers import writer_utils
label_desc: Use image node_id 8 for calling the MetadataWriter obj's underlying member method code with example usage: obj.add_bert_text_input(tokenizer, ids_name, mask_name, segment_name) and returns: self