Skip to content

Instantly share code, notes, and snippets.

@dwaligora
Last active August 29, 2015 14:11
Show Gist options
  • Save dwaligora/a01f64a04b01d88bbe4e to your computer and use it in GitHub Desktop.
Save dwaligora/a01f64a04b01d88bbe4e to your computer and use it in GitHub Desktop.

Interface between miniBrain and Orchestrator

Date: 2014-11-10
Author: Daniel Waligora

There are two types of methods:

  • Cache methods
  • Interactive methods

Cache methods are called once per session to retrieve additional information. This information does not require to be sent back to the server or synced again during the session. Example for such data would be an allowed word list for a project. As long as the initial input data does not change, the word list does not change.

Interactive methods are methods that change the state on the client, e.g. querying for new tweets to be labeled by the user.

Cache methods

Allowed Word List

POST /allowed_word_list 

Purpose

Fetches the allowed word list for a given project. The data is used to validate on the fly the input of the user. E.g.: User assigns a word to a label, only words in the list are allowed to be entered.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
wordlist list Yes Returns a set of strings. Strings can contain anything, including whitespace, quotes, tabs and UTF-8.

Examples

** Request**

POST /allowed_word_list -d '{"project_id":8}'

** Response**

{
    "wordlist": [
        "picked",
        "random",
        "description",
        "other"
    ]
}

Label List

POST /labels

Purpose

Get all unique labels associated with the project.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
labels list yes set of strings

Examples

** Request**

POST /labels -d '{"project_id":8}'

** Response**

{
    "labels": [
        "rave",
        "rant",
        "other"
    ]
}

Word Co-occurrence Matrix

POST /word_co_occurence_matrix

Purpose

In order to show the number of interactions satisfied by word-to-label associations a word co-occurence matrix is needed. The matrix uses a Bag-of-Word representation.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
word string yes unique word
document-ids list yes list of interaction IDs; not necessarily .interaction.id but a miniBrain-created unique ID. Type of the ID: int

Examples

** Request**

POST /word_co_occurence -d '{"project_id":8}'

** Response**

{
    "awesome": [
        8,
        9,
        10,
        28
    ],
    "awful": [
        8,
        28,
        39,
        40
    ],
    "amazing": [
        8,
        9,
        10,
        28,
        49,
        100
    ]
}

Interactive Methods

WhatsNext

POST /whats_next

Purpose

Submits the current changes made by the user and simultaneously requests a new command with the necessary data to execute the command on the client. The client knows how to interpret the command but cannot determine what the next step is by itself.

Input Parameters

Name Type required Description
project_id int Yes
tweet_labels list No List of tweet-ids with the user-labeled label
word_labels list No List of labels with words

Output Parameters

Name Type required Description
command string Yes one pre-defined command. Dictates what the user interface/user should do. Possible Commands:
tweets list No List of tweets needing labeling
word_labels list No List of labels with words

Examples

** Request**

POST /whats_next -d '{"project_id":8}'

** Response**

{"command":"annotate_words"}

** Request**

POST /whats_next -d '{"project_id":8}'

** Response**

{
    "command": "annotate_tweets",
    "tweets": [
        {
            "id": 8,
            "content": "I love you"
        },
        {
            "id": 9,
            "content": "I hate you guys"
        }
    ]
}

** Request**

POST /whats_next -d '{"project_id":8}'

** Response**

{
    "command": "annotate_tweets",
    "tweets": [
        {
            "id": 8,
            "content": "I love you"
        },
        {
            "id": 9,
            "content": "I hate you guys"
        }
    ],
    "word_labels": {
        "rave": [
            "amazing",
            "awesome",
            "best"
        ],
        "rant": [
            "terrible",
            "horrible",
            "dumb"
        ],
        "other": [
            "flight",
            "blah",
            "from"
        ]
    }
}

** Request**

POST /whats_next -d '{"project_id":8,"tweet_labels":{"8":"rave","9":"rave","100":"rant","80":"other"}}'

** Response**

{
    "command": "annotate_tweets",
    "tweets": [
        {
            "id": 8,
            "content": "I love you"
        },
        {
            "id": 9,
            "content": "I hate you guys"
        }
    ],
    "word_labels": {
        "rave": [
            "amazing",
            "awesome",
            "best"
        ],
        "rant": [
            "terrible",
            "horrible",
            "dumb"
        ],
        "other": [
            "flight",
            "blah",
            "from"
        ]
    }
}

** Request**

POST /whats_next -d '{"project_id":8,"tweet_labels":{"8":"rave","9":"rave","100":"rant","80":"other"},"word_labels":{"rave":["amazing"],"rant":["awful"],"other":["so"]}}'

** Response**

{
    "command": "annotate_tweets",
    "tweets": [
        {
            "id": 8,
            "content": "I love you"
        },
        {
            "id": 9,
            "content": "I hate you guys"
        }
    ]
}

Start

POST /start

Purpose

Project sessions need to be started and a slot assigned. This is initially done syncroniously. If no error occurs, HTTP code 200 is returned. Otherwise a json object containing an error description is returned.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
error string no An error message is returned if no slot is available or another problem occured.

Examples

** Request**

POST /start -d '{"project_id":8}'

** Response**

{}

** Request**

POST /start -d '{"project_id":8}'

** Response**

{"error":"no slot available"}

Submit to Brain

POST /submit_to_brain

Purpose

Automatically uploads the work done by the user up to this poitn to the brain and schedules a job on the brain. The job itself is run asynchronously but the final job id of the brain can be returned immediately.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
job_id string yes Job id of the brain job

Examples

** Request**

POST /submit_to_brain -d '{"project_id":8}'

** Response**

{"job_id":"a983f"}

Download Work

POST /download_work

Purpose

Download the work of the user by merging the initially uploaded file and the labels provided by the user for the interactions. Removes unlabeled data. Additionally adds the word-to-label associations, independently of the interactions.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
url string yes S3 filename pointing to a valid interaction file.

Examples

** Request**

POST /download_work -d '{"project_id":8}'

** Response**

{"url":"3983983_labeled_file"}

Get Predictions

POST /predictions

Purpose

Retrieve label predictions and confidences for the currently unlabeled interactions.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
id string yes interaction ID; not necessarily .interaction.id but a miniBrain-created unique ID
label string yes one of the user created labels. Must be included in /labels
confidence double yes Real number [0,1]
content string yes .interaction.content of the predicted interaction

Examples

** Request**

POST /predictions -d '{"project_id":8}'

** Response**

[
    {
        "id": "a39db",
        "label": "rave",
        "confidence": 0.8894,
        "content": "Awesome."
    },
    {
        "id": "a38db",
        "label": "rant",
        "confidence": 0.3894,
        "content": "This is shit"
    }
]

Save

POST /save

Purpose

Save the state of the minibrain. If no error occurs, HTTP code 200 is returned.

Input Parameters

Name Type required Description
project_id int Yes

Output Parameters

Name Type required Description
error string no An error message is returned if no slot is available or another problem occured.

Examples

** Request**

POST /save -d '{"project_id":8}'

** Response**

{}

**Request **

POST /save -d '{"project_id":8}'

** Response **

{"error":"write permission denied"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment