Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big/small tall/short modification #894

Merged
merged 30 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bfaa041
passing unit tests for big/small/short/tall
paynesa Jul 9, 2020
efb84aa
biggest axis determination
paynesa Jul 9, 2020
20402a7
relative size perception
paynesa Jul 9, 2020
878ad04
fix small error
paynesa Jul 9, 2020
6374323
add relations and attributes to perception and test
paynesa Jul 9, 2020
812d31d
update relation learning
paynesa Jul 9, 2020
c7b2874
chinese language generator is updated
paynesa Jul 9, 2020
ce06d67
update complete; todo = test learning
paynesa Jul 10, 2020
0f7683a
fix learning tests
paynesa Jul 10, 2020
0eaac0e
Merge branch 'master' into learn-imprecise-description
paynesa Jul 16, 2020
ae66a97
rebase
paynesa Jul 16, 2020
6cdeb46
update comment removal
paynesa Jul 16, 2020
773ad28
remove unused args
paynesa Jul 17, 2020
1c9e801
remove more unused arguments
paynesa Jul 17, 2020
cb1447f
added special edge type
denizbeser Aug 6, 2020
46dcfb4
add gaze to curricula
paynesa Aug 10, 2020
046f42d
skip a few tests temporarily to rebase and pass CI
paynesa Aug 10, 2020
5395ba4
Merge branch 'master' into learn-imprecise-description
paynesa Aug 10, 2020
5e3f299
fix imports to pass pylint
paynesa Aug 10, 2020
947d8c2
issue found; temporary hackish fix to do with ordering of gaze vs. no…
paynesa Aug 10, 2020
1bd6893
sort from low to high graph complexity when matching candidate object…
paynesa Aug 10, 2020
0a93dce
remove print/debug statements
paynesa Aug 10, 2020
94387c4
add back in verb learner to integrated learner
paynesa Aug 10, 2020
2f89445
add back in verb learner to integrated learner
paynesa Aug 10, 2020
3627eb2
add bool flag so that only sort in object recognizer rather than obje…
paynesa Aug 10, 2020
9e191c6
update perception tests based on new edge implemented by Deniz
paynesa Aug 10, 2020
4ba80aa
remove debug and commented code
paynesa Aug 13, 2020
22aa52e
kwargs 1
paynesa Aug 13, 2020
02fc988
kwargs 2
paynesa Aug 13, 2020
460a2ad
re-enable relative-to-learner size
paynesa Aug 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 154 additions & 87 deletions adam/curriculum/imprecise_descriptions_curriculum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from itertools import chain
from typing import Sequence, Optional
from typing import Sequence, Optional, Iterable
from immutablecollections import immutableset
from more_itertools import flatten
from adam.language.language_generator import LanguageGenerator
from adam.language.dependency import LinearizedDependencyTree
from adam.ontology import OntologyNode
from adam.curriculum.curriculum_utils import (
Phase1InstanceGroup,
PHASE1_CHOOSER_FACTORY,
Expand All @@ -12,6 +13,9 @@
learner_template_factory,
make_noise_objects,
)
from adam.language_specific import MASS_NOUN
from adam.language.dependency.universal_dependencies import NOUN
from adam.ontology.phase2_ontology import gravitationally_aligned_axis_is_largest
from adam.ontology import IS_SPEAKER, IS_ADDRESSEE
from adam.curriculum.phase1_curriculum import (
make_pass_template,
Expand All @@ -34,7 +38,6 @@
)
from adam.language_specific.english.english_language_generator import (
USE_ADVERBIAL_PATH_MODIFIER,
USE_VERTICAL_MODIFIERS,
)
from adam.ontology import THING
from adam.ontology.phase1_ontology import (
Expand Down Expand Up @@ -68,6 +71,8 @@
TABLE,
THEME,
SPIN,
HEAD,
HAND,
)
from adam.situation import Action, SituationObject
from adam.situation.high_level_semantics_situation import HighLevelSemanticsSituation
Expand All @@ -76,72 +81,30 @@
TemplateObjectVariable,
Phase1SituationTemplate,
)
from adam.language_specific.english.english_phase_1_lexicon import (
GAILA_PHASE_1_ENGLISH_LEXICON,
)

BOOL_SET = immutableset([True, False])


def _big_x_template(
theme: TemplateObjectVariable, noise_objects: Optional[int]
) -> Phase1SituationTemplate:
learner = learner_template_factory()
computed_background = [learner]
computed_background.extend(make_noise_objects(noise_objects))
return Phase1SituationTemplate(
f"big-{theme.handle}",
salient_object_variables=[theme],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(theme, learner)],
)


def _little_x_template(
theme: TemplateObjectVariable, noise_objects: Optional[int]
) -> Phase1SituationTemplate:
learner = learner_template_factory()
computed_background = [learner]
computed_background.extend(make_noise_objects(noise_objects))
return Phase1SituationTemplate(
f"small-{theme.handle}",
salient_object_variables=[theme],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(learner, theme)],
)


