diff --git a/README.md b/README.md index 6aa2239..d4073c3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This repository contains the code for replicating results from * [Kenton Lee](https://homes.cs.washington.edu/~kentonl), [Luheng He](https://homes.cs.washington.edu/~luheng), [Mike Lewis](https://research.fb.com/people/lewis-mike) and [Luke Zettlemoyer](https://www.cs.washington.edu/people/faculty/lsz) * In Proceedings of the Conference on Empirical Methods in Natural Language Process (EMNLP), 2017 -A demo of the code can be found here: https://kentonl.github.io/e2e-coref. +A demo of the code can be found here: http://www.kentonl.com/e2e-coref. ### Requirements * Python 2.7 diff --git a/demo.py b/demo.py index 5f02888..0208f2b 100755 --- a/demo.py +++ b/demo.py @@ -56,14 +56,6 @@ if __name__ == "__main__": else: port = None - if len(sys.argv) > 3: - # For https. See https://certbot.eff.org - keyfile = sys.argv[3] - certfile = sys.argv[4] - else: - keyfile = None - certfile = None - print "Running experiment: {}.".format(name) config = util.get_config("experiments.conf")[name] config["log_dir"] = util.mkdirs(os.path.join(config["log_root"], name)) @@ -80,29 +72,29 @@ if __name__ == "__main__": if port is not None: class CorefRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): - def do_GET(self): - idx = self.path.find("?") - if idx >= 0: - args = cgi.parse_qs(self.path[idx+1:]) - if "text" in args: - text_arg = args["text"] - if len(text_arg) == 1 and len(text_arg[0]) <= 10000: - text = text_arg[0].decode("utf-8") - print(u"Document text: {}".format(text)) - example = make_predictions(text, model) - print_predictions(example) - self.send_response(200) - self.send_header("Content-Type", "application/json") - self.end_headers() - self.wfile.write("jsonCallback({})".format(json.dumps(example))) - return + def do_POST(self): + form = cgi.FieldStorage( + fp=self.rfile, + headers=self.headers, + environ={"REQUEST_METHOD":"POST", + "CONTENT_TYPE":self.headers["Content-Type"] + }) + if "text" in form: + text = form["text"].value.decode("utf-8") + if len(text) <= 10000: + print(u"Document text: {}".format(text)) + example = make_predictions(text, model) + print_predictions(example) + self.send_response(200) + self.send_header("Content-Type", "application/json") + self.end_headers() + self.wfile.write(json.dumps(example)) + return self.send_response(400) self.send_header("Content-Type", "application/json") self.end_headers() server = BaseHTTPServer.HTTPServer(("", port), CorefRequestHandler) - if keyfile is not None: - server.socket = ssl.wrap_socket(server.socket, keyfile=keyfile, certfile=certfile, server_side=True) print("Running server at port {}".format(port)) server.serve_forever() else: diff --git a/docs/index.html b/docs/index.html index 8b920ab..74c901c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,7 +5,6 @@ - @@ -13,56 +12,9 @@

End-to-end Neural Coreference Resolution

-

This is the demo for the coreference resolution system described in:

-
- End-to-end Neural Coreference Resolution -
- Kenton Lee, - Luheng He, - Mike Lewis and - Luke Zettlemoyer -
- In Proceedings of the Conference on Empirical Methods in Natural Language Process (EMNLP), 2017. -
-

Submit an input document below. A simple example is provided.

-

On the right side, the highest-scoring spans are shown. On the left side, the predicted coreference cluster (mentions of the same entity) are shown.

-

Hover over the mentions on either side to highlight their location in the document and render the attention weights of the words.

-

The code is available here.

-
-
-
-
-
-
-

Input Document

- -
-
-
-
-
- -      - - Render attention weights on hover -
-
-
-
-
-
-
-

- -
-
-

-

-
-
-

- +

The demo has been moved to here.

+ diff --git a/html/deploy.sh b/html/deploy.sh new file mode 100755 index 0000000..4f520d5 --- /dev/null +++ b/html/deploy.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +html_root=~/public_html +name=e2e-coref +mkdir -p $html_root/$name +cp index.html main.js query.cgi $html_root/$name diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..8b920ab --- /dev/null +++ b/html/index.html @@ -0,0 +1,68 @@ + + + + End-to-End Neural Coreference Resolution Demo + + + + + + + +
+
+
+

End-to-end Neural Coreference Resolution

+

This is the demo for the coreference resolution system described in:

+
+ End-to-end Neural Coreference Resolution +
+ Kenton Lee, + Luheng He, + Mike Lewis and + Luke Zettlemoyer +
+ In Proceedings of the Conference on Empirical Methods in Natural Language Process (EMNLP), 2017. +
+

Submit an input document below. A simple example is provided.

+

On the right side, the highest-scoring spans are shown. On the left side, the predicted coreference cluster (mentions of the same entity) are shown.

+

Hover over the mentions on either side to highlight their location in the document and render the attention weights of the words.

+

The code is available here.

+
+
+
+
+
+
+

Input Document

+ +
+
+
+
+
+ +      + + Render attention weights on hover +
+
+
+
+
+
+
+

+
    +
    +
    +

    +

    +
    +
    +

    +
      +
      +
      + + diff --git a/docs/main.js b/html/main.js similarity index 95% rename from docs/main.js rename to html/main.js index d5376eb..b31e4cc 100644 --- a/docs/main.js +++ b/html/main.js @@ -91,34 +91,38 @@ function render_top_spans(top_spans_div, top_spans_data, text, head_scores) { }); } -function jsonCallback(data) { - var text_div = $("#text"); - text_div.empty(); - var text = [].concat.apply([], data.sentences); - $.each(text, function(i, token) { - var lrb = $("") - .attr("id", "lrb" + i) - .appendTo(text_div); - var text_span = $("") - .attr("id", "t" + i) - .html(token) - .appendTo(text_div); - var rrb = $("") - .attr("id", "rrb" + i) - .appendTo(text_div); - $("").text(" ").appendTo(text_div); - }); - render_predicted_clusters($("#predicted-clusters"), data.predicted_clusters, text, data.head_scores); - render_top_spans($("#top-spans"), data.top_spans, text, data.head_scores); - $("#top-spans-title").text("Top Spans"); - $("#text-title").text("Document"); - $("#predicted-clusters-title").text("Predicted Clusters"); -} - $(document).ready(function() { $("#input-form").submit(function(event){ event.preventDefault(); var text = $("#input-doc").val().replace("’", "'"); - $.getJSON("https://appositive.cs.washington.edu:8080?callback=?", {"text": text}); + $.ajax({ + dataType: "json", + url: "query.cgi", + data: { "text": text }, + timeout: 60000, + success: function(data, statusText, xhr) { + var text_div = $("#text"); + text_div.empty(); + var text = [].concat.apply([], data.sentences); + $.each(text, function(i, token) { + var lrb = $("") + .attr("id", "lrb" + i) + .appendTo(text_div); + var text_span = $("") + .attr("id", "t" + i) + .html(token) + .appendTo(text_div); + var rrb = $("") + .attr("id", "rrb" + i) + .appendTo(text_div); + $("").text(" ").appendTo(text_div); + }); + render_predicted_clusters($("#predicted-clusters"), data.predicted_clusters, text, data.head_scores); + render_top_spans($("#top-spans"), data.top_spans, text, data.head_scores); + $("#top-spans-title").text("Top Spans"); + $("#text-title").text("Document"); + $("#predicted-clusters-title").text("Predicted Clusters"); + } + }); }); }); diff --git a/html/query.cgi b/html/query.cgi new file mode 100755 index 0000000..9476f62 --- /dev/null +++ b/html/query.cgi @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +import sys +import json +import requests +import cgi, cgitb +cgitb.enable() + +SERVER = "http://localhost" +PORT = 10001 + +form = cgi.FieldStorage() +if "text" not in form: + print "Status: %d %s\n\n" % (400, "Bad Request") + sys.exit(0) +text = form.getvalue("text") +try: + post_response = requests.post(url="{}:{}".format(SERVER, PORT), data={"text":text}, timeout=180) +except requests.exceptions.ConnectionError as e: + print e + sys.exit(0) + +print "Content-Type: text/html" +print + +print post_response.text.encode("utf-8")