text-analysis / keyword_extraction.py
Daryl Fung
added top 10
2a000a7
raw
history blame contribute delete
No virus
4.02 kB
from keybert import KeyBERT
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
test_doc = """
Database that collects, administrative, clinical and demographic information on hospital discharges (including deaths, sign-outs and transfers). Some provinces and territories also use the DAD to capture day surgery.
The discharge abstract database is a database for information on all AHS separations for acute care institutions, including discharges, deaths, sign-outs and transfers.
Data on discharges, transfers and deaths of in-patients and day surgery patients from acute care hospitals in BC. All Canadian hospitals (except those in Quebec) submit their separations records directly to the Canadian Institute of Health information (CIHI) for inclusion in the Discharge Abstract Database (DAD). The database contains demographic, administrative and clinical data for hospital discharges (inpatient acute, chronic, rehabilitation) and day surgeries. A provincial data set, including various CIHI value-added elements (such as case mix groups, and resource intensity weights) is released on a monthly basis to the respective Ministries of Health. The DAD data files which Population Data BC receives include the CIHI variables. Population Data BC receives these data once per year.
Health data maintained by Manitoba Health consisting of hospital forms/computerized records containing summaries of demographic and clinical information (e.g., gender, postal code, diagnoses and procedure codes) completed at the point of discharge from the hospital. Several hundred thousand abstracts per year are submitted for all separations from acute and chronic care facilities in Manitoba and for all Manitobans admitted to out-of-province facilities. The Hospital Abstracts Data includes records of both Manitoba residents and non-Manitoba residents hospitalized in Manitoba facilities and information about inpatient and day surgery services.
Patient discharge information from New Brunswick hospitals. Captures administrative, clinical and demographic information including discharges, deaths, sign-outs, and transfers.
The Provincial Discharge Abstract Database (PDAD) is the NLCHI dataset that contains demographic, clinical and administrative data collected at hospitals when patients are discharged from inpatient and surgical day care services and submitted to the CIHI Discharge Abstract Database. The PDAD captures information regarding hospitalizations of both residents of NL and non-residents receiving care in NL.
Contains information on each hospital admission recorded in a Nova Scotia hospital
The Discharge Abstract Database is a database for information on all separation from acute care institutions within a fiscal year (April 1st to March 31st). Data is received directly from acute care facilities or from their respective health/regional authority or ministry/department of health.
Captures administrative, clinical and demographic information on discharges for acute care facilities (including deaths, sign-outs and transfers).
"""
def keyword_extract(doc, kw_model, n_grams, save_output='results/'):
keyword_onegram = kw_model.extract_keywords(doc, top_n=10, keyphrase_ngram_range=(1, n_grams), stop_words=None)
words = list(zip(*keyword_onegram))[0]
scores = list(zip(*keyword_onegram))[1]
keyword_df = pd.DataFrame({'words': words, 'scores': scores})
plt.title("Word Count")
plt.figure(figsize=(24, 8))
plt.yticks(fontsize=15)
sns.barplot(data=keyword_df, y='words', x='scores', palette='blend:#7AB,#EDA')
plt.xlabel("scores", fontsize=15)
plt.ylabel("words", fontsize=15)
plt.savefig(save_output, dpi=300, bbox_inches="tight")
plt.close()
if __name__ == '__main__':
kw_model = KeyBERT()
keyword_extract(test_doc, kw_model, 1)
keyword_extract(test_doc, kw_model, 2)
keyword_extract(test_doc, kw_model, 3)
keywords = kw_model.extract_keywords(test_doc, highlight=True)
print(keywords)