def _tall_x_template(
theme: TemplateObjectVariable, noise_objects: Optional[int]
) -> Phase1SituationTemplate:
learner = learner_template_factory()
computed_background = [learner]
computed_background.extend(make_noise_objects(noise_objects))

# TODO: This difference should be an axis size but we can't yet
# implement that. See: https://github.com/isi-vista/adam/issues/832
return Phase1SituationTemplate(
f"tall-{theme.handle}",
salient_object_variables=[theme],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(theme, learner)],
syntax_hints=[USE_VERTICAL_MODIFIERS],
)


def _short_x_template(
theme: TemplateObjectVariable, noise_objects: Optional[int]
) -> Phase1SituationTemplate:
learner = learner_template_factory()
computed_background = [learner]
computed_background.extend(make_noise_objects(noise_objects))

# TODO: This difference should be an axis size but we can't yet
# implement that. See: https://github.com/isi-vista/adam/issues/832
return Phase1SituationTemplate(
f"tall-{theme.handle}",
salient_object_variables=[theme],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(learner, theme)],
syntax_hints=[USE_VERTICAL_MODIFIERS],
)
# easy hack to get all nouns that aren't recognized particulars, body parts, or mass nouns -- i.e. the ones that can be big or small
NODES_TO_CHOOSE_FROM = [
x[0]
for x in GAILA_PHASE_1_ENGLISH_LEXICON._ontology_node_to_word.items() # pylint:disable=protected-access
if x[1].part_of_speech in [NOUN]
and MASS_NOUN not in x[1].properties
and x[0] not in [BABY, HEAD, HAND]
]
# differentiate between the nodes that can be modified with tall and those that can't
TALL_ELIGIBLE_NODES = [
node
for node in NODES_TO_CHOOSE_FROM
if gravitationally_aligned_axis_is_largest(node, GAILA_PHASE_1_ONTOLOGY)
]
BIG_ELIGIBLE_NODES = [
node for node in NODES_TO_CHOOSE_FROM if node not in TALL_ELIGIBLE_NODES
]
CHOOSER = PHASE1_CHOOSER_FACTORY()


def make_eat_big_small_curriculum( # pylint: disable=unused-argument
Expand Down Expand Up @@ -170,7 +133,12 @@ def make_eat_big_small_curriculum( # pylint: disable=unused-argument
for _object in [COOKIE, WATERMELON]:
object_to_eat = SituationObject.instantiate_ontology_node(
ontology_node=_object,
debug_handle=_object.handle,
debug_handle=_object.handle + "_salient",
ontology=GAILA_PHASE_1_ONTOLOGY,
)
object_to_eat2 = SituationObject.instantiate_ontology_node(
ontology_node=_object,
debug_handle=_object.handle + "_non_salient",
ontology=GAILA_PHASE_1_ONTOLOGY,
)
other_edibles = [
Expand All @@ -183,15 +151,16 @@ def make_eat_big_small_curriculum( # pylint: disable=unused-argument
]
computed_background = [learner]
computed_background.extend(other_edibles)
computed_background.extend([object_to_eat2])

# Big
for relation_list in [
[
bigger_than(object_to_eat, learner),
bigger_than(object_to_eat, object_to_eat2),
bigger_than(object_to_eat, other_edibles),
],
[
bigger_than(learner, object_to_eat),
bigger_than(object_to_eat2, object_to_eat),
bigger_than(other_edibles, object_to_eat),
],
]:
Expand All @@ -218,9 +187,82 @@ def make_eat_big_small_curriculum( # pylint: disable=unused-argument
)


# TODO: Refactor this curriculum
# See: https://github.com/isi-vista/adam/issues/898
def make_spin_tall_short_curriculum( # pylint: disable=unused-argument
def _tall_x_template(
background: Iterable[TemplateObjectVariable],
random_node: OntologyNode = CHOOSER.choice(TALL_ELIGIBLE_NODES),
) -> Phase1SituationTemplate:
# hack to pick a random node that will yield "tall"
theme1 = standard_object("theme1", random_node)
theme2 = standard_object("theme2", random_node)
computed_background = [theme2]
computed_background.extend(background)
return Phase1SituationTemplate(
f"tall-{theme1.handle}",
salient_object_variables=[theme1],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(theme1, theme2)],
gazed_objects=[theme1],
)


def _big_x_template(
background: Iterable[TemplateObjectVariable],
random_node: OntologyNode = CHOOSER.choice(BIG_ELIGIBLE_NODES),
) -> Phase1SituationTemplate:
# hack to pick a random node that will yield "big"
theme1 = standard_object("theme1", random_node)
theme2 = standard_object("theme2", random_node)
computed_background = [theme2, learner_template_factory()]
computed_background.extend(background)
return Phase1SituationTemplate(
f"big-{theme1.handle}",
salient_object_variables=[theme1],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(theme1, theme2)],
gazed_objects=[theme1],
)


def _little_x_template(
background: Iterable[TemplateObjectVariable],
random_node: OntologyNode = CHOOSER.choice(BIG_ELIGIBLE_NODES),
) -> Phase1SituationTemplate:
# hack to pick a random node that will yield "little"
theme1 = standard_object("theme1", random_node)
theme2 = standard_object("theme2", random_node)
computed_background = [theme2]
computed_background.extend(background)
return Phase1SituationTemplate(
f"little-{theme1.handle}",
salient_object_variables=[theme1],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(theme2, theme1)],
gazed_objects=[theme1],
)


def _short_x_template(
background: Iterable[TemplateObjectVariable],
random_node: OntologyNode = CHOOSER.choice(TALL_ELIGIBLE_NODES),
) -> Phase1SituationTemplate:
# hack to pick a random node that will yield "short"
theme1 = standard_object("theme1", random_node)
theme2 = standard_object("theme2", random_node)
computed_background = [theme2]
computed_background.extend(background)
return Phase1SituationTemplate(
f"short-{theme1.handle}",
salient_object_variables=[theme1],
background_object_variables=computed_background,
asserted_always_relations=[bigger_than(theme2, theme1)],
gazed_objects=[theme1],
)


def make_spin_tall_short_curriculum(
# TODO: Refactor this curriculum
# See: https://github.com/isi-vista/adam/issues/898
# pylint: disable=unused-argument
num_samples: Optional[int],
noise_objects: Optional[int],
language_generator: LanguageGenerator[
Expand All @@ -245,7 +287,12 @@ def make_spin_tall_short_curriculum( # pylint: disable=unused-argument
for _object in [CHAIR, TABLE]:
theme = SituationObject.instantiate_ontology_node(
ontology_node=_object,
debug_handle=_object.handle,
debug_handle=_object.handle + "_salient",
ontology=GAILA_PHASE_1_ONTOLOGY,
)
theme2 = SituationObject.instantiate_ontology_node(
ontology_node=_object,
debug_handle=_object.handle + "_non_salient",
ontology=GAILA_PHASE_1_ONTOLOGY,
)
other_objs = [
Expand All @@ -258,11 +305,12 @@ def make_spin_tall_short_curriculum( # pylint: disable=unused-argument
]
computed_background = [learner]
computed_background.extend(other_objs)
computed_background.extend([theme2])

# Tall and short
for relation_list in [
[bigger_than(learner, theme), bigger_than(other_objs, theme)],
[bigger_than(theme, learner), bigger_than(theme, other_objs)],
[bigger_than(theme2, theme), bigger_than(other_objs, theme)],
[bigger_than(theme, theme2), bigger_than(theme, other_objs)],
]:
situations.append(
HighLevelSemanticsSituation(
Expand All @@ -279,7 +327,6 @@ def make_spin_tall_short_curriculum( # pylint: disable=unused-argument
)
],
always_relations=relation_list,
syntax_hints=[USE_VERTICAL_MODIFIERS],
)
)

Expand All @@ -295,31 +342,51 @@ def make_imprecise_size_descriptions(
HighLevelSemanticsSituation, LinearizedDependencyTree
],
) -> Phase1InstanceGroup:
theme_0 = standard_object("theme", banned_properties=[IS_SPEAKER, IS_ADDRESSEE])
theme_1 = standard_object(
"theme-thing", THING, banned_properties=[IS_SPEAKER, IS_ADDRESSEE]
# we choose random tall and short nodes here
random_tall_nodes = (
[CHOOSER.choice(TALL_ELIGIBLE_NODES) for i in range(num_samples)]
if num_samples
else [CHOOSER.choice(TALL_ELIGIBLE_NODES) for i in range(5)]
)
random_big_nodes = (
[CHOOSER.choice(BIG_ELIGIBLE_NODES) for i in range(num_samples)]
if num_samples
else [CHOOSER.choice(BIG_ELIGIBLE_NODES) for i in range(5)]
)

background = make_noise_objects(noise_objects)

return phase1_instances(
"Imprecise Size",
chain(
flatten(
# generate big and small for all eligible nodes
[
sampled(
template(theme, noise_objects),
template(random_node=node, background=background),
ontology=GAILA_PHASE_1_ONTOLOGY,
chooser=PHASE1_CHOOSER_FACTORY(),
block_multiple_of_the_same_type=False,
max_to_sample=num_samples if num_samples else 5,
)
for template in [
_big_x_template,
_little_x_template,
_tall_x_template,
_short_x_template,
]
for theme in [theme_0, theme_1]
for node in random_big_nodes
for template in [_big_x_template, _little_x_template]
]
)
),
flatten(
# generate tall and short for all eligible nodes
[
sampled(
template(random_node=node, background=background),
ontology=GAILA_PHASE_1_ONTOLOGY,
chooser=PHASE1_CHOOSER_FACTORY(),
max_to_sample=1,
block_multiple_of_the_same_type=False,
)
for node in random_tall_nodes
for template in [_tall_x_template, _short_x_template]
]
),
),
language_generator=language_generator,
)
Expand Down
Loading