diff --git a/parlai/tasks/casino/LICENSE_DOCUMENTATION b/parlai/tasks/casino/LICENSE_DOCUMENTATION new file mode 100644 index 00000000000..10fabd90118 --- /dev/null +++ b/parlai/tasks/casino/LICENSE_DOCUMENTATION @@ -0,0 +1,395 @@ +Attribution 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + +======================================================================= + +Creative Commons Attribution 4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution 4.0 International Public License ("Public License"). To the +extent this Public License may be interpreted as a contract, You are +granted the Licensed Rights in consideration of Your acceptance of +these terms and conditions, and the Licensor grants You such rights in +consideration of benefits the Licensor receives from making the +Licensed Material available under these terms and conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Adapter's License means the license You apply to Your Copyright + and Similar Rights in Your contributions to Adapted Material in + accordance with the terms and conditions of this Public License. + + c. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + d. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + e. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + f. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + g. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + h. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + i. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + j. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + k. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part; and + + b. produce, reproduce, and Share Adapted Material. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material (including in modified + form), You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + 4. If You Share Adapted Material You produce, the Adapter's + License You apply must not prevent recipients of the Adapted + Material from complying with this Public License. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material; and + + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + + +======================================================================= + +Creative Commons is not a party to its public licenses. +Notwithstanding, Creative Commons may elect to apply one of its public +licenses to material it publishes and in those instances will be +considered the “Licensor.” The text of the Creative Commons public +licenses is dedicated to the public domain under the CC0 Public Domain +Dedication. Except for the limited purpose of indicating that material +is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the public +licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/parlai/tasks/casino/README.md b/parlai/tasks/casino/README.md new file mode 100644 index 00000000000..c0b7ff435bd --- /dev/null +++ b/parlai/tasks/casino/README.md @@ -0,0 +1,25 @@ +Task: CampSite Negotiation Dialogue (CaSiNo) +====================== + +**Description** + +We provide a novel dataset (referred to as CaSiNo) of 1030 negotiation dialogues. Two participants take the role of campsite neighbors and negotiate for Food, Water, and Firewood packages, based on their individual preferences and requirements. This design keeps the task tractable, while still facilitating linguistically rich and personal conversations. This helps to overcome the limitations of prior negotiation datasets such as Deal or No Deal and Craigslist Bargain. Each dialogue consists of rich meta-data including participant demographics, personality, and their subjective evaluation of the negotiation in terms of satisfaction and opponent likeness. + +**Citation** +``` +@inproceedings{chawla2021casino, + title={CaSiNo: A Corpus of Campsite Negotiation Dialogues for Automatic Negotiation Systems}, + author={Chawla, Kushal and Ramirez, Jaysa and Clever, Rene and Lucas, Gale and May, Jonathan and Gratch, Jonathan}, + booktitle={Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies}, + pages={3167--3185}, + year={2021} +} +``` + +LICENSE: This dataset has been released under the CC-BY-4.0 License. Please refer to the LICENSE_DOCUMENTATION file in this repository for more information. + +Dataset Homepage: https://github.com/kushalchawla/CaSiNo + +NAACL 2021 Paper: https://aclanthology.org/2021.naacl-main.254.pdf + +Tags: #CaSiNo, #All, #Negotiation \ No newline at end of file diff --git a/parlai/tasks/casino/__init__.py b/parlai/tasks/casino/__init__.py new file mode 100644 index 00000000000..240697e3247 --- /dev/null +++ b/parlai/tasks/casino/__init__.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. diff --git a/parlai/tasks/casino/agents.py b/parlai/tasks/casino/agents.py new file mode 100644 index 00000000000..99a4a747509 --- /dev/null +++ b/parlai/tasks/casino/agents.py @@ -0,0 +1,335 @@ +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +from parlai.core.teachers import Teacher +from .build import build +from parlai.utils.io import PathManager +import json +import os +import random +import copy + +WELCOME_MESSAGE = "Negotiate with your opponent to decide who gets how many items of each kind. There are three kinds of packages: Food, Water, and Firewood. Each has a quantity of 3. Try hard to get as much value as you can, while still leaving your partner satisfied and with a positive perception about you. If you fail to come to an agreement, both parties get 5 points. Refer to the following preference order and arguments for your negotiation: \n\nFood\nValue: {food_val} points for each package\nArgument: {food_argument}\n\nWater\nValue: {water_val} points for each package\nArgument: {water_argument}\n\nFirewood\nValue: {firewood_val} points for each package\nArgument: {firewood_argument}\n" + + +def get_welcome_values(part_info): + + value2points = {'High': 5, 'Medium': 4, 'Low': 3} + + issue2points = {v: value2points[k] for k, v in part_info['value2issue'].items()} + issue2reason = { + v: part_info['value2reason'][k] for k, v in part_info['value2issue'].items() + } + + welcome_values = {} + for issue in ['Food', 'Water', 'Firewood']: + welcome_values[issue.lower() + '_val'] = issue2points[issue] + welcome_values[issue.lower() + '_argument'] = issue2reason[issue] + + return welcome_values + + +def get_utterance_text(utterance): + + if utterance['text'] == '': + return '' + + # the utterance is not a dummy one at this point + if utterance['text'] != 'Submit-Deal': + # simply return it + return utterance['text'] + + # if it is a Submit-Deal -> attach task_data + txt = f"{utterance['text']} What I get- Food:{utterance['task_data']['issue2youget']['Food']}, Water: {utterance['task_data']['issue2youget']['Water']}, Firewood: {utterance['task_data']['issue2youget']['Firewood']}; What you get- Food:{utterance['task_data']['issue2theyget']['Food']}, Water: {utterance['task_data']['issue2theyget']['Water']}, Firewood: {utterance['task_data']['issue2theyget']['Firewood']}" + + return txt + + +class CasinoTeacher(Teacher): + """ + A negotiation teacher that loads the CaSiNo data from https://github.com/kushalchawla/CaSiNo. + + Each dialogue is converted into two datapoints, one from the perspective of each participant. + """ + + def __init__(self, opt, shared=None): + super().__init__(opt, shared) + self.datatype = opt['datatype'].split(':')[0] + self.datatype_ = opt['datatype'] + self.random = self.datatype_ == 'train' + build(opt) + + filename = self.datatype + data_path = os.path.join( + opt['datapath'], 'casino', 'casino_' + filename + '.json' + ) + + if shared and 'data' in shared: + self.episodes = shared['episodes'] + else: + self._setup_data(data_path) + print(f"Total episodes: {self.num_episodes()}") + + # for ordered data in batch mode (especially, for validation and + # testing), each teacher in the batch gets a start index and a step + # size so they all process disparate sets of the data + self.step_size = opt.get('batchsize', 1) + self.data_offset = opt.get('batchindex', 0) + + self.reset() + + def _setup_data(self, data_path): + print('loading: ' + data_path) + with PathManager.open(data_path) as data_file: + dialogues = json.load(data_file) + + episodes = [] + for dialogue in dialogues: + + # divide the dialogue into two perspectives, one for each participant + episode = copy.deepcopy(dialogue) + episode[ + 'perspective' + ] = ( + 'mturk_agent_1' + ) # id of the agent whose perspective will be used in this dialog + episodes.append(episode) + + episode = copy.deepcopy(dialogue) + episode[ + 'perspective' + ] = ( + 'mturk_agent_2' + ) # id of the agent whose perspective will be used in this dialog + episodes.append(episode) + + self.episodes = episodes + + # add dummy data to ensure that every chat begins with a teacher utterance (THEM) and ends at the agent's utterance (YOU). This is done for uniformity while parsing the data. It makes the code simpler and easier to read than DealNoDeal counterpart. + for ix, episode in enumerate(self.episodes): + + chat_logs = episode['chat_logs'] + perspective = episode['perspective'] + + if chat_logs[0]['id'] == perspective: + # chat must start with a teacher; add dummy utterance + dummy_utterance = { + 'text': '', + 'task_data': {}, + 'id': 'mturk_agent_1' + if perspective == 'mturk_agent_2' + else 'mturk_agent_2', + } + + chat_logs = [dummy_utterance] + chat_logs + + if chat_logs[-1]['id'] != perspective: + # chat must end with the agent; add dummy utterance + dummy_utterance = { + 'text': '', + 'task_data': {}, + 'id': 'mturk_agent_1' + if perspective == 'mturk_agent_1' + else 'mturk_agent_2', + } + + chat_logs = chat_logs + [dummy_utterance] + + self.episodes[ix]['chat_logs'] = chat_logs + + def reset(self): + super().reset() + self.episode_idx = self.data_offset - self.step_size + self.dialogue_idx = None + self.perspective = None + self.dialogue = None + self.output = None + self.expected_response = None + self.epochDone = False + + def num_examples(self): + """ + Lets return the the number of responses that an agent would generate in one epoch + 1 count for every output. This will include special utterances for submit-deal, accept-deal, and reject-deal. + + """ + num_exs = 0 + + for episode in self.episodes: + + for utt in episode['chat_logs']: + if utt['text'] != '': + # skip the dummy utterances + num_exs += 1 + + return (num_exs // 2) + len( + self.episodes + ) # since each dialogue was converted into 2 perspectives, one for each participant: see _setup_data + + def num_episodes(self): + return len(self.episodes) + + def share(self): + shared = super().share() + shared['episodes'] = self.episodes + return shared + + def observe(self, observation): + """ + Process observation for metrics. + """ + if self.expected_response is not None: + self.metrics.evaluate_response(observation, self.expected_response) + self.expected_response = None + return observation + + def act(self): + if self.dialogue_idx is not None: + # continue existing conversation + return self._continue_dialogue() + elif self.random: + # if random, then select the next random example + self.episode_idx = random.randrange(len(self.episodes)) + return self._start_dialogue() + elif self.episode_idx + self.step_size >= len(self.episodes): + # end of examples + self.epochDone = True + return {'episode_done': True} + else: + # get next non-random example + self.episode_idx = (self.episode_idx + self.step_size) % len(self.episodes) + return self._start_dialogue() + + def _start_dialogue(self): + """ + Starting a dialogue should be the same as continuing a dialogue but with just one difference: it will attach the welcome note to the teacher's utterance. + + Each dialogue has two agents possible: mturk_agent_1 or mturk_agent_2. One of them will act as the perspective for this episode. + """ + + episode = self.episodes[self.episode_idx] + self.perspective = episode['perspective'] + self.other_id = ( + 'mturk_agent_1' if self.perspective == 'mturk_agent_2' else 'mturk_agent_2' + ) + + part_info = episode['participant_info'][self.perspective] + part_info_other = episode['participant_info'][self.other_id] + + welcome_values = get_welcome_values(part_info) + welcome = WELCOME_MESSAGE.format( + food_val=welcome_values['food_val'], + water_val=welcome_values['water_val'], + firewood_val=welcome_values['firewood_val'], + food_argument=welcome_values['food_argument'], + water_argument=welcome_values['water_argument'], + firewood_argument=welcome_values['firewood_argument'], + ) + + self.dialogue = episode['chat_logs'] + self.output = { + 'your_points_scored': part_info['outcomes']['points_scored'], + 'how_satisfied_is_your_partner': part_info_other['outcomes'][ + 'satisfaction' + ], + 'how_much_does_your_partner_like_you': part_info_other['outcomes'][ + 'opponent_likeness' + ], + } + + self.dialogue_idx = -1 + + action = self._continue_dialogue() + if action['text']: + # This is non-empty; meaning the teacher starts the conversation and has something to say. + action['text'] = f"{welcome}\n{action['text']}" + else: + # text is empty, meaning that the teacher did not start the conversation but the empty string is just a result of the dummy teacher utterance added in _setup_data + action['text'] = welcome + + action['meta-info'] = welcome_values + + return action + + def _continue_dialogue(self): + """ + Return an action object + + From the perspective of a specific agent's id, all utterances authored by the other agent are coming from the teacher as the text of the action object, and all utterances authored by this agent appear as the labels. + """ + action = {} + # Fill in teacher's message (THEM) + self.dialogue_idx += 1 + if self.dialogue_idx < len(self.dialogue): + # this is a usual dialogue teacher-agent pair; return the teacher's utterance as action text. + utterance = self.dialogue[self.dialogue_idx] + assert utterance['id'] != self.perspective + utterance_text = get_utterance_text( + utterance + ) # will take care of special submit-deal utterance and dummy utterances + action['text'] = utterance_text + + if action['text'] == 'Reject-Deal': + # merge with the next dialogue_idx since that is from the same participant while this code assumes alternative utterances. + self.dialogue_idx += 1 # we know that this will be valid + utterance = self.dialogue[self.dialogue_idx] + assert utterance['id'] != self.perspective + utterance_text = get_utterance_text( + utterance + ) # will take care of special submit-deal utterance and dummy utterances + action['text'] = action['text'] + ' ' + utterance_text + else: + # the primary dialogue is over; now is the time to return the output of this dialogue + action[ + 'text' + ] = f"Your points scored: {self.output['your_points_scored']}, How satisfied is your partner: {self.output['how_satisfied_is_your_partner']}, How much does your partner like you: {self.output['how_much_does_your_partner_like_you']}" + + # Fill in learner's response (YOU) + self.dialogue_idx += 1 + self.expected_response = None + if self.dialogue_idx < len(self.dialogue): + # usual dialogue going on; return the agent's utterance as the labels + utterance = self.dialogue[self.dialogue_idx] + assert ( + utterance['id'] == self.perspective + ), f"id: {utterance['id']}, perspect: {self.perspective}" + utterance_text1 = get_utterance_text( + utterance + ) # will take care of special submit-deal utterance and dummy utterances + + utterance_text2 = '' + if utterance_text1 == 'Reject-Deal': + # merge with the next dialogue_idx since that is from the same participant while this code assumes alternative utterances. + self.dialogue_idx += 1 # we know that this will be valid + utterance = self.dialogue[self.dialogue_idx] + assert utterance['id'] == self.perspective + utterance_text2 = get_utterance_text( + utterance + ) # will take care of special submit-deal utterance and dummy utterances + + self.expected_response = ( + [utterance_text1 + ' ' + utterance_text2] + if (utterance_text1 + ' ' + utterance_text2).strip() + else None + ) + else: + # no label required when the primary dialogue is complete + pass + + if self.expected_response: + # since labels is automatically renamed to eval_labels for valid/test, doing just this takes care of everything. Ensures that labels can atleast be accessed regardless of the datatype. + action['labels'] = self.expected_response + + if self.dialogue_idx >= len(self.dialogue): + self.dialogue_idx = None + action['episode_done'] = True + else: + action['episode_done'] = False + + return action + + +class DefaultTeacher(CasinoTeacher): + pass diff --git a/parlai/tasks/casino/build.py b/parlai/tasks/casino/build.py new file mode 100644 index 00000000000..36ee71bfd5f --- /dev/null +++ b/parlai/tasks/casino/build.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +from parlai.core.build_data import DownloadableFile +import parlai.core.build_data as build_data +import os + +RESOURCES = [ + DownloadableFile( + 'https://raw.githubusercontent.com/kushalchawla/CaSiNo/main/data/split/casino_train.json', + 'casino_train.json', + '6b953d153fc8c78f27e911c1439b93b9b3519357e3ba825091b2e567845ba3a7', + zipped=False, + ), + DownloadableFile( + 'https://raw.githubusercontent.com/kushalchawla/CaSiNo/main/data/split/casino_valid.json', + 'casino_valid.json', + '91f2d1f09accedf98667ac081fd5083752738390734e991601b036643da077e0', + zipped=False, + ), + DownloadableFile( + 'https://raw.githubusercontent.com/kushalchawla/CaSiNo/main/data/split/casino_test.json', + 'casino_test.json', + 'bf6da2d7c105396300d85a65819c04d99304ac9abb8a590ba342fd0c86b4dd12', + zipped=False, + ), +] + + +def build(opt): + dpath = os.path.join(opt['datapath'], 'casino') + version = "v1.1" + + if not build_data.built(dpath, version_string=version): + print('[building data: ' + dpath + ']') + + # make a clean directory if needed + if build_data.built(dpath): + # an older version exists, so remove these outdated files. + build_data.remove_dir(dpath) + build_data.make_dir(dpath) + + # Download the data. + for downloadable_file in RESOURCES: + downloadable_file.download_file(dpath) + + # Mark as done + build_data.mark_done(dpath, version_string=version) diff --git a/parlai/tasks/casino/test.py b/parlai/tasks/casino/test.py new file mode 100644 index 00000000000..28ffa4018b5 --- /dev/null +++ b/parlai/tasks/casino/test.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +# Copyright (c) Facebook, Inc. and its affiliates. +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +from parlai.utils.testing import AutoTeacherTest # noqa: F401 + + +class TestDefaultTeacher(AutoTeacherTest): + task = 'casino' diff --git a/parlai/tasks/casino/test/casino_test.yml b/parlai/tasks/casino/test/casino_test.yml new file mode 100644 index 00000000000..87e3b8fa8a0 --- /dev/null +++ b/parlai/tasks/casino/test/casino_test.yml @@ -0,0 +1,46 @@ +acts: +- - episode_done: false + labels: + - 'hello, that could be a good idea, but I think I need more rations ' + meta-info: + firewood_argument: to cook and stay warm. + firewood_val: 3 + food_argument: because I am diabetic. I need to eat small many meals + food_val: 4 + water_argument: 'to stay hydrated, I will need more water because I need to + stay hydrated, If I don''t I will faint. ' + water_val: 5 + text: "Negotiate with your opponent to decide who gets how many items of each\ + \ kind. There are three kinds of packages: Food, Water, and Firewood. Each has\ + \ a quantity of 3. Try hard to get as much value as you can, while still leaving\ + \ your partner satisfied and with a positive perception about you. If you fail\ + \ to come to an agreement, both parties get 5 points. Refer to the following\ + \ preference order and arguments for your negotiation: \n\nFood\nValue: 4 points\ + \ for each package\nArgument: because I am diabetic. I need to eat small many\ + \ meals\n\nWater\nValue: 5 points for each package\nArgument: to stay hydrated,\ + \ I will need more water because I need to stay hydrated, If I don't I will\ + \ faint. \n\nFirewood\nValue: 3 points for each package\nArgument: to cook and\ + \ stay warm.\n\nHi we would like you to consider giving us all of the rations\ + \ for the trip." +- - episode_done: false + labels: + - 'I need more food and water, you see I am diabetic, I need to eat many small + meals ' + text: How important are they to you? We would like to get a good mix, preferably + more food. +- - episode_done: false + labels: + - 'let me have two food and three parts of water, I can let you have all the firewood + and one fpart food ' + text: 😡 I can let the firewood and water lax if you provide us food. +- - episode_done: false + labels: + - '😡my type of diabetes needs many meals otherwise my insulin levels will be low ' + text: We do have a fire to start, but we are very hungry. Diabetics can eat less + food because of the small meals. Don't lie to me. +- - episode_done: false + labels: + - 'your type maybe needs wild fruits which you can easily gather🙂 ' + text: I am diabetic also. +num_episodes: 200 +num_examples: 1594 diff --git a/parlai/tasks/casino/test/casino_train.yml b/parlai/tasks/casino/test/casino_train.yml new file mode 100644 index 00000000000..59f1de639f8 --- /dev/null +++ b/parlai/tasks/casino/test/casino_train.yml @@ -0,0 +1,51 @@ +acts: +- - episode_done: false + labels: + - 'Hello!, how are you doing? ' + meta-info: + firewood_argument: It gets cold at night where I am going camping, so I will + need additional firewood + firewood_val: 5 + food_argument: I am going with a big family and any extra food will be helpful. + food_val: 4 + water_argument: It is hot and dry during the day and I don't want to be dehydrated. + water_val: 3 + text: "Negotiate with your opponent to decide who gets how many items of each\ + \ kind. There are three kinds of packages: Food, Water, and Firewood. Each has\ + \ a quantity of 3. Try hard to get as much value as you can, while still leaving\ + \ your partner satisfied and with a positive perception about you. If you fail\ + \ to come to an agreement, both parties get 5 points. Refer to the following\ + \ preference order and arguments for your negotiation: \n\nFood\nValue: 4 points\ + \ for each package\nArgument: I am going with a big family and any extra food\ + \ will be helpful.\n\nWater\nValue: 3 points for each package\nArgument: It\ + \ is hot and dry during the day and I don't want to be dehydrated.\n\nFirewood\n\ + Value: 5 points for each package\nArgument: It gets cold at night where I am\ + \ going camping, so I will need additional firewood\n" +- - episode_done: false + labels: + - '🙂 super!, ... so you are going camping too? ' + text: I'm good - and you? +- - episode_done: false + labels: + - 'oh, I''m sorry to hear about that... I think I can help with the water, but + you need firewood as well? ' + text: Yep - I'm hoping you can help me out here. I've just finished my last round + of chemo and really need to flush my systm out. I'd love it if I could take + all 3 waters and 1 firewood. You can have the rest. +- - episode_done: false + labels: + - 'The reason I am asking, is because it gets very cold in the desert at night...and + I may need that... but if all you need is one, I don''t see why we couldn''t + make a deal ' + text: Well, just one would be beneficial. I don't regulate my body heat as much + as I used to. +- - episode_done: false + labels: + - 'Once again, really sad to hear about your condition☹️..., but perhaps being + in the great outdoors would be beneficial for your immune system?😮... So you + need 3 water and 1 firewood? ' + text: that would be amazing - I know it does get cold so I definitely don't want + you to be cold either. I don't need any of the food - not much of an appetite + right now anyway. +num_episodes: 1800 +num_examples: 14301 diff --git a/parlai/tasks/casino/test/casino_valid.yml b/parlai/tasks/casino/test/casino_valid.yml new file mode 100644 index 00000000000..c0cb02a2b0c --- /dev/null +++ b/parlai/tasks/casino/test/casino_valid.yml @@ -0,0 +1,52 @@ +acts: +- - episode_done: false + labels: + - 'Hello there! Are you getting excited for your upcoming trip?! I am so very + excited to test my skills! ' + meta-info: + firewood_argument: It is the rainy season where I am traveling, so the abundance + of dry firewood to scavenge for is slim. + firewood_val: 5 + food_argument: Due to the rainy season there has been a disease go through the + vegetation in the area, so I would like to be prepared in case the same has + happened where I am going. + food_val: 4 + water_argument: There is a lot of rain water I can collect and boil down that + is safe to drink. + water_val: 3 + text: "Negotiate with your opponent to decide who gets how many items of each\ + \ kind. There are three kinds of packages: Food, Water, and Firewood. Each has\ + \ a quantity of 3. Try hard to get as much value as you can, while still leaving\ + \ your partner satisfied and with a positive perception about you. If you fail\ + \ to come to an agreement, both parties get 5 points. Refer to the following\ + \ preference order and arguments for your negotiation: \n\nFood\nValue: 4 points\ + \ for each package\nArgument: Due to the rainy season there has been a disease\ + \ go through the vegetation in the area, so I would like to be prepared in case\ + \ the same has happened where I am going.\n\nWater\nValue: 3 points for each\ + \ package\nArgument: There is a lot of rain water I can collect and boil down\ + \ that is safe to drink.\n\nFirewood\nValue: 5 points for each package\nArgument:\ + \ It is the rainy season where I am traveling, so the abundance of dry firewood\ + \ to scavenge for is slim.\n" +- - episode_done: false + labels: + - 'Great! Have you checked to see what the weather has been like in the area you + are going to?? ' + text: Hi friend! I'm very excited to go to the trip +- - episode_done: false + labels: + - 'I have checked and see that it is in the rainy season! I know I need to pack + some extra firewood if you can spare me some?? ' + text: Definitely I will checked. I m eager to prepare each & every things for + the trip +- - episode_done: false + labels: + - 'Great! Can I take 2 and you can have 1?? I am willing to give you 2 of the + water then! ' + text: yes. I will definitely give you. I bring extra woods. +- - episode_done: false + labels: + - 'I suppose I could do that. I am worried a disease has possibly spread to the + area due to the very wet weather, but I can sure fish for most of my food then! ' + text: Its pleasure to me. Will you give food extra 1 to me? +num_episodes: 60 +num_examples: 462 diff --git a/parlai/tasks/task_list.py b/parlai/tasks/task_list.py index 52a9e25da17..295986ccb5d 100644 --- a/parlai/tasks/task_list.py +++ b/parlai/tasks/task_list.py @@ -1452,4 +1452,17 @@ "or the set of valid actions from the text descriptions of the world." ), }, + { + "id": "CaSiNo", + "display_name": "CaSiNo (CampSite Negotiation Dialogues)", + "task": "casino", + "tags": ["Negotiation"], + "description": ( + "A dataset of 1030 negotiation dialogues. Two participants take the role of campsite neighbors and negotiate for Food, Water, and Firewood packages, based on their individual preferences and requirements." + ), + "links": { + "paper": "https://aclanthology.org/2021.naacl-main.254.pdf", + "website": "https://github.com/kushalchawla/CaSiNo", + }, + }, ]