{"action":"created","comment":{"url":"https://api.github.com/repos/allenai/allennlp/pulls/comments/180906604","pull_request_review_id":111412804,"id":180906604,"diff_hunk":"@@ -0,0 +1,192 @@\n+import logging\n+from typing import List, Dict\n+\n+from overrides import overrides\n+\n+import torch\n+\n+from allennlp.common import Params\n+from allennlp.data.fields.production_rule_field import ProductionRuleArray\n+from allennlp.data.vocabulary import Vocabulary\n+from allennlp.modules import TextFieldEmbedder, Seq2SeqEncoder\n+from allennlp.modules.similarity_functions import SimilarityFunction\n+from allennlp.nn.decoding import BeamSearch, MaximumMarginalLikelihood\n+from allennlp.nn import util as nn_util\n+from allennlp.models.model import Model\n+from allennlp.models.encoder_decoders.nlvr.nlvr_decoder_state import NlvrDecoderState\n+from allennlp.models.encoder_decoders.nlvr.nlvr_decoder_step import NlvrDecoderStep\n+from allennlp.models.encoder_decoders.nlvr.nlvr_semantic_parser import NlvrSemanticParser\n+from allennlp.semparse.worlds import NlvrWorld\n+\n+logger = logging.getLogger(__name__)  # pylint: disable=invalid-name\n+\n+\n+@Model.register(\"nlvr_direct_parser\")\n+class NlvrDirectSemanticParser(NlvrSemanticParser):\n+    \"\"\"\n+    ``NlvrDirectSemanticParser`` is an ``NlvrSemanticParser`` that gets around the problem of lack\n+    of logical form annotations by maximizing the marginal likelihood of an approximate set of target\n+    sequences that yield the correct denotation. The main difference between this parser and\n+    ``NlvrCoverageSemanticParser`` is that while this parser takes the output of an offline search\n+    process as the set of target sequences for training, the latter performs search during training.\n+\n+    Parameters\n+    ----------\n+    vocab : ``Vocabulary``\n+        Passed to super-class.\n+    sentence_embedder : ``TextFieldEmbedder``\n+        Passed to super-class.\n+    nonterminal_embedder : ``TextFieldEmbedder``\n+        Passed to super-class.\n+    terminal_embedder : ``TextFieldEmbedder``\n+        Passed to super-class.\n+    encoder : ``Seq2SeqEncoder``\n+        Passed to super-class.\n+    attention_function : ``SimilarityFunction``\n+        We compute an attention over the input question at each step of the decoder, using the\n+        decoder hidden state as the query.  This is the similarity function we use for that\n+        attention.\n+    decoder_beam_search : ``BeamSearch``\n+        Beam search used to retrieve best sequences after training.\n+    max_decoding_steps : ``int``\n+        Maximum number of steps for beam search after training.\n+    \"\"\"\n+    def __init__(self,\n+                 vocab: Vocabulary,\n+                 sentence_embedder: TextFieldEmbedder,\n+                 nonterminal_embedder: TextFieldEmbedder,\n+                 terminal_embedder: TextFieldEmbedder,\n+                 encoder: Seq2SeqEncoder,\n+                 attention_function: SimilarityFunction,\n+                 decoder_beam_search: BeamSearch,\n+                 max_decoding_steps: int) -> None:\n+        super(NlvrDirectSemanticParser, self).__init__(vocab=vocab,\n+                                                       sentence_embedder=sentence_embedder,\n+                                                       nonterminal_embedder=nonterminal_embedder,\n+                                                       terminal_embedder=terminal_embedder,\n+                                                       encoder=encoder)\n+        self._decoder_trainer = MaximumMarginalLikelihood()\n+        action_embedding_dim = nonterminal_embedder.get_output_dim() * 2\n+\n+        self._decoder_step = NlvrDecoderStep(encoder_output_dim=self._encoder.get_output_dim(),\n+                                             action_embedding_dim=action_embedding_dim,\n+                                             attention_function=attention_function)\n+        self._decoder_beam_search = decoder_beam_search\n+        self._max_decoding_steps = max_decoding_steps\n+        self._action_padding_index = -1\n+\n+    @overrides\n+    def forward(self,  # type: ignore\n+                sentence: Dict[str, torch.LongTensor],\n+                worlds: List[List[NlvrWorld]],\n+                actions: List[List[ProductionRuleArray]],\n+                target_action_sequences: torch.LongTensor = None,\n+                labels: torch.LongTensor = None) -> Dict[str, torch.Tensor]:\n+        # pylint: disable=arguments-differ\n+        \"\"\"\n+        Decoder logic for producing type constrained target sequences that maximize coverage of\n+        their respective agendas, and minimize a denotation based loss.","path":"allennlp/models/encoder_decoders/nlvr/nlvr_direct_semantic_parser.py","position":88,"original_position":88,"commit_id":"8051e24b5342f8abdfe9ec388ac80eea50fa394b","original_commit_id":"8051e24b5342f8abdfe9ec388ac80eea50fa394b","user":{"login":"pdasigi","id":3508113,"avatar_url":"https://avatars2.githubusercontent.com/u/3508113?v=4","gravatar_id":"","url":"https://api.github.com/users/pdasigi","html_url":"https://github.com/pdasigi","followers_url":"https://api.github.com/users/pdasigi/followers","following_url":"https://api.github.com/users/pdasigi/following{/other_user}","gists_url":"https://api.github.com/users/pdasigi/gists{/gist_id}","starred_url":"https://api.github.com/users/pdasigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdasigi/subscriptions","organizations_url":"https://api.github.com/users/pdasigi/orgs","repos_url":"https://api.github.com/users/pdasigi/repos","events_url":"https://api.github.com/users/pdasigi/events{/privacy}","received_events_url":"https://api.github.com/users/pdasigi/received_events","type":"User","site_admin":false},"body":"Thanks! Fixed it.","created_at":"2018-04-11T21:39:50Z","updated_at":"2018-04-11T21:39:51Z","html_url":"https://github.com/allenai/allennlp/pull/1053#discussion_r180906604","pull_request_url":"https://api.github.com/repos/allenai/allennlp/pulls/1053","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/comments/180906604"},"html":{"href":"https://github.com/allenai/allennlp/pull/1053#discussion_r180906604"},"pull_request":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1053"}},"in_reply_to_id":180897690},"pull_request":{"url":"https://api.github.com/repos/allenai/allennlp/pulls/1053","id":178473250,"html_url":"https://github.com/allenai/allennlp/pull/1053","diff_url":"https://github.com/allenai/allennlp/pull/1053.diff","patch_url":"https://github.com/allenai/allennlp/pull/1053.patch","issue_url":"https://api.github.com/repos/allenai/allennlp/issues/1053","number":1053,"state":"open","locked":false,"title":"Training NLVR parser using logical forms","user":{"login":"pdasigi","id":3508113,"avatar_url":"https://avatars2.githubusercontent.com/u/3508113?v=4","gravatar_id":"","url":"https://api.github.com/users/pdasigi","html_url":"https://github.com/pdasigi","followers_url":"https://api.github.com/users/pdasigi/followers","following_url":"https://api.github.com/users/pdasigi/following{/other_user}","gists_url":"https://api.github.com/users/pdasigi/gists{/gist_id}","starred_url":"https://api.github.com/users/pdasigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdasigi/subscriptions","organizations_url":"https://api.github.com/users/pdasigi/orgs","repos_url":"https://api.github.com/users/pdasigi/repos","events_url":"https://api.github.com/users/pdasigi/events{/privacy}","received_events_url":"https://api.github.com/users/pdasigi/received_events","type":"User","site_admin":false},"body":"Summary of changes:\r\n1) Use multi-world consistency along with agenda in `scripts/nlvr/get_nlvr_logical_forms.py` and added a flag `--ignore_agenda` to the script to produce logical forms relying only on consistency (they're bad!).\r\n2) Changed the format of the preprocessed files produced by `scripts/nlvr/get_nlvr_logical_forms.py` to include action sequences instead of logical forms, and also worlds and labels in the output for computing metrics during training.\r\n3) Changed the dataset reader to allow reading preprocessed data format.\r\n4) Kept the core functionality of `NlvrSemanticParser` in a base class, and broke the rest into two classes - `NlvrCoverageSemanticParser`, that trains without logical form supervision using ERM as before; and `NlvrDirectSemanticParser` (for the lack of a better name), that trains with the logical forms produced by offline search using MML.","created_at":"2018-03-30T00:45:31Z","updated_at":"2018-04-11T21:39:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"70198fc01106a8ce631c272147339d67d6734626","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/allenai/allennlp/pulls/1053/commits","review_comments_url":"https://api.github.com/repos/allenai/allennlp/pulls/1053/comments","review_comment_url":"https://api.github.com/repos/allenai/allennlp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/allenai/allennlp/issues/1053/comments","statuses_url":"https://api.github.com/repos/allenai/allennlp/statuses/8051e24b5342f8abdfe9ec388ac80eea50fa394b","head":{"label":"pdasigi:train_nlvr_parser_with_lfs","ref":"train_nlvr_parser_with_lfs","sha":"8051e24b5342f8abdfe9ec388ac80eea50fa394b","user":{"login":"pdasigi","id":3508113,"avatar_url":"https://avatars2.githubusercontent.com/u/3508113?v=4","gravatar_id":"","url":"https://api.github.com/users/pdasigi","html_url":"https://github.com/pdasigi","followers_url":"https://api.github.com/users/pdasigi/followers","following_url":"https://api.github.com/users/pdasigi/following{/other_user}","gists_url":"https://api.github.com/users/pdasigi/gists{/gist_id}","starred_url":"https://api.github.com/users/pdasigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdasigi/subscriptions","organizations_url":"https://api.github.com/users/pdasigi/orgs","repos_url":"https://api.github.com/users/pdasigi/repos","events_url":"https://api.github.com/users/pdasigi/events{/privacy}","received_events_url":"https://api.github.com/users/pdasigi/received_events","type":"User","site_admin":false},"repo":{"id":101232158,"name":"allennlp","full_name":"pdasigi/allennlp","owner":{"login":"pdasigi","id":3508113,"avatar_url":"https://avatars2.githubusercontent.com/u/3508113?v=4","gravatar_id":"","url":"https://api.github.com/users/pdasigi","html_url":"https://github.com/pdasigi","followers_url":"https://api.github.com/users/pdasigi/followers","following_url":"https://api.github.com/users/pdasigi/following{/other_user}","gists_url":"https://api.github.com/users/pdasigi/gists{/gist_id}","starred_url":"https://api.github.com/users/pdasigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pdasigi/subscriptions","organizations_url":"https://api.github.com/users/pdasigi/orgs","repos_url":"https://api.github.com/users/pdasigi/repos","events_url":"https://api.github.com/users/pdasigi/events{/privacy}","received_events_url":"https://api.github.com/users/pdasigi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pdasigi/allennlp","description":"An open-source NLP research library, built on PyTorch.","fork":true,"url":"https://api.github.com/repos/pdasigi/allennlp","forks_url":"https://api.github.com/repos/pdasigi/allennlp/forks","keys_url":"https://api.github.com/repos/pdasigi/allennlp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pdasigi/allennlp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pdasigi/allennlp/teams","hooks_url":"https://api.github.com/repos/pdasigi/allennlp/hooks","issue_events_url":"https://api.github.com/repos/pdasigi/allennlp/issues/events{/number}","events_url":"https://api.github.com/repos/pdasigi/allennlp/events","assignees_url":"https://api.github.com/repos/pdasigi/allennlp/assignees{/user}","branches_url":"https://api.github.com/repos/pdasigi/allennlp/branches{/branch}","tags_url":"https://api.github.com/repos/pdasigi/allennlp/tags","blobs_url":"https://api.github.com/repos/pdasigi/allennlp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pdasigi/allennlp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pdasigi/allennlp/git/refs{/sha}","trees_url":"https://api.github.com/repos/pdasigi/allennlp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pdasigi/allennlp/statuses/{sha}","languages_url":"https://api.github.com/repos/pdasigi/allennlp/languages","stargazers_url":"https://api.github.com/repos/pdasigi/allennlp/stargazers","contributors_url":"https://api.github.com/repos/pdasigi/allennlp/contributors","subscribers_url":"https://api.github.com/repos/pdasigi/allennlp/subscribers","subscription_url":"https://api.github.com/repos/pdasigi/allennlp/subscription","commits_url":"https://api.github.com/repos/pdasigi/allennlp/commits{/sha}","git_commits_url":"https://api.github.com/repos/pdasigi/allennlp/git/commits{/sha}","comments_url":"https://api.github.com/repos/pdasigi/allennlp/comments{/number}","issue_comment_url":"https://api.github.com/repos/pdasigi/allennlp/issues/comments{/number}","contents_url":"https://api.github.com/repos/pdasigi/allennlp/contents/{+path}","compare_url":"https://api.github.com/repos/pdasigi/allennlp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pdasigi/allennlp/merges","archive_url":"https://api.github.com/repos/pdasigi/allennlp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pdasigi/allennlp/downloads","issues_url":"https://api.github.com/repos/pdasigi/allennlp/issues{/number}","pulls_url":"https://api.github.com/repos/pdasigi/allennlp/pulls{/number}","milestones_url":"https://api.github.com/repos/pdasigi/allennlp/milestones{/number}","notifications_url":"https://api.github.com/repos/pdasigi/allennlp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pdasigi/allennlp/labels{/name}","releases_url":"https://api.github.com/repos/pdasigi/allennlp/releases{/id}","deployments_url":"https://api.github.com/repos/pdasigi/allennlp/deployments","created_at":"2017-08-23T23:05:48Z","updated_at":"2017-08-23T23:05:50Z","pushed_at":"2018-04-11T18:24:18Z","git_url":"git://github.com/pdasigi/allennlp.git","ssh_url":"git@github.com:pdasigi/allennlp.git","clone_url":"https://github.com/pdasigi/allennlp.git","svn_url":"https://github.com/pdasigi/allennlp","homepage":"http://www.allennlp.org/","size":11268,"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:wikitables","ref":"wikitables","sha":"65f2c14b2d98d4b5119e56398face9a78b156eb1","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-04-11T18:24:16Z","pushed_at":"2018-04-11T18:24:14Z","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":10218,"stargazers_count":1881,"watchers_count":1881,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":248,"mirror_url":null,"archived":false,"open_issues_count":54,"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":248,"open_issues":54,"watchers":1881,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1053"},"html":{"href":"https://github.com/allenai/allennlp/pull/1053"},"issue":{"href":"https://api.github.com/repos/allenai/allennlp/issues/1053"},"comments":{"href":"https://api.github.com/repos/allenai/allennlp/issues/1053/comments"},"review_comments":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1053/comments"},"review_comment":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/allenai/allennlp/pulls/1053/commits"},"statuses":{"href":"https://api.github.com/repos/allenai/allennlp/statuses/8051e24b5342f8abdfe9ec388ac80eea50fa394b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pdasigi"}}