class_docstr: Extracts Score2Perf examples from NoteSequence protos for conditioning.
class_docstr_tok: ["Extracts","Score2Perf","examples","from","NoteSequence","protos","for","conditioning","."]
docstr: Initialize a ConditionalExtractExamplesDoFn.
  
  If any of the `encode_score_fns` or `encode_performance_fn` returns an empty
  encoding for a particular example, the example will be discarded.
  
  Args:
    melody: If True, uses both melody and performance conditioning.
    noisy: If True, uses a perturbed version of the performance for
           conditioning. Currently only supported for mel & perf autoencoder.
    encode_performance_fn: Performance encoding function. Will be applied to
        the performance NoteSequence and the resulting encoding will be stored
        as 'targets' in each example.
    encode_score_fns: Optional dictionary of named score encoding functions.
        If provided, each function will be applied to the score NoteSequence
        and the resulting encodings will be stored in each example.
    augment_fns: Optional list of data augmentation functions. If provided,
        each function will be applied to each performance NoteSequence (and
        score, when using scores), creating a separate example per
        augmentation function. Should not modify the NoteSequence.
    num_replications: Number of times input NoteSequence protos will be
        replicated prior to splitting.
  
  Raises:
    ValueError: If the maximum hop size is less than twice the minimum hop
        size, or if `encode_score_fns` and `random_crop_length` are both
        specified.
docstr_tok: ["Initialize","a","ConditionalExtractExamplesDoFn",".","If","any","of","the","`","encode_score_fns","`","or","`","encode_performance_fn","`","returns","an","empty","encoding","for","a","particular","example",",","the","example","will","be","discarded",".","Args",":","melody",":","If","True",",","uses","both","melody","and","performance","conditioning",".","noisy",":","If","True",",","uses","a","perturbed","version","of","the","performance","for","conditioning",".","Currently","only","supported","for","mel","&","perf","autoencoder",".","encode_performance_fn",":","Performance","encoding","function",".","Will","be","applied","to","the","performance","NoteSequence","and","the","resulting","encoding","will","be","stored","as","'targets","'","in","each","example",".","encode_score_fns",":","Optional","dictionary","of","named","score","encoding","functions",".","If","provided",",","each","function","will","be","applied","to","the","score","NoteSequence","and","the","resulting","encodings","will","be","stored","in","each","example",".","augment_fns",":","Optional","list","of","data","augmentation","functions",".","If","provided",",","each","function","will","be","applied","to","each","performance","NoteSequence","(","and","score",",","when","using","scores",")",",","creating","a","separate","example","per","augmentation","function",".","Should","not","modify","the","NoteSequence",".","num_replications",":","Number","of","times","input","NoteSequence","protos","will","be","replicated","prior","to","splitting",".","Raises",":","ValueError",":","If","the","maximum","hop","size","is","less","than","twice","the","minimum","hop","size",",","or","if","`","encode_score_fns","`","and","`","random_crop_length","`","are","both","specified","."]
code: def __init__(
      self,
      melody,
      noisy,
      encode_performance_fn,
      encode_score_fns,
      augment_fns,
      num_replications,
      *unused_args,
      **unused_kwargs,
  ):
      """Initialize a ConditionalExtractExamplesDoFn.
  
      If any of the `encode_score_fns` or `encode_performance_fn` returns an empty
      encoding for a particular example, the example will be discarded.
  
      Args:
        melody: If True, uses both melody and performance conditioning.
        noisy: If True, uses a perturbed version of the performance for
               conditioning. Currently only supported for mel & perf autoencoder.
        encode_performance_fn: Performance encoding function. Will be applied to
            the performance NoteSequence and the resulting encoding will be stored
            as 'targets' in each example.
        encode_score_fns: Optional dictionary of named score encoding functions.
            If provided, each function will be applied to the score NoteSequence
            and the resulting encodings will be stored in each example.
        augment_fns: Optional list of data augmentation functions. If provided,
            each function will be applied to each performance NoteSequence (and
            score, when using scores), creating a separate example per
            augmentation function. Should not modify the NoteSequence.
        num_replications: Number of times input NoteSequence protos will be
            replicated prior to splitting.
  
      Raises:
        ValueError: If the maximum hop size is less than twice the minimum hop
            size, or if `encode_score_fns` and `random_crop_length` are both
            specified.
      """
      super(ConditionalExtractExamplesDoFn, self).__init__(
          *unused_args, **unused_kwargs
      )
      self._melody = melody
      self._noisy = noisy
      self._encode_performance_fn = encode_performance_fn
      self._encode_score_fns = encode_score_fns
      self._num_replications = num_replications
      self._augment_fns = (
          augment_fns if augment_fns else [lambda ns: ns]
      )
      self._decode_performance_fn = (
          music_encoders.MidiPerformanceEncoder(
              steps_per_second=100,
              num_velocity_bins=32,
              min_pitch=21,
              max_pitch=108,
              add_eos=False,
          ).decode
      )
  
imports: import copy
  import functools
  import hashlib
  import logging
  import os
  import random
  import typing
  import apache_beam
  from apache_beam import typehints
  from apache_beam.metrics import Metrics
  from magenta.models.score2perf import music_encoders
  import note_seq
  from note_seq import chord_inference
  from note_seq import melody_inference
  from note_seq import sequences_lib
  import numpy
  from tensor2tensor.data_generators import generator_utils
  import tensorflow.compat.v1
label_desc: Use image node_id 1 to create a new ConditionalExtractExamplesDoFn object from inherited base classes: beam with example: obj = ConditionalExtractExamplesDoFn(melody, noisy, encode_performance_fn, encode_score_fns, augment_fns, num_replications)