{"action":"created","comment":{"url":"https://api.github.com/repos/allenai/allennlp/pulls/comments/178324713","pull_request_review_id":108373240,"id":178324713,"diff_hunk":"@@ -0,0 +1,129 @@\n+from typing import Dict, Union, Set\n+import logging\n+\n+from collections import defaultdict\n+from overrides import overrides\n+import torch\n+from torch.autograd import Variable\n+\n+from allennlp.data.fields.field import Field\n+from allennlp.data.vocabulary import Vocabulary\n+from allennlp.common.checks import ConfigurationError\n+\n+logger = logging.getLogger(__name__)  # pylint: disable=invalid-name\n+\n+\n+class MultiLabelField(Field[torch.Tensor]):\n+    \"\"\"\n+    A ``MultiLabelField`` is an extension of the :class:`LabelField` that allows for multiple labels.\n+    It is particularly useful in multi-label classification where more than one label can be correct.\n+    As with the :class:`LabelField`, labels are either strings of text or 0-indexed integers (if you wish\n+    to skip indexing by passing skip_indexing=True).\n+    If the labels need indexing, we will use a :class:`Vocabulary` to convert the string labels\n+    into integers.\n+\n+    This field will get converted into a vector of length equals the vocabulary size with\n+    one hot encoding for the labels (all zeros, and ones for the labels).\n+\n+    Parameters\n+    ----------\n+    labels : ``Set[Union[str, int]]``\n+    label_namespace : ``str``, optional (default=\"labels\")\n+        The namespace to use for converting label strings into integers.  We map label strings to\n+        integers for you (e.g., \"entailment\" and \"contradiction\" get converted to 0, 1, ...),\n+        and this namespace tells the ``Vocabulary`` object which mapping from strings to integers\n+        to use (so \"entailment\" as a label doesn't get the same integer id as \"entailment\" as a\n+        word).  If you have multiple different label fields in your data, you should make sure you\n+        use different namespaces for each one, always using the suffix \"labels\" (e.g.,\n+        \"passage_labels\" and \"question_labels\").\n+    skip_indexing : ``bool``, optional (default=False)\n+        If your labels are 0-indexed integers, you can pass in this flag, and we'll skip the indexing\n+        step.  If this is ``False`` and your labels are not strings, this throws a ``ConfigurationError``.\n+    \"\"\"\n+    # It is possible that users want to use this field with a namespace which uses OOV/PAD tokens.\n+    # This warning will be repeated for every instantiation of this class (i.e for every data\n+    # instance), spewing a lot of warnings so this class variable is used to only log a single\n+    # warning per namespace.\n+    _already_warned_namespaces: Set[str] = set()\n+\n+    # Dictionary from a vocab namespace to size. Need the vocab size to map labels to a tensor\n+    _vocab_size: Dict[str, int] = defaultdict(int)\n+\n+    def __init__(self,\n+                 labels: Set[Union[str, int]],","path":"allennlp/data/fields/multilabel_field.py","position":53,"original_position":53,"commit_id":"934e3e870d043f839d0227c59a337be072e0ab23","original_commit_id":"8f576a74d9ecf5fc817a0ca9c9f303fc400e58d6","user":{"login":"joelgrus","id":1308313,"avatar_url":"https://avatars1.githubusercontent.com/u/1308313?v=4","gravatar_id":"","url":"https://api.github.com/users/joelgrus","html_url":"https://github.com/joelgrus","followers_url":"https://api.github.com/users/joelgrus/followers","following_url":"https://api.github.com/users/joelgrus/following{/other_user}","gists_url":"https://api.github.com/users/joelgrus/gists{/gist_id}","starred_url":"https://api.github.com/users/joelgrus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelgrus/subscriptions","organizations_url":"https://api.github.com/users/joelgrus/orgs","repos_url":"https://api.github.com/users/joelgrus/repos","events_url":"https://api.github.com/users/joelgrus/events{/privacy}","received_events_url":"https://api.github.com/users/joelgrus/received_events","type":"User","site_admin":false},"body":"I think this should be `Sequence` not `Set`, so that it type-checks to pass in a list (as you do in some places)","created_at":"2018-03-30T16:41:18Z","updated_at":"2018-03-30T16:55:14Z","html_url":"https://github.com/allenai/allennlp/pull/1054#discussion_r178324713","pull_request_url":"https://api.github.com/repos/allenai/allennlp/pulls/1054","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/comments/178324713"},"html":{"href":"https://github.com/allenai/allennlp/pull/1054#discussion_r178324713"},"pull_request":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1054"}}},"pull_request":{"url":"https://api.github.com/repos/allenai/allennlp/pulls/1054","id":178592230,"html_url":"https://github.com/allenai/allennlp/pull/1054","diff_url":"https://github.com/allenai/allennlp/pull/1054.diff","patch_url":"https://github.com/allenai/allennlp/pull/1054.patch","issue_url":"https://api.github.com/repos/allenai/allennlp/issues/1054","number":1054,"state":"open","locked":false,"title":"Add a multilabel field","user":{"login":"ibeltagy","id":2287797,"avatar_url":"https://avatars0.githubusercontent.com/u/2287797?v=4","gravatar_id":"","url":"https://api.github.com/users/ibeltagy","html_url":"https://github.com/ibeltagy","followers_url":"https://api.github.com/users/ibeltagy/followers","following_url":"https://api.github.com/users/ibeltagy/following{/other_user}","gists_url":"https://api.github.com/users/ibeltagy/gists{/gist_id}","starred_url":"https://api.github.com/users/ibeltagy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibeltagy/subscriptions","organizations_url":"https://api.github.com/users/ibeltagy/orgs","repos_url":"https://api.github.com/users/ibeltagy/repos","events_url":"https://api.github.com/users/ibeltagy/events{/privacy}","received_events_url":"https://api.github.com/users/ibeltagy/received_events","type":"User","site_admin":false},"body":"Adding a multilabel field which is useful for multi-label multi-class classification. \r\nNotes:\r\n- I don't like how I am reading the vocabulary size, but I didn't find a better way. I am open to better suggestions. \r\n- The `as_tensor` function returns a dense vector of zeros and ones. It would have been more efficient to work with a list of indices instead, but that's not supported by torch.nn.BCEWithLogitsLoss","created_at":"2018-03-30T16:34:00Z","updated_at":"2018-03-30T16:55:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1cd2c26b62bbe98deffbaa22d1280f7ef56be9df","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/allenai/allennlp/pulls/1054/commits","review_comments_url":"https://api.github.com/repos/allenai/allennlp/pulls/1054/comments","review_comment_url":"https://api.github.com/repos/allenai/allennlp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allenai/allennlp/issues/1054/comments","statuses_url":"https://api.github.com/repos/allenai/allennlp/statuses/934e3e870d043f839d0227c59a337be072e0ab23","head":{"label":"ibeltagy:multilabel_field","ref":"multilabel_field","sha":"934e3e870d043f839d0227c59a337be072e0ab23","user":{"login":"ibeltagy","id":2287797,"avatar_url":"https://avatars0.githubusercontent.com/u/2287797?v=4","gravatar_id":"","url":"https://api.github.com/users/ibeltagy","html_url":"https://github.com/ibeltagy","followers_url":"https://api.github.com/users/ibeltagy/followers","following_url":"https://api.github.com/users/ibeltagy/following{/other_user}","gists_url":"https://api.github.com/users/ibeltagy/gists{/gist_id}","starred_url":"https://api.github.com/users/ibeltagy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibeltagy/subscriptions","organizations_url":"https://api.github.com/users/ibeltagy/orgs","repos_url":"https://api.github.com/users/ibeltagy/repos","events_url":"https://api.github.com/users/ibeltagy/events{/privacy}","received_events_url":"https://api.github.com/users/ibeltagy/received_events","type":"User","site_admin":false},"repo":{"id":126412790,"name":"allennlp","full_name":"ibeltagy/allennlp","owner":{"login":"ibeltagy","id":2287797,"avatar_url":"https://avatars0.githubusercontent.com/u/2287797?v=4","gravatar_id":"","url":"https://api.github.com/users/ibeltagy","html_url":"https://github.com/ibeltagy","followers_url":"https://api.github.com/users/ibeltagy/followers","following_url":"https://api.github.com/users/ibeltagy/following{/other_user}","gists_url":"https://api.github.com/users/ibeltagy/gists{/gist_id}","starred_url":"https://api.github.com/users/ibeltagy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibeltagy/subscriptions","organizations_url":"https://api.github.com/users/ibeltagy/orgs","repos_url":"https://api.github.com/users/ibeltagy/repos","events_url":"https://api.github.com/users/ibeltagy/events{/privacy}","received_events_url":"https://api.github.com/users/ibeltagy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ibeltagy/allennlp","description":"An open-source NLP research library, built on PyTorch.","fork":true,"url":"https://api.github.com/repos/ibeltagy/allennlp","forks_url":"https://api.github.com/repos/ibeltagy/allennlp/forks","keys_url":"https://api.github.com/repos/ibeltagy/allennlp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ibeltagy/allennlp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ibeltagy/allennlp/teams","hooks_url":"https://api.github.com/repos/ibeltagy/allennlp/hooks","issue_events_url":"https://api.github.com/repos/ibeltagy/allennlp/issues/events{/number}","events_url":"https://api.github.com/repos/ibeltagy/allennlp/events","assignees_url":"https://api.github.com/repos/ibeltagy/allennlp/assignees{/user}","branches_url":"https://api.github.com/repos/ibeltagy/allennlp/branches{/branch}","tags_url":"https://api.github.com/repos/ibeltagy/allennlp/tags","blobs_url":"https://api.github.com/repos/ibeltagy/allennlp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ibeltagy/allennlp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ibeltagy/allennlp/git/refs{/sha}","trees_url":"https://api.github.com/repos/ibeltagy/allennlp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ibeltagy/allennlp/statuses/{sha}","languages_url":"https://api.github.com/repos/ibeltagy/allennlp/languages","stargazers_url":"https://api.github.com/repos/ibeltagy/allennlp/stargazers","contributors_url":"https://api.github.com/repos/ibeltagy/allennlp/contributors","subscribers_url":"https://api.github.com/repos/ibeltagy/allennlp/subscribers","subscription_url":"https://api.github.com/repos/ibeltagy/allennlp/subscription","commits_url":"https://api.github.com/repos/ibeltagy/allennlp/commits{/sha}","git_commits_url":"https://api.github.com/repos/ibeltagy/allennlp/git/commits{/sha}","comments_url":"https://api.github.com/repos/ibeltagy/allennlp/comments{/number}","issue_comment_url":"https://api.github.com/repos/ibeltagy/allennlp/issues/comments{/number}","contents_url":"https://api.github.com/repos/ibeltagy/allennlp/contents/{+path}","compare_url":"https://api.github.com/repos/ibeltagy/allennlp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ibeltagy/allennlp/merges","archive_url":"https://api.github.com/repos/ibeltagy/allennlp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ibeltagy/allennlp/downloads","issues_url":"https://api.github.com/repos/ibeltagy/allennlp/issues{/number}","pulls_url":"https://api.github.com/repos/ibeltagy/allennlp/pulls{/number}","milestones_url":"https://api.github.com/repos/ibeltagy/allennlp/milestones{/number}","notifications_url":"https://api.github.com/repos/ibeltagy/allennlp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ibeltagy/allennlp/labels{/name}","releases_url":"https://api.github.com/repos/ibeltagy/allennlp/releases{/id}","deployments_url":"https://api.github.com/repos/ibeltagy/allennlp/deployments","created_at":"2018-03-23T00:54:46Z","updated_at":"2018-03-30T16:16:35Z","pushed_at":"2018-03-30T16:51:07Z","git_url":"git://github.com/ibeltagy/allennlp.git","ssh_url":"git@github.com:ibeltagy/allennlp.git","clone_url":"https://github.com/ibeltagy/allennlp.git","svn_url":"https://github.com/ibeltagy/allennlp","homepage":"http://www.allennlp.org/","size":10108,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"allenai:master","ref":"master","sha":"db44a25bb453011a3f8144ef9901007cf652ad7d","user":{"login":"allenai","id":5667695,"avatar_url":"https://avatars3.githubusercontent.com/u/5667695?v=4","gravatar_id":"","url":"https://api.github.com/users/allenai","html_url":"https://github.com/allenai","followers_url":"https://api.github.com/users/allenai/followers","following_url":"https://api.github.com/users/allenai/following{/other_user}","gists_url":"https://api.github.com/users/allenai/gists{/gist_id}","starred_url":"https://api.github.com/users/allenai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenai/subscriptions","organizations_url":"https://api.github.com/users/allenai/orgs","repos_url":"https://api.github.com/users/allenai/repos","events_url":"https://api.github.com/users/allenai/events{/privacy}","received_events_url":"https://api.github.com/users/allenai/received_events","type":"Organization","site_admin":false},"repo":{"id":91356408,"name":"allennlp","full_name":"allenai/allennlp","owner":{"login":"allenai","id":5667695,"avatar_url":"https://avatars3.githubusercontent.com/u/5667695?v=4","gravatar_id":"","url":"https://api.github.com/users/allenai","html_url":"https://github.com/allenai","followers_url":"https://api.github.com/users/allenai/followers","following_url":"https://api.github.com/users/allenai/following{/other_user}","gists_url":"https://api.github.com/users/allenai/gists{/gist_id}","starred_url":"https://api.github.com/users/allenai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenai/subscriptions","organizations_url":"https://api.github.com/users/allenai/orgs","repos_url":"https://api.github.com/users/allenai/repos","events_url":"https://api.github.com/users/allenai/events{/privacy}","received_events_url":"https://api.github.com/users/allenai/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/allenai/allennlp","description":"An open-source NLP research library, built on PyTorch.","fork":false,"url":"https://api.github.com/repos/allenai/allennlp","forks_url":"https://api.github.com/repos/allenai/allennlp/forks","keys_url":"https://api.github.com/repos/allenai/allennlp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/allenai/allennlp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/allenai/allennlp/teams","hooks_url":"https://api.github.com/repos/allenai/allennlp/hooks","issue_events_url":"https://api.github.com/repos/allenai/allennlp/issues/events{/number}","events_url":"https://api.github.com/repos/allenai/allennlp/events","assignees_url":"https://api.github.com/repos/allenai/allennlp/assignees{/user}","branches_url":"https://api.github.com/repos/allenai/allennlp/branches{/branch}","tags_url":"https://api.github.com/repos/allenai/allennlp/tags","blobs_url":"https://api.github.com/repos/allenai/allennlp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/allenai/allennlp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/allenai/allennlp/git/refs{/sha}","trees_url":"https://api.github.com/repos/allenai/allennlp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/allenai/allennlp/statuses/{sha}","languages_url":"https://api.github.com/repos/allenai/allennlp/languages","stargazers_url":"https://api.github.com/repos/allenai/allennlp/stargazers","contributors_url":"https://api.github.com/repos/allenai/allennlp/contributors","subscribers_url":"https://api.github.com/repos/allenai/allennlp/subscribers","subscription_url":"https://api.github.com/repos/allenai/allennlp/subscription","commits_url":"https://api.github.com/repos/allenai/allennlp/commits{/sha}","git_commits_url":"https://api.github.com/repos/allenai/allennlp/git/commits{/sha}","comments_url":"https://api.github.com/repos/allenai/allennlp/comments{/number}","issue_comment_url":"https://api.github.com/repos/allenai/allennlp/issues/comments{/number}","contents_url":"https://api.github.com/repos/allenai/allennlp/contents/{+path}","compare_url":"https://api.github.com/repos/allenai/allennlp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/allenai/allennlp/merges","archive_url":"https://api.github.com/repos/allenai/allennlp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/allenai/allennlp/downloads","issues_url":"https://api.github.com/repos/allenai/allennlp/issues{/number}","pulls_url":"https://api.github.com/repos/allenai/allennlp/pulls{/number}","milestones_url":"https://api.github.com/repos/allenai/allennlp/milestones{/number}","notifications_url":"https://api.github.com/repos/allenai/allennlp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/allenai/allennlp/labels{/name}","releases_url":"https://api.github.com/repos/allenai/allennlp/releases{/id}","deployments_url":"https://api.github.com/repos/allenai/allennlp/deployments","created_at":"2017-05-15T15:52:41Z","updated_at":"2018-03-30T14:05:43Z","pushed_at":"2018-03-30T16:51:09Z","git_url":"git://github.com/allenai/allennlp.git","ssh_url":"git@github.com:allenai/allennlp.git","clone_url":"https://github.com/allenai/allennlp.git","svn_url":"https://github.com/allenai/allennlp","homepage":"http://www.allennlp.org/","size":10200,"stargazers_count":1809,"watchers_count":1809,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":228,"mirror_url":null,"archived":false,"open_issues_count":56,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":228,"open_issues":56,"watchers":1809,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1054"},"html":{"href":"https://github.com/allenai/allennlp/pull/1054"},"issue":{"href":"https://api.github.com/repos/allenai/allennlp/issues/1054"},"comments":{"href":"https://api.github.com/repos/allenai/allennlp/issues/1054/comments"},"review_comments":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1054/comments"},"review_comment":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1054/commits"},"statuses":{"href":"https://api.github.com/repos/allenai/allennlp/statuses/934e3e870d043f839d0227c59a337be072e0ab23"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"joelgrus"}}