File size: 5,275 Bytes
d4c443d 9aeddde b81abb3 9aeddde b81abb3 9aeddde c58a472 ebc812a 9aeddde 8dc5742 9aeddde b81abb3 9aeddde b81abb3 9aeddde b81abb3 9aeddde 84751cd 9aeddde b81abb3 ebc812a 0430397 b81abb3 ebc812a 0430397 9aeddde |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import json
import datasets
import os
from PIL import Image
from numpy import asarray
_CITATION = """\
@inproceedings{gao-etal-2018-action,
title = "What Action Causes This? Towards Naive Physical Action-Effect Prediction",
author = "Gao, Qiaozi and
Yang, Shaohua and
Chai, Joyce and
Vanderwende, Lucy",
booktitle = "Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = jul,
year = "2018",
address = "Melbourne, Australia",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/P18-1086",
doi = "10.18653/v1/P18-1086",
pages = "934--945",
}
"""
_DESCRIPTION = """\
Despite recent advances in knowledge representation, automated reasoning, and machine learning, artificial agents still lack the ability to understand basic action-effect relations regarding the physical world, for example, the action of cutting a cucumber most likely leads to the state where the cucumber is broken apart into smaller pieces. If artificial agents (e.g., robots) ever become our partners in joint tasks, it is critical to empower them with such action-effect understanding so that they can reason about the state of the world and plan for actions. Towards this goal, this paper introduces a new task on naive physical action-effect prediction, which addresses the relations between concrete actions (expressed in the form of verb-noun pairs) and their effects on the state of the physical world as depicted by images. We collected a dataset for this task and developed an approach that harnesses web image data through distant supervision to facilitate learning for action-effect prediction. Our empirical results have shown that web data can be used to complement a small number of seed examples (e.g., three examples for each action) for model learning. This opens up possibilities for agents to learn physical action-effect relations for tasks at hand through communication with humans with a few examples.
"""
_URL = "https://huggingface.co/datasets/sled-umich/Action-Effect"
JSON_URL = "http://162.212.153.129/action_effect_info.json"
IMGS_URL = "action_effect_image_rs.tar.gz"
class Action_Effect(datasets.GeneratorBasedBuilder):
"""
What Action Causes This? Towards Naive Physical Action-Effect Prediction
"""
VERSION = datasets.Version("1.0.0")
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"verb noun": datasets.Value("string"),
"effect_sentence_list": datasets.features.Sequence(datasets.Value("string")),
"effect_phrases_list": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
"positive_image_list": datasets.features.Sequence(datasets.Value("string")),
"negative_image_list": datasets.features.Sequence(datasets.Value("string")),
# "positive_image_list": datasets.features.Sequence(datasets.Image()),
# "negative_image_list": datasets.features.Sequence(datasets.Image()),
}
),
homepage=_URL,
citation=_CITATION,
)
def _split_generators(self, dl_manager: datasets.DownloadManager):
[action_effect_info_path, img_zip_path] = dl_manager.download_and_extract([JSON_URL, IMGS_URL])
# print(dl_dir)
# action_effect_info_path = dl_dir[0] + "/action_effect_info.json"
# img_zip_path = dl_dir[1] + "/action_effect_image_rs.tar.gz"
return [
datasets.SplitGenerator(
name= "ActionEffect",
gen_kwargs={
"action_effect_info_path": action_effect_info_path, "img_zip_path": img_zip_path
},
)
]
def _generate_examples(self, action_effect_info_path, img_zip_path):
with open(action_effect_info_path) as f:
action_effect_info = json.load(f)
# img_zip = tarfile.open(img_zip_path)
img_root = img_zip_path+ "/action_effect_image_rs/"
for idx, this_ae_info in enumerate(action_effect_info):
this_ae_info['positive_image_list'] = []
this_ae_info['negative_image_list'] = []
vn = this_ae_info["verb noun"]
this_image_root_positive = img_root + vn.replace(" ", "+") + "/positive/"
this_image_root_negative = img_root + vn.replace(" ", "+") + "/positive/"
for img_name in os.listdir(this_image_root_positive):
img_np = this_image_root_positive + img_name
# img_pil = Image.open(this_image_root_positive + img_name)
# img_np = asarray(img_pil)
this_ae_info["positive_image_list"].append(img_np)
for img_name in os.listdir(this_image_root_negative):
# img_pil = Image.open(this_image_root_negative + img_name)
# img_np = asarray(img_pil)
img_np = this_image_root_negative + img_name
this_ae_info["negative_image_list"].append(img_np)
yield idx, this_ae_info
|