def _make_drink_cups_curriculum( num_samples: Optional[int], noise_objects: Optional[int], language_generator: LanguageGenerator[ HighLevelSemanticsSituation, LinearizedDependencyTree ], ) -> Phase1InstanceGroup: templates = [] for cup in [CUP, CUP_2, CUP_3, CUP_4]: cup_obj = standard_object("cup", cup) liquid_0 = object_variable("liquid_0", required_properties=[LIQUID]) person_0 = standard_object( "person_0", PERSON, banned_properties=[IS_SPEAKER, IS_ADDRESSEE] ) templates.append( Phase1SituationTemplate( "drink-cup", salient_object_variables=[liquid_0, person_0, cup_obj], background_object_variables=make_noise_objects(noise_objects), actions=[ Action( DRINK, argument_roles_to_fillers=[(AGENT, person_0), (THEME, liquid_0)], auxiliary_variable_bindings=[(DRINK_CONTAINER_AUX, cup_obj)], ) ], asserted_always_relations=[inside(liquid_0, cup_obj)], ) ) return phase2_instances( "drink - cup", chain( *[ sampled( cup_template, chooser=PHASE1_CHOOSER_FACTORY(), ontology=GAILA_PHASE_2_ONTOLOGY, max_to_sample=num_samples, block_multiple_of_the_same_type=True, ) if num_samples else all_possible( cup_template, chooser=PHASE1_CHOOSER_FACTORY(), ontology=GAILA_PHASE_2_ONTOLOGY, ) for cup_template in templates ] ), perception_generator=GAILA_PHASE_2_PERCEPTION_GENERATOR, language_generator=language_generator, )
def _make_sit_on_chair_curriculum( num_samples: Optional[int], noise_objects: Optional[int], language_generator: LanguageGenerator[ HighLevelSemanticsSituation, LinearizedDependencyTree ], ) -> Phase1InstanceGroup: templates = [] for chair_type in [CHAIR, CHAIR_2, CHAIR_3, CHAIR_4, CHAIR_5]: sitter = standard_object( "sitter_0", THING, required_properties=[ANIMATE], banned_properties=[IS_SPEAKER, IS_ADDRESSEE], ) seat = standard_object("chair", chair_type) templates.append( make_sit_transitive( sitter, seat, noise_objects, surface=False, syntax_hints=False ) ) templates.append( make_sit_template_intransitive( sitter, seat, noise_objects, surface=False, syntax_hints=False ) ) return phase2_instances( "sit on chair", chain( *[ sampled( template, chooser=PHASE1_CHOOSER_FACTORY(), ontology=GAILA_PHASE_2_ONTOLOGY, max_to_sample=num_samples, block_multiple_of_the_same_type=True, ) if num_samples else all_possible( template, chooser=PHASE1_CHOOSER_FACTORY(), ontology=GAILA_PHASE_2_ONTOLOGY, ) for template in templates ] ), perception_generator=GAILA_PHASE_2_PERCEPTION_GENERATOR, language_generator=language_generator, )
def _prepositional_relation_described_curriculum( max_to_sample: int, noise_objects_sets: Iterable[Iterable[TemplateObjectVariable]], *, min_noise_relations: int = 0, max_noise_relations: int = 0, add_noise: bool, chooser: RandomChooser, samples_to_template_den: int = 1, block_multiple_of_same_type: bool, language_generator: LanguageGenerator[ HighLevelSemanticsSituation, LinearizedDependencyTree ], include_targets_in_noise: bool = False, min_samples: int = 6, ) -> Phase1InstanceGroup: target_1 = standard_object( "target_1", THING, required_properties=[INTEGRATED_EXPERIMENT_PROP] ) target_2 = standard_object( "target_2", THING, required_properties=[INTEGRATED_EXPERIMENT_PROP] ) target_with_object_on = standard_object( "target with object on", INANIMATE_OBJECT, required_properties=[INTEGRATED_EXPERIMENT_PROP, CAN_HAVE_THINGS_RESTING_ON_THEM], ) templates = ( [ _on_template( target_1, target_with_object_on, background_objects, is_training=True, background_relations=background_relations_builder( background_objects, num_relations, target=target_1, target_2=target_with_object_on, include_targets_in_noise=include_targets_in_noise, ), ) for background_objects in noise_objects_sets for num_relations in range(min_noise_relations, max_noise_relations) ] if add_noise else [ _on_template( target_1, target_with_object_on, immutableset(), is_training=True ) ] ) templates.extend( [ _beside_template( target_1, target_2, background_objects, is_right=is_right, is_training=True, background_relations=background_relations_builder( background_objects, num_relations, target=target_1, target_2=target_2, include_targets_in_noise=include_targets_in_noise, ), ) for is_right in BOOL_SET for background_objects in noise_objects_sets for num_relations in range(min_noise_relations, max_noise_relations) ] if add_noise else [ _beside_template( target_1, target_2, immutableset(), is_right=is_right, is_training=True ) for is_right in BOOL_SET ] ) templates.extend( [ _behind_template( target_1, target_2, background_objects, is_near=is_near, is_training=True, background_relations=background_relations_builder( background_objects, num_relations, target=target_1, target_2=target_2, include_targets_in_noise=include_targets_in_noise, ), ) for is_near in BOOL_SET for background_objects in noise_objects_sets for num_relations in range(min_noise_relations, max_noise_relations) ] if add_noise else [ _behind_template( target_1, target_2, immutableset(), is_near=is_near, is_training=True ) for is_near in BOOL_SET ] ) templates.extend( [ _in_front_template( target_1, target_2, background_objects, is_near=is_near, is_training=True, background_relations=background_relations_builder( background_objects, num_relations, target=target_1, target_2=target_2, include_targets_in_noise=include_targets_in_noise, ), ) for is_near in BOOL_SET for background_objects in noise_objects_sets for num_relations in range(min_noise_relations, max_noise_relations) ] if add_noise else [ _in_front_template( target_1, target_2, immutableset(), is_near=is_near, is_training=True ) for is_near in BOOL_SET ] ) return phase2_instances( "Prepositional Relation", flatten( [ sampled( template, ontology=INTEGRATED_EXPERIMENT_ONTOLOGY, chooser=chooser, max_to_sample=max( math.ceil(max_to_sample / samples_to_template_den), min_samples ), block_multiple_of_the_same_type=block_multiple_of_same_type, ) for template in templates ] ), language_generator=language_generator, perception_generator=INTEGRATED_EXPERIMENT_PERCEPTION_GENERATOR, )
def _single_attribute_described_curriculum( max_to_sample: int, target_color_objects: Iterable[TemplateObjectVariable], noise_objects_sets: Iterable[Iterable[TemplateObjectVariable]], *, min_noise_relations: int = 0, max_noise_relations: int = 0, add_noise: bool, chooser: RandomChooser, samples_to_template_den: int = 1, block_multiple_of_same_type: bool, language_generator: LanguageGenerator[ HighLevelSemanticsSituation, LinearizedDependencyTree ], include_targets_in_noise: bool = False, min_samples: int = 6, ) -> Phase1InstanceGroup: def object_with_color( target_with_color: TemplateObjectVariable, *, background_objects: Iterable[TemplateObjectVariable] = immutableset(), background_relations: Iterable[Relation[Any]] = immutableset(), ) -> Phase1SituationTemplate: return Phase1SituationTemplate( name=f"single-attribute-color-{target_with_color.handle}", salient_object_variables=[target_with_color], background_object_variables=background_objects if add_noise else immutableset(), asserted_always_relations=background_relations if add_noise else immutableset(), ) templates = ( [ object_with_color( target_object, background_objects=background_objects, background_relations=background_relations_builder( background_objects, num_relations, target=target_object, include_targets_in_noise=include_targets_in_noise, ), ) for target_object in target_color_objects for background_objects in noise_objects_sets for num_relations in range(min_noise_relations, max_noise_relations) ] if add_noise else [object_with_color(target_object) for target_object in target_color_objects] ) return phase2_instances( "Single Attribute", flatten( [ sampled( template, ontology=INTEGRATED_EXPERIMENT_ONTOLOGY, chooser=chooser, max_to_sample=max( math.ceil(max_to_sample / samples_to_template_den), min_samples ), block_multiple_of_the_same_type=block_multiple_of_same_type, ) for template in templates ] ), language_generator=language_generator, perception_generator=INTEGRATED_EXPERIMENT_PERCEPTION_GENERATOR, )