The following describes the steps necessary to add a model implemented in allennlp to the online demo.
These assume that the model to be added to the demo is already available in master of allennlp. We will follow the implementation of the SRL demo as an example.
- Fork and clone allennlp-demo, then follow installation instructions.
Dockerfile
:- Make sure the commit id for
allennlp/commit
points to a commit where your model is implemented. Alternatively, you can use a release that includes your model with, for example,allennlp/allennlp:v0.6.2
.
- Make sure the commit id for
server/models.py
: Instantiate aDemoModel
object in theMODELS
dictionary.- Provide a url to the trained model (e.g.,
https://s3-us-west-2.amazonaws.com/allennlp/models/srl-model-2018.05.25.tar.gz
).
- Provide a url to the trained model (e.g.,
demo/src/components/menu.js
:- Add a
buildLink
clause:
{buildLink("semantic-role-labeling", "Semantic Role Labeling")}
- Add a
demo/src/components/
:- Add a
<your-model-name>Component.js
file. - this is where most of the model-specific js logic is implemented. See
demo/src/components/SrlComponent.js
for example.
- Add a
demo/src/App.js
:- Import the model component implemented in the previous step:
import SrlComponent from './components/SrlComponent';
- In the instantiation of
ModelComponent
, add anelse if
clause returning an instance of your new component:
else if (selectedModel === "semantic-role-labeling") { return (<SrlComponent requestData={requestData} responseData={responseData}/>) }
app.py
:- Add a
app.route
to the html page, using the same name provided in step (4). This allows users to link directly to your model.
@app.route('/semantic-role-labeling/<permalink>')
- Consider also adding logging of your model's outputs. Search for
log_blob
in thepredict
function.
- Add a
- Add a test for your model to
tests/server_test.py
.- For instance, see
test_semantic_role_labeling
.
- For instance, see