Commit 25dff938 by Kenton Lee

Move demo out of github page.

parent a7534b73
...@@ -7,7 +7,7 @@ This repository contains the code for replicating results from ...@@ -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) * [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 * 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 ### Requirements
* Python 2.7 * Python 2.7
......
...@@ -56,14 +56,6 @@ if __name__ == "__main__": ...@@ -56,14 +56,6 @@ if __name__ == "__main__":
else: else:
port = None 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) print "Running experiment: {}.".format(name)
config = util.get_config("experiments.conf")[name] config = util.get_config("experiments.conf")[name]
config["log_dir"] = util.mkdirs(os.path.join(config["log_root"], name)) config["log_dir"] = util.mkdirs(os.path.join(config["log_root"], name))
...@@ -80,29 +72,29 @@ if __name__ == "__main__": ...@@ -80,29 +72,29 @@ if __name__ == "__main__":
if port is not None: if port is not None:
class CorefRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): class CorefRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self): def do_POST(self):
idx = self.path.find("?") form = cgi.FieldStorage(
if idx >= 0: fp=self.rfile,
args = cgi.parse_qs(self.path[idx+1:]) headers=self.headers,
if "text" in args: environ={"REQUEST_METHOD":"POST",
text_arg = args["text"] "CONTENT_TYPE":self.headers["Content-Type"]
if len(text_arg) == 1 and len(text_arg[0]) <= 10000: })
text = text_arg[0].decode("utf-8") if "text" in form:
text = form["text"].value.decode("utf-8")
if len(text) <= 10000:
print(u"Document text: {}".format(text)) print(u"Document text: {}".format(text))
example = make_predictions(text, model) example = make_predictions(text, model)
print_predictions(example) print_predictions(example)
self.send_response(200) self.send_response(200)
self.send_header("Content-Type", "application/json") self.send_header("Content-Type", "application/json")
self.end_headers() self.end_headers()
self.wfile.write("jsonCallback({})".format(json.dumps(example))) self.wfile.write(json.dumps(example))
return return
self.send_response(400) self.send_response(400)
self.send_header("Content-Type", "application/json") self.send_header("Content-Type", "application/json")
self.end_headers() self.end_headers()
server = BaseHTTPServer.HTTPServer(("", port), CorefRequestHandler) 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)) print("Running server at port {}".format(port))
server.serve_forever() server.serve_forever()
else: else:
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head> </head>
<body> <body>
...@@ -13,55 +12,8 @@ ...@@ -13,55 +12,8 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<h2>End-to-end Neural Coreference Resolution</h2> <h2>End-to-end Neural Coreference Resolution</h2>
<p>This is the demo for the coreference resolution system described in: </p> <p>The demo has been moved to <a href="http://www.kentonl.com/e2e-coref">here.</a></p>
<div class="well text-left" style="display:inline-block">
<b><a href="https://homes.cs.washington.edu/~kentonl/pub/lhlz-emnlp.2017.pdf">End-to-end Neural Coreference Resolution</a></b>
<br>
<a href="https://homes.cs.washington.edu/~kentonl">Kenton Lee</a>,
<a href="https://homes.cs.washington.edu/~luheng">Luheng He</a>,
<a href="https://research.fb.com/people/lewis-mike">Mike Lewis</a> and
<a href="https://www.cs.washington.edu/people/faculty/lsz">Luke Zettlemoyer</a>
<br>
<em>In Proceedings of the Conference on Empirical Methods in Natural Language Process (EMNLP), 2017.</em>
</div> </div>
<p>Submit an input document below. A simple example is provided.</p>
<p>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.</p>
<p>Hover over the mentions on either side to highlight their location in the document and render the attention weights of the words.</p>
<p>The code is available <a href="https://github.com/kentonl/e2e-coref">here</a>.</p>
</div>
</div>
<form role="form" id="input-form">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<h4>Input Document</h4>
<textarea id="input-doc" class="form-control" rows="5" required>Unlike many elite athletes, Federer had a long-term plan from an early age to preserve his body, paying close attention to fitness with the trainer Pierre Paganini. Unlike many young tennis stars, Federer avoided overplaying, managing his schedule sagaciously.</textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" id="form-submit" class="btn btn-primary">Submit</button>
&nbsp;&nbsp;&nbsp;&nbsp;
<input id="show-attention" type="checkbox" class="custom-control-input">
<span class="custom-control-description">Render attention weights on hover</span>
</div>
</div>
</form>
<br>
<br>
<div class="row">
<div class="col-md-3">
<h4 id="predicted-clusters-title"></h4>
<ul id="predicted-clusters" class="list-group"></ul>
</div>
<div class="col-md-6">
<h4 id="text-title"></h4>
<p id="text" class="lead"></p>
</div>
<div class="col-md-3">
<h4 id="top-spans-title"></h4>
<ul id="top-spans" class="list-group"></ul>
</div> </div>
</div> </div>
</body> </body>
......
#!/bin/bash
html_root=~/public_html
name=e2e-coref
mkdir -p $html_root/$name
cp index.html main.js query.cgi $html_root/$name
<!DOCTYPE HTML>
<html>
<head>
<title>End-to-End Neural Coreference Resolution Demo</title>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>End-to-end Neural Coreference Resolution</h2>
<p>This is the demo for the coreference resolution system described in: </p>
<div class="well text-left" style="display:inline-block">
<b><a href="https://homes.cs.washington.edu/~kentonl/pub/lhlz-emnlp.2017.pdf">End-to-end Neural Coreference Resolution</a></b>
<br>
<a href="https://homes.cs.washington.edu/~kentonl">Kenton Lee</a>,
<a href="https://homes.cs.washington.edu/~luheng">Luheng He</a>,
<a href="https://research.fb.com/people/lewis-mike">Mike Lewis</a> and
<a href="https://www.cs.washington.edu/people/faculty/lsz">Luke Zettlemoyer</a>
<br>
<em>In Proceedings of the Conference on Empirical Methods in Natural Language Process (EMNLP), 2017.</em>
</div>
<p>Submit an input document below. A simple example is provided.</p>
<p>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.</p>
<p>Hover over the mentions on either side to highlight their location in the document and render the attention weights of the words.</p>
<p>The code is available <a href="https://github.com/kentonl/e2e-coref">here</a>.</p>
</div>
</div>
<form role="form" id="input-form">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<h4>Input Document</h4>
<textarea id="input-doc" class="form-control" rows="5" required>Unlike many elite athletes, Federer had a long-term plan from an early age to preserve his body, paying close attention to fitness with the trainer Pierre Paganini. Unlike many young tennis stars, Federer avoided overplaying, managing his schedule sagaciously.</textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button type="submit" id="form-submit" class="btn btn-primary">Submit</button>
&nbsp;&nbsp;&nbsp;&nbsp;
<input id="show-attention" type="checkbox" class="custom-control-input">
<span class="custom-control-description">Render attention weights on hover</span>
</div>
</div>
</form>
<br>
<br>
<div class="row">
<div class="col-md-3">
<h4 id="predicted-clusters-title"></h4>
<ul id="predicted-clusters" class="list-group"></ul>
</div>
<div class="col-md-6">
<h4 id="text-title"></h4>
<p id="text" class="lead"></p>
</div>
<div class="col-md-3">
<h4 id="top-spans-title"></h4>
<ul id="top-spans" class="list-group"></ul>
</div>
</div>
</body>
</html>
...@@ -91,7 +91,16 @@ function render_top_spans(top_spans_div, top_spans_data, text, head_scores) { ...@@ -91,7 +91,16 @@ function render_top_spans(top_spans_div, top_spans_data, text, head_scores) {
}); });
} }
function jsonCallback(data) { $(document).ready(function() {
$("#input-form").submit(function(event){
event.preventDefault();
var text = $("#input-doc").val().replace("’", "'");
$.ajax({
dataType: "json",
url: "query.cgi",
data: { "text": text },
timeout: 60000,
success: function(data, statusText, xhr) {
var text_div = $("#text"); var text_div = $("#text");
text_div.empty(); text_div.empty();
var text = [].concat.apply([], data.sentences); var text = [].concat.apply([], data.sentences);
...@@ -113,12 +122,7 @@ function jsonCallback(data) { ...@@ -113,12 +122,7 @@ function jsonCallback(data) {
$("#top-spans-title").text("Top Spans"); $("#top-spans-title").text("Top Spans");
$("#text-title").text("Document"); $("#text-title").text("Document");
$("#predicted-clusters-title").text("Predicted Clusters"); $("#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});
}); });
}); });
#!/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")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment