• Stars
    star
    158
  • Rank 237,131 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Framework for learning dialogue agents in a two-player game setting.

CoCoA (Collaborative Communicating Agents)

CoCoA is a dialogue framework written in Python, providing tools for data collection through a text-based chat interface and model development in PyTorch (largely based on OpenNMT).

This repo contains code for the following tasks:

  • MutualFriends: two agents, each with a private list of friends with multiple attributes (e.g. school, company), try to find their mutual friends through a conversation.
  • CraigslistBargain: a buyer and a seller negotiate the price of an item for sale on Craigslist.
  • DealOrNoDeal: two agents negotiate to split a group of items with different points among them. The items are books, hats and balls.

Papers:

Note: We have not fully integrated the MutualFriends task with the cocoa package. For now please refer to the mutualfriends branch for the ACL 2017 paper.


Installation

Dependencies: Python 2.7, PyTorch 0.4.1.

NOTE: MutualFriends still depends on Tensorflow 1.2 and uses different leanring modules. See details on the mutualfriends branch.

pip install -r requirements.txt
python setup.py develop

Main concepts/classes

Schema and scenarios

A dialogue is grounded in a scenario. A schema defines the structure of scenarios. For example, a simple scenario that specifies the dialogue topic is

Topic
Artificial Intelligence

and its schema (in JSON) is

{
    "attributes": [
        "value_type": "topic",
        "name": "Topic"
    ]
}

Systems and sessions

A dialogue agent is instantiated in a session which receives and sends messages. A system is used to create multiple sessions (that may run in parallel) of a specific agent type. For example, system = NeuralSystem(model) loads a trained model and system.new_session() is called to create a new session whenever a human user is available to chat.

Events and controllers

A dialogue controller takes two sessions and have them send/receive events until the task is finished or terminated. The most common event is message, which sends some text data. There are also task-related events, such as select in MutualFriends, which sends the selected item.

Examples and datasets

A dialogue is represented as an example which has a scenario, a series of events, and some metadata (e.g. example id). Examples can be read from / write to a JSON file in the following structure:

examples.json
|--[i]
|  |--"uuid": "<uuid>"
|  |--"scenario_uuid": "<uuid>"
|  |--"scenario": "{scenario dict}"
|  |--"agents": {0: "agent type", 1: "agent type"}
|  |--"outcome": {"reward": R}
|  |--"events"
|     |--[j]
|        |--"action": "action"
|        |--"data": "event data"
|        |--"agent": agent_id
|        |--"time": "event sent time"

A dataset reads in training and testing examples from JSON files.

Code organization

CoCoA is designed to be modular so that one can add their own task/modules easily. All tasks depend on the cocoa pacakge. See documentation in the task folder for task-specific details.

Data collection

We provide basic infrastructure (see cocoa.web) to set up a website that pairs two users or a user and a bot to chat in a given scenario.

Generate scenarios

The first step is to create a .json schema file and then (randomly) generate a set of scenarios that the dialogue will be situated in.

Setup the web server

The website pairs a user with another user or a bot (if available). A dialogue scenario is displayed and the two agents can chat with each other. Users are then directed to a survey to rate their partners (optional). All dialogue events are logged in a SQL database.

Our server is built by Flask. The backend (cocoa/web/main/backend.py) contains code for pairing, logging, dialogue quality check. The frontend code is in task/web/templates.

To deploy the web server, run

cd <name-of-your-task>;
PYTHONPATH=. python web/chat_app.py --port <port> --config web/app_params.json --schema-path <path-to-schema> --scenarios-path <path-to-scenarios> --output <output-dir>
  • Data and log will be saved in <output-dir>. Important: note that this will delete everything in <output-dir> if it's not empty.
  • --num-scenarios: total number of scenarios to sample from. Each scenario will have num_HITs / num_scenarios chats. You can also specify ratios of number of chats for each system in the config file. Note that the final result will be an approximation of these numbers due to concurrent database calls.

To collect data from Amazon Mechanical Turk (AMT), workers should be directed to the link http://your-url:<port>/?mturk=1. ?mturk=1 makes sure that workers will receive a Mturk code at the end of the task to submit the HIT.

Dump the database

Dump data from the SQL database to a JSON file (see Examples and datasets for the JSON structure).

cd <name-of-your-task>;
PYTHONPATH=. python ../scripts/web/dump_db.py --db <output-dir>/chat_state.db --output <output-dir>/transcripts/transcripts.json --surveys <output-dir>/transcripts/surveys.json --schema <path-to-schema> --scenarios-path <path-to-scenarios> 

Render JSON transcript to HTML:

PYTHONPATH=. python ../scripts/visualize_transcripts.py --dialogue-transcripts <path-to-json-transcript> --html-output <path-to-output-html-file> --css-file ../chat_viewer/css/my.css

Other options for HTML visualization:

  • --survey-transcripts: path to survey.json if survey is enabled during data collection.
  • --survey-only: only visualize dialgoues with submitted surveys.
  • --summary: statistics of the dialogues.

Dialogue agents

