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
* [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
......
......@@ -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:
......
......@@ -5,7 +5,6 @@
<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>
......@@ -13,56 +12,9 @@
<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>
<p>The demo has been moved to <a href="http://www.kentonl.com/e2e-coref">here.</a></p>
</div>
</div>
</div>
</body>
</html>
#!/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,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 = $("<span>")
.attr("id", "lrb" + i)
.appendTo(text_div);
var text_span = $("<span>")
.attr("id", "t" + i)
.html(token)
.appendTo(text_div);
var rrb = $("<span>")
.attr("id", "rrb" + i)
.appendTo(text_div);
$("<span>").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 = $("<span>")
.attr("id", "lrb" + i)
.appendTo(text_div);
var text_span = $("<span>")
.attr("id", "t" + i)
.html(token)
.appendTo(text_div);
var rrb = $("<span>")
.attr("id", "rrb" + i)
.appendTo(text_div);
$("<span>").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");
}
});
});
});
#!/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