Skip to content

Conversation

ianbulovic
Copy link
Contributor

@ianbulovic ianbulovic commented Jul 30, 2025

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:

cnlpt rest --model mlml-chip/negation_pubmedbert_sharpseed

Then you can send queries to localhost:8000/process.

To run the negation and temporal models simultaneously, you could do:

cnlpt rest \
 --model /negation=mlml-chip/negation_pubmedbert_sharpseed \
 --model /temporal=mlml-chip/thyme2_colon_e2e

Then you can send negation queries to localhost:8000/negation/process and temporal queries to localhost:8000/temporal/process.

API changes

Input

The /process endpoint for every model accepts query parameters for max_seq_length, chunk_len, num_chunks, and insert_empty_chunk_at_beginning. The endpoint also expects a JSON payload with the following format:

{
  text: str,
  entity_spans: list[tuple[int, int]] | None,
}

If entity_spans is null or omitted, then the model will just process text. 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.

@ianbulovic
Copy link
Contributor Author

Closing in favor of #241

@ianbulovic ianbulovic closed this Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant