src/prost/prost.py
def build_examples_from_config(config, variables, product=True,
                               remove_duplicates=True):
  """Construct Test cases for a task.

  Args:
    config: raw dictionary configurary read in from scenario yml file.
    variables: global and scenario lexicons.
  Returns:
    Formatted examples for the provided template
  """
  # get answer key function, prep evs
  expect_fn = globals()[config.pop('expect_fn')]
  enum_variables = T.itemmap(lambda x: make_enum_vars(*x), variables)
  logging.debug('variables: %s, ev: %s', variables, enum_variables)

  # find keys for the template
  template = copy.deepcopy(config)
  template.update(template.pop('choices'))
  all_keys = find_all_keys(template)

  # build value sets for the template
  # fillin_items: {lexicon: <values>, }
  fillin_items = _get_fillin_items(all_keys, **variables)
  fillin_values = ensure_listlike(list(fillin_items.values()))
  val_sets = (itertools.product if product else zip)(*fillin_values)

  # remove all sets with duplicate values and restructure
  if remove_duplicates:
    val_sets = T.filter(lambda x: len(set(x)) == len(x), val_sets)

  # restructure as var -> value maps
  mappings = T.map(lambda vals: dict(zip(list(fillin_items), vals)), val_sets)

  def generate_example(mapping):
    data = recursive_format(template, mapping)
    example = {**data, 'label': expect_fn(data, mapping, ev=enum_variables)}
    # Capitilize first word.
    for k in ('context', 'question', 'ex_question'):
      example[k] = example[k][0].upper() + example[k][1:]
    return example

  examples = list(T.map(generate_example, mappings))
  logging.debug('Built %d from task %s', len(examples), config['name'])
  return examples
Construct Test cases for a task.

  Args:
    config: raw dictionary configurary read in from scenario yml file.
    variables: global and scenario lexicons.
  Returns:
    Formatted examples for the provided template
  
Construct Test cases for a task.
Construct Test cases for a task .
def build_examples_from_config(config, variables, product=True,
                               remove_duplicates=True):
  expect_fn = globals()[config.pop('expect_fn')]
  enum_variables = T.itemmap(lambda x: make_enum_vars(*x), variables)
  logging.debug('variables: %s, ev: %s', variables, enum_variables)
  template = copy.deepcopy(config)
  template.update(template.pop('choices'))
  all_keys = find_all_keys(template)
  fillin_items = _get_fillin_items(all_keys, **variables)
  fillin_values = ensure_listlike(list(fillin_items.values()))
  val_sets = (itertools.product if product else zip)(*fillin_values)
  if remove_duplicates:
    val_sets = T.filter(lambda x: len(set(x)) == len(x), val_sets)
  mappings = T.map(lambda vals: dict(zip(list(fillin_items), vals)), val_sets)
  def generate_example(mapping):
    data = recursive_format(template, mapping)
    example = {**data, 'label': expect_fn(data, mapping, ev=enum_variables)}
    for k in ('context', 'question', 'ex_question'):
      example[k] = example[k][0].upper() + example[k][1:]
    return example
  examples = list(T.map(generate_example, mappings))
  logging.debug('Built %d from task %s', len(examples), config['name'])
  return examples
def build_examples_from_config ( config , variables , product = True , remove_duplicates = True ) : expect_fn = globals ( ) [ config . pop ( 'expect_fn' ) ] enum_variables = T . itemmap ( lambda x : make_enum_vars ( * x ) , variables ) logging . debug ( 'variables: %s, ev: %s' , variables , enum_variables ) template = copy . deepcopy ( config ) template . update ( template . pop ( 'choices' ) ) all_keys = find_all_keys ( template ) fillin_items = _get_fillin_items ( all_keys , ** variables ) fillin_values = ensure_listlike ( list ( fillin_items . values ( ) ) ) val_sets = ( itertools . product if product else zip ) ( * fillin_values ) if remove_duplicates : val_sets = T . filter ( lambda x : len ( set ( x ) ) == len ( x ) , val_sets ) mappings = T . map ( lambda vals : dict ( zip ( list ( fillin_items ) , vals ) ) , val_sets ) def generate_example ( mapping ) : data = recursive_format ( template , mapping ) example = { ** data , 'label' : expect_fn ( data , mapping , ev = enum_variables ) } for k in ( 'context' , 'question' , 'ex_question' ) : example [ k ] = example [ k ] [ 0 ] . upper ( ) + example [ k ] [ 1 : ] return example examples = list ( T . map ( generate_example , mappings ) ) logging . debug ( 'Built %d from task %s' , len ( examples ) , config [ 'name' ] ) return examples
Construct Test cases for a task.
Construct Test cases for a task .
"""Construct Test cases for a task.

  Args:
    config: raw dictionary configurary read in from scenario yml file.
    variables: global and scenario lexicons.
  Returns:
    Formatted examples for the provided template
  """ # get answer key function, prep evs # find keys for the template # build value sets for the template # fillin_items: {lexicon: <values>, } # remove all sets with duplicate values and restructure # restructure as var -> value maps # Capitilize first word.
Formatted examples for the provided template
Formatted examples for the provided template
config
raw dictionary configurary read in from scenario yml file.
raw dictionary configurary read in from scenario yml file .
variables
global and scenario lexicons.
global and scenario lexicons .
product
remove_duplicates