code: def get_augment_ratio(
      train_data,
      should_augment_predicate,
      can_augment_predicate,
      desired_ratio=0.1,
      max_ratio=0.5,
  ):
      """
      Returns X so that if you randomly select X * N sentences, you get 10%
  
      The ratio will be chosen in the assumption that the final dataset
      is of size N rather than N + X * N.
  
      should_augment_predicate: returns True if the sentence has some
        feature which we may want to change occasionally.  for example,
        depparse sentences which end in punct
      can_augment_predicate: in the depparse sentences example, it is
        technically possible for the punct at the end to be the parent
        of some other word in the sentence.  in that case, the sentence
        should not be chosen.  should be at least as restrictive as
        should_augment_predicate
      """
      n_data = len(train_data)
      n_should_augment = sum(
          should_augment_predicate(sentence) for sentence in train_data
      )
      n_can_augment = sum(
          can_augment_predicate(sentence) for sentence in train_data
      )
      n_error = sum(
          can_augment_predicate(sentence)
          and not should_augment_predicate(sentence)
          for sentence in train_data
      )
      if n_error > 0:
          raise AssertionError(
              "can_augment_predicate allowed sentences not allowed by should_augment_predicate"
          )
  
      if n_can_augment == 0:
          logger.warning(
              "Found no sentences which matched can_augment_predicate {}".format(
                  can_augment_predicate
              )
          )
          return 0.0
      n_needed = n_data * desired_ratio - (n_data - n_should_augment)
      # if we want 10%, for example, and more than 10% already matches, we can skip
      if n_needed < 0:
          return 0.0
      ratio = n_needed / n_can_augment
      if ratio > max_ratio:
          return max_ratio
      return ratio
  
file_path: stanza/stanza/models/common/data.py
imports: import logging
  import random
  import torch
  import stanza.models.common.seq2seq_constant
  from stanza.models.common.doc import HEAD, ID, UPOS
label_desc: Use image node_id 5 for calling a global function with example usage: get_augment_ratio(train_data, should_augment_predicate, can_augment_predicate, desired_ratio, max_ratio) and returns: ratio, int, int, max_ratio