To add an agent for a task, you need to implement a system <name-of-your-task>/systems/<agent-name>_system.py and a session <name-of-your-task>/sessions/<agent-name>_session.py.

Model training and testing

See documentation in the under each task (e.g., ./craigslistbargain).

Evaluation

To deploy bots to the web interface, add the "models" field in the website config file, e.g.

"models": {
    "rulebased": {
        "active": true,
        "type": "rulebased",
    }
}

See also set up the web server.

More Repositories

1

dspy

DSPy: The framework for programming—not prompting—foundation models
Python
18,220
star
2

CoreNLP

CoreNLP: A Java suite of core NLP tools for tokenization, sentence segmentation, NER, parsing, coreference, sentiment analysis, etc.
Java
9,678
star
3

stanza

Stanford NLP Python library for tokenization, sentence segmentation, NER, and parsing of many human languages
Python
7,278
star
4

GloVe

Software in C and data files for the popular GloVe model for distributed word representations, a.k.a. word vectors or embeddings
C
6,867
star
5

cs224n-winter17-notes

Course notes for CS224N Winter17
TeX
1,587
star
6

pyreft

ReFT: Representation Finetuning for Language Models
Python
1,137
star
7

treelstm

Tree-structured Long Short-Term Memory networks (http://arxiv.org/abs/1503.00075)
Lua
875
star
8

pyvene

Stanford NLP Python Library for Understanding and Improving PyTorch Models via Interventions
Python
625
star
9

string2string

String-to-String Algorithms for Natural Language Processing
Jupyter Notebook
533
star
10

python-stanford-corenlp

Python interface to CoreNLP using a bidirectional server-client interface.
Python
516
star
11

mac-network

Implementation for the paper "Compositional Attention Networks for Machine Reasoning" (Hudson and Manning, ICLR 2018)
Python
494
star
12

phrasal

A large-scale statistical machine translation system written in Java.
Java
208
star
13

spinn

SPINN (Stack-augmented Parser-Interpreter Neural Network): fast, batchable, context-aware TreeRNNs
Python
205
star
14

coqa-baselines

The baselines used in the CoQA paper
Python
176
star
15

stanza-old

Stanford NLP group's shared Python tools.
Python
138
star
16

chirpycardinal

Stanford's Alexa Prize socialbot
Python
131
star
17

stanfordnlp

[Deprecated] This library has been renamed to "Stanza". Latest development at: https://github.com/stanfordnlp/stanza
Python
114
star
18

wge

Workflow-Guided Exploration: sample-efficient RL agent for web tasks
Python
109
star
19

pdf-struct

Logical structure analysis for visually structured documents
Python
81
star
20

edu-convokit

Edu-ConvoKit: An Open-Source Framework for Education Conversation Data
Jupyter Notebook
75
star
21

cs224n-web

http://cs224n.stanford.edu
HTML
60
star
22

ColBERT-QA

Code for Relevance-guided Supervision for OpenQA with ColBERT (TACL'21)
40
star
23

stanza-train

Model training tutorials for the Stanza Python NLP Library
Python
37
star
24

phrasenode

Mapping natural language commands to web elements
Python
37
star
25

contract-nli-bert

A baseline system for ContractNLI (https://stanfordnlp.github.io/contract-nli/)
Python
29
star
26

color-describer

Code for Learning to Generate Compositional Color Descriptions
OpenEdge ABL
26
star
27

stanza-resources

23
star
28

python-corenlp-protobuf

Python bindings for Stanford CoreNLP's protobufs.
Python
20
star
29

miniwob-plusplus-demos

Demos for the MiniWoB++ benchmark
17
star
30

multi-distribution-retrieval

Code for our paper Resources and Evaluations for Multi-Distribution Dense Information Retrieval
Python
14
star
31

huggingface-models

Scripts for pushing models to huggingface repos
Python
11
star
32

nlp-meetup-demo

Java
8
star
33

sentiment-treebank

Updated version of SST
Python
8
star
34

en-worldwide-newswire

An English NER dataset built from foreign newswire
Python
7
star
35

plot-data

datasets for plotting
Jupyter Notebook
6
star
36

contract-nli

ContractNLI: A Dataset for Document-level Natural Language Inference for Contracts
HTML
4
star
37

plot-interface

Web interface for the plotting project
JavaScript
3
star
38

handparsed-treebank

Extra hand parsed data for training models
Perl
2
star
39

coqa

CoQA -- A Conversational Question Answering Challenge
Shell
2
star
40

pdf-struct-models

A repository for hosting models for https://github.com/stanfordnlp/pdf-struct
HTML
2
star
41

chirpy-parlai-blenderbot-fork

A fork of ParlAI supporting Chirpy Cardinal's custom neural generator
Python
2
star
42

wob-data

Data for QAWoB and FlightWoB web interaction benchmarks from the World of Bits paper (Shi et al., 2017).
Python
2
star
43

pdf-struct-dataset

Dataset for pdf-struct (https://github.com/stanfordnlp/pdf-struct)
HTML
1
star
44

nn-depparser

A re-implementation of nndep using PyTorch.
Python
1
star