Skip to content

Inconsistent loading time when loading patterns into spaCy from FastAPI #3253

@raqibhayder

Description

@raqibhayder

First check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.
  • After submitting this, I commit to one of:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • I already hit the "watch" button in this repository to receive notifications, and I commit to help at least 2 people that ask questions in the future.
    • Implement a Pull Request for a confirmed bug.

Example

I have created a repo called fruits which is self-contained and reproduces the issue at hand.

Description

I was using flask and spaCy to serve a named entity recognition (NER) model to detect entities in text, very similar to the fruits repo. I load patterns from two pattern files, fruits.jsonl and animals.jsonl, which would take about 1 minute or so to load the ~40k patterns.

I decided to move from flask to fastapi, but unfortunately, this leads to pattern loading times going up and becoming inconsistent. The loading times for different scenarios are in the README.md in the fruits repo.

History

I first raised this issue in spaCy discussion here as it was thought to be a spaCy issue, but upon further investigation, I believe that it is a FastAPI issue. Using spaCy to load patterns from a standalone script does not slow down the load time. The slowdown only happens when patterns are being loaded inside a FastAPI application.

Any help will be appreciated. Please ask any questions that you might have (I will be actively monitoring this issue).

Environment

  • OS: macOS
  • FastAPI Version [e.g. 0.65.0]:
  • IDE: PyCharm
  • FastAPI version: 0.63.0
  • Python version: 3.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions