alphagov / govuk-content-metadata

GovNER: an encoder-based language model (RoBERTa) fine-tuned to perform Named Entity Recognition (NER) on GOV.UK content
MIT License
4 stars 1 forks source link

Add a logger to fast_api_model_serving/main.py #97

Open exfalsoquodlibet opened 1 year ago

exfalsoquodlibet commented 1 year ago
          I'm a fan of logging. This can help debug issues and understand the flow of the application. You could use python's builtin `logging` library, others exist. This can add log statements to various bits of the code which has some advantages to print statements.

ie.. here you could add for the spacy loading of models

import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# ...

print("Load the spacy models")
logger.info("Loading spacy models...")
nlp_phase1 = spacy.load("models/phase1_ner_trf_model/model-best")
nlp_phase2 = spacy.load("models/phase2_ner_trf_model/model-best")

_Originally posted by @mammykins in https://github.com/alphagov/govuk-content-metadata/pull/96#discussion_r1152418280_

exfalsoquodlibet commented 1 year ago

To integrate Cloud logging with Python logging:

https://cloud.google.com/logging/docs/reference/libraries#client-libraries-install-python

https://cloud.google.com/python/docs/reference/logging/latest/std-lib-integration

https://cloud.google.com/logging/docs/setup/python