Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24 bert improvements #25

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %%
"""
This script is used to perform topic analysis on the data from the MSE and Buildhub forums,
focusing on the mentions of "heat pump" related keywords.
Expand Down Expand Up @@ -27,6 +28,7 @@
from asf_public_discourse_home_decarbonisation.utils.topic_analysis_utils import (
create_bar_plot_most_common_topics,
get_outputs_from_topic_model,
distribution_of_length_outliers_and_others,
)

# %% [markdown]
Expand All @@ -41,57 +43,14 @@
bh_data = get_bh_data(category="all", collection_date="24_02_01")

# %%
# Replacing abbreviations
mse_data["title"] = mse_data["title"].apply(
lambda x: x.lower()
.replace("ashps", "air source heat pumps")
.replace("ashp", "air source heat pump")
.replace("gshps", "ground source heat pumps")
.replace("gshp", "ground source heat pump")
.replace("hps", "heat pumps")
.replace("hp", "heat pump")
.replace("ufh", "under floor heating")
)
mse_data["text"] = mse_data["text"].apply(
lambda x: x.lower()
.replace("ashps", "air source heat pumps")
.replace("ashp", "air source heat pump")
.replace("gshps", "ground source heat pumps")
.replace("gshp", "ground source heat pump")
.replace("hps", "heat pumps")
.replace("hp", "heat pump")
.replace("ufh", "under floor heating")
)
# Replacing abbreviations
bh_data["title"] = (
bh_data["title"]
.astype(str)
.apply(
lambda x: x.lower()
.replace("ashps", "air source heat pumps")
.replace("ashp", "air source heat pump")
.replace("gshps", "ground source heat pumps")
.replace("gshp", "ground source heat pump")
.replace("hps", "heat pumps")
.replace("hp", "heat pump")
.replace("ufh", "under floor heating")
)
)
bh_data["text"] = (
bh_data["text"]
.astype(str)
.apply(
lambda x: x.lower()
.replace("ashps", "air source heat pumps")
.replace("ashp", "air source heat pump")
.replace("gshps", "ground source heat pumps")
.replace("gshp", "ground source heat pump")
.replace("hps", "heat pumps")
.replace("hp", "heat pump")
.replace("ufh", "under floor heating")
)
from asf_public_discourse_home_decarbonisation.pipeline.bert_topic_analysis.evaluate_bertopic_results import (
process_abbreviations,
)

# %%
mse_data = process_abbreviations(mse_data)
bh_data = process_abbreviations(bh_data)

# %%
mse_data["category"].unique()

Expand Down Expand Up @@ -123,15 +82,14 @@
topic_model = BERTopic(umap_model=umap_model)
topics, probs = topic_model.fit_transform(docs)


# %%
topics, topics_info, doc_info = get_outputs_from_topic_model(topic_model, docs)

# %%
topics_info.head()

# %%
doc_info.head()
distribution_of_length_outliers_and_others(doc_info)

# %%
create_bar_plot_most_common_topics(topics_info=topics_info, top_n_topics=16)
Expand Down Expand Up @@ -159,7 +117,6 @@
# %%
topic_model.visualize_term_rank()


# %%


Expand Down Expand Up @@ -188,7 +145,6 @@
topic_model = BERTopic(umap_model=umap_model)
topics, probs = topic_model.fit_transform(docs)


# %%
topics, topics_info, doc_info = get_outputs_from_topic_model(topic_model, docs)

Expand All @@ -198,6 +154,9 @@
# %%
doc_info.head()

# %%
distribution_of_length_outliers_and_others(doc_info)

# %%
create_bar_plot_most_common_topics(topics_info=topics_info, top_n_topics=16)

Expand Down
Loading