Consolidate REST APIs #239
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft refactor of the REST APIs that unifies everything into one
CnlpRestApp
class, which accepts only a model path and optionally a device to run on.CLI changes
The CLI now accepts one or more
--model
arguments with a path to the model, and an optional routing prefix for the model's REST endpoint.For example, to run the negation model, you could do:
Then you can send queries to
localhost:8000/process
.To run the negation and temporal models simultaneously, you could do:
Then you can send negation queries to
localhost:8000/negation/process
and temporal queries tolocalhost:8000/temporal/process
.API changes
Input
The
/process
endpoint for every model accepts query parameters formax_seq_length
,chunk_len
,num_chunks
, andinsert_empty_chunk_at_beginning
. The endpoint also expects a JSON payload with the following format:If
entity_spans
is null or omitted, then the model will just processtext
. Otherwise, the model will process a new string for each entity, where<e>
and</e>
are inserted at the span boundaries.Output
The model will return a list of JSON objects, one for each entity (or just one if no entity spans were given). Each will contain the text that was processed, along with an object describing the output of each of the model's tasks.
For classification tasks, it will include the predicted label, and the probabilities for each possible label.
For tagging tasks, it will include a list of spans, with the span text, predicted tag, start word index, end word index, and whether the span is valid (starting with a
B-
tag).For relations tasks, it will include a list of relations, with the text and word index of both arguments, and the predicted relation label.
TODO
This implementation so far only supports models with the
"cnlpt"
model type, so a few changes will need to be made to support LSTM, CNN, and hierarchical models.For tagging and relations tasks, it would be nice to return character indices instead of word indices for consistency (since the
entity_spans
input expects character indices).The logger still needs to be configured, probably we should log to a file as well as the console whenever a
/process
request is made.Once the API is finalized the README and docker files should be updated to reflect the changes.