Skip to content

Commit a0b9ff9

Browse files
committed
Minor edits
1 parent f8d45d5 commit a0b9ff9

5 files changed

Lines changed: 79 additions & 13 deletions

File tree

scripts/R/models_stats_dist.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ df_cso <- read.csv('~/PycharmProjects/SoftwareTopics/data/interim/taxonomy/cso_p
1515

1616
#target <- c("\\# Nodes", "\\# Edges", "\\# Leafs", "\\# Roots", "\\# Self Loops", "\\# Cycles", "\\# CC", "Pairs Acc", '\\# New Terms', "\\# Parents", "\\# Children", 'Density', 'Avg Eccentricity', 'Diameter', 'Max Parents', 'Max Children', "Avg Depth")
1717

18-
target <- c("\\# Nodes", '\\# New Terms', '\\# Unlinked', "\\# Edges", 'Density', "\\# Roots", "\\# Leaves", "Avg Parents", "Avg Children", 'Max Parents', 'Max Children', "Avg Depth", 'Diameter' ,"\\# Components", "\\# Loops", "\\# Cycles", 'Is DAG')
18+
target <- c("\\# Nodes", '\\# New Terms', '\\# Unlinked', "\\# Edges", 'Density', "\\# Roots", "\\# Leaves", "Avg Parents", "Avg Children", 'Max Parents', 'Max Children', "Avg Depth", 'Diameter' ,"\\# Components", "\\# Loops", "\\# Cycles")
1919

2020

2121
df_cso <- df_cso %>%
2222
filter(Metric %in% target) %>%
23+
mutate(Metric = replace(Metric, Metric == "\\# New Terms", '\\# New Nodes')) %>%
2324
mutate_at(c('Sim_Threshold', 'Value'), as.numeric)%>%
2425
mutate(LLM = replace(LLM, LLM == 'all-mpnet-base-v2', 'MP')) %>%
2526
mutate(LLM = replace(LLM, LLM == 'all-MiniLM-L6-v2', 'L6')) %>%
@@ -39,6 +40,7 @@ df_wiki$Max_Depth <- as.factor(df_wiki$Max_Depth)
3940

4041
df_wiki <- df_wiki %>%
4142
filter(Metric %in% target) %>%
43+
mutate(Metric = replace(Metric, Metric == "\\# New Terms", '\\# New Nodes')) %>%
4244
mutate_at(c('Value'), as.numeric) %>%
4345
unite("processing", cycle:bridge:abstract:minimization, remove = FALSE, sep=', ') %>%
4446
mutate(Metric = gsub(r"(\\)", "", Metric)) %>%
@@ -54,6 +56,7 @@ df_llm <- read.csv('~/PycharmProjects/SoftwareTopics/data/interim/taxonomy/LLM_p
5456

5557
df_llm <- df_llm %>%
5658
filter(Metric %in% target) %>%
59+
mutate(Metric = replace(Metric, Metric == "\\# New Terms", '\\# New Nodes')) %>%
5760
unite("processing", cycle:bridge:abstract:minimization, remove = FALSE, sep=', ') %>%
5861
mutate(Metric = gsub(r"(\\)", "", Metric)) %>%
5962
mutate_at(c('Value'), as.numeric) %>%
@@ -68,6 +71,7 @@ df_llm_iter <- read.csv('~/PycharmProjects/SoftwareTopics/data/interim/taxonomy/
6871

6972
df_llm_iter <- df_llm_iter %>%
7073
filter(Metric %in% target) %>%
74+
mutate(Metric = replace(Metric, Metric == "\\# New Terms", '\\# New Nodes')) %>%
7175
unite("processing", cycle:bridge:abstract:minimization, remove = FALSE, sep=', ') %>%
7276
mutate(Metric = gsub(r"(\\)", "", Metric)) %>%
7377
mutate_at(c('Value'), as.numeric) %>%
@@ -90,7 +94,7 @@ df <- df %>%
9094
mutate(src = fct_relevel(src, 'CSO', 'Wiki', 'LLM', 'LLM_Iter')) %>%
9195
mutate(Metric = replace(Metric, Metric == '# CC', 'Components')) %>%
9296
mutate(Metric = factor(Metric,
93-
c("# Nodes", '# New Terms', '# Unlinked', "# Edges", 'Density', "# Roots", "# Leaves", "Avg Parents", 'Max Parents', "Avg Children", 'Max Children', "Avg Depth", 'Diameter' ,"# Components", "# Loops", "# Cycles", 'Is DAG')))
97+
c("# Nodes", '# New Nodes', '# Unlinked', "# Edges", 'Density', "# Roots", "# Leaves", "Avg Parents", 'Max Parents', "Avg Children", 'Max Children', "Avg Depth", 'Diameter' ,"# Components", "# Loops", "# Cycles", 'Is DAG')))
9498

9599
#c("# Nodes", "# Edges", "# Leafs", "# Roots", "# Bridges", "# Intermediate", "# Self Loops", "# Cycles", "Components", "Pairs Acc", '# New Terms', "# Parents", "# Children", 'Max Parents', 'Max Children', 'Density', 'Avg Eccentricity', 'Avg Depth', 'Diameter'))
96100

scripts/python/clean.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from entity.taxonomy import Taxonomy
2+
from processing import CycleRemovalProcessing
3+
4+
def clean():
5+
in_path = '/home/sasce/PycharmProjects/SoftwareTopics/src/pipeline/patched_gitranking_ensemble_patched_cascade_topsis_llm_gpt-4-1106-preview_prompt_type_patch.json'
6+
out_path = '/home/sasce/PycharmProjects/SoftwareTopics/src/pipeline/patched_gitranking_ensemble_patched_cascade_topsis_llm_gpt-4-1106-preview_prompt_type_patch_final.json'
7+
8+
taxonomy = Taxonomy().load(in_path)
9+
cycle = CycleRemovalProcessing()
10+
taxonomy = cycle.process(taxonomy)
11+
taxonomy = taxonomy.update()
12+
data = taxonomy.model_dump_json(indent=4)
13+
with open(out_path, 'w') as f:
14+
f.write(data)
15+
16+
17+
if __name__ == '__main__':
18+
clean()

scripts/python/correct_stats.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pandas as pd
2+
3+
4+
def stats():
5+
in_path = '/home/sasce/PycharmProjects/SoftwareTopics/data/result/software_taxonomy_validation_anonymized_merged_w_LLM.csv'
6+
7+
df = pd.read_csv(in_path)
8+
9+
"""Get count of pairs for each annotator. And also the percentage"""
10+
annotator_counts = df.groupby('annotator').size().reset_index(name='counts')
11+
annotator_counts = annotator_counts.assign(percentage=annotator_counts['counts'] / len(df) * 100)
12+
annotator_counts.to_csv('../../data/result/annotator_counts.csv', index=False)
13+
14+
"""For each annotator get the percentage of is_correct column"""
15+
annotator_stats = df.groupby('annotator').agg({'is_correct': 'mean'}).reset_index()
16+
annotator_stats.to_csv('../../data/result/annotator_stats.csv', index=False)
17+
18+
"""Drop the rows that have 99 as annotator"""
19+
df = df[df['annotator'] != 99]
20+
21+
"""Group by the columns term,hypernym and then sum over the is_correct column and percentage"""
22+
df = df.groupby(['term', 'hypernym']).agg({'is_correct': 'sum'}).reset_index()
23+
df = df.assign(percentage=df['is_correct'] / len(df) * 100)
24+
"""If the is_correct column is greater than 3 replace it with ≥3"""
25+
df = df.assign(is_correct=df['is_correct'].apply(lambda x: '>3' if x > 3 else x))
26+
27+
out_path = '../../data/result/annotation_stats.csv'
28+
df.to_csv(out_path, index=False)
29+
30+
"""Count each group of is_correct column and percentage"""
31+
stats = df.groupby('is_correct').size().reset_index(name='counts')
32+
stats = stats.assign(percentage=stats['counts'] / len(df) * 100)
33+
stats.to_csv('../../data/result/annotation_stats_counts.csv', index=False)
34+
35+
if __name__ == '__main__':
36+
stats()

src/pipeline/evaluation_metrics.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def compute_metrics(cfg: DictConfig):
4040
metrics_rename.update(function.columns_rename)
4141

4242
for folder in folders:
43+
if 'temp' not in str(folder):
44+
continue
4345
files = [x for x in folder.iterdir() if x.suffix == '.json']
4446
metrics = []
4547
for file in tqdm(files, desc=folder.stem):
@@ -50,7 +52,10 @@ def compute_metrics(cfg: DictConfig):
5052
pairs = [(x[0], x[1]) for x in taxonomy.pairs]
5153
g = nx.DiGraph()
5254
g.add_edges_from(pairs)
53-
row = format_params(taxonomy.other['params'])
55+
row = format_params(taxonomy.other['params']) if 'params' in taxonomy.other or not taxonomy.other else {'name': file.stem.split('_')[-1]}
56+
57+
row = {'name': file.stem.split('_')[-1]}
58+
print(row)
5459
logger.info(f"Processing {file.stem}")
5560
if 'processed' in folder.stem:
5661
pp.update(taxonomy.other['post_processing'])
@@ -66,8 +71,9 @@ def compute_metrics(cfg: DictConfig):
6671
metrics.append(row)
6772

6873
df = pd.DataFrame(metrics)
69-
sort_columns = list(format_params(taxonomy.other['params']).keys())
70-
df.sort_values(by=sort_columns, ascending=True, inplace=True)
74+
if 'params' in taxonomy.other:
75+
sort_columns = list(format_params(taxonomy.other['params']).keys())
76+
df.sort_values(by=sort_columns, ascending=True, inplace=True)
7177

7278
if 'Sim Threshold' in df.columns:
7379
df['Sim Threshold'] = df['Sim Threshold'].astype(float)
@@ -89,20 +95,22 @@ def compute_metrics(cfg: DictConfig):
8995
df.to_csv(folder / 'metrics.csv', index=False)
9096

9197
metrics_name = [x for x in metrics_rename.values() if x in df.columns]
92-
header_order = list(format_params(taxonomy.other['params']).keys()) + pp_names + metrics_name
93-
df.sort_values(by=list(format_params(taxonomy.other['params']).keys()) + pp_names, ascending=True,
98+
if 'params' in taxonomy.other:
99+
header_order = list(format_params(taxonomy.other['params']).keys()) + pp_names + metrics_name
100+
df.sort_values(by=list(format_params(taxonomy.other['params']).keys()) + pp_names, ascending=True,
94101
inplace=True)
95102

96-
df = df[header_order]
103+
df = df[header_order]
97104
df.to_latex(folder / 'metrics.tex', index=False,
98105
escape=False, float_format="{:.2f}".format,
99106
header=['\\rot{{' + x + '}}' for x in df.columns])
100107

101-
id_vars = list(format_params(taxonomy.other['params']).keys()) + pp_names
102-
header_rename = {x: str(x).replace(" ", "_") for x in id_vars}
103-
df.rename(columns=header_rename, inplace=True)
108+
if 'params' in taxonomy.other:
109+
id_vars = list(format_params(taxonomy.other['params']).keys()) + pp_names
110+
header_rename = {x: str(x).replace(" ", "_") for x in id_vars}
111+
df.rename(columns=header_rename, inplace=True)
104112

105-
melted = df.melt(id_vars=header_rename.values(),
113+
melted = df.melt(id_vars='name',
106114
value_vars=metrics_name,
107115
var_name='Metric', value_name='Value')
108116
melted.to_csv(folder / 'melted_metrics.csv', index=False)

src/processing/cycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def process(self, taxonomy: Taxonomy) -> Taxonomy:
3737
logger.info(f"Number of removed edges: {len(removed)}")
3838
for loop_edge in removed:
3939
self.graph.remove_edge(*loop_edge)
40-
40+
assert nx.is_directed_acyclic_graph(self.graph)
4141
inverse_exists = [int(self.graph.has_edge(b, a)) for a, b in removed]
4242
percentage = sum(inverse_exists) / (len(inverse_exists)+1) * 100
4343
removed = [[a, b, z] for (a, b), z in zip(removed, inverse_exists)]

0 commit comments

Comments
 (0)