Skip to content

Commit

Permalink
New citation format
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Edge committed Oct 21, 2024
1 parent 2d89b02 commit 75bc3c4
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 158 deletions.
13 changes: 7 additions & 6 deletions app/workflows/detect_case_patterns/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,7 @@ def create(sv: ap_variables.SessionVariables, workflow):
tdf = dcp.time_series_df
tdf = tdf[tdf["pattern"] == selected_pattern]
sv.detect_case_patterns_selected_pattern_df.value = tdf
sv.detect_case_patterns_selected_pattern_att_counts.value = (
dcp.compute_attribute_counts(
selected_pattern,
time_col,
)
)

count_ct = dcp.create_time_series_chart(
selected_pattern,
selected_pattern_period
Expand All @@ -266,6 +261,12 @@ def create(sv: ap_variables.SessionVariables, workflow):
else:
c1, c2 = st.columns([2, 3])
with c1:
sv.detect_case_patterns_selected_pattern_att_counts.value = (
dcp.compute_attribute_counts(
selected_pattern,
selected_pattern_period,
)
)
variables = {
"pattern": sv.detect_case_patterns_selected_pattern.value,
"period": sv.detect_case_patterns_selected_pattern_period.value,
Expand Down
118 changes: 62 additions & 56 deletions app/workflows/query_text_data/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,62 +162,68 @@ async def create(sv: SessionVariables, workflow=None):
st.warning(f"Process files to continue.")
else:
with st.expander("Options", expanded=False):
c1, c2, c3, c4, c5, c6, c7 = st.columns(7)
with c1:
st.number_input(
"Relevance test budget",
value=sv.relevance_test_budget.value,
key=sv.relevance_test_budget.key,
min_value=0,
help="The query method works by asking an LLM to evaluate the relevance of potentially-relevant text chunks, returning a single token, yes/no judgement. This parameter allows the user to cap the number of relvance tests that may be performed prior to generating an answer using all relevant chunks. Larger budgets will generally give better answers for a greater cost."
)
with c2:
st.number_input(
"Tests/topic/round",
value=sv.relevance_test_batch_size.value,
key=sv.relevance_test_batch_size.key,
min_value=0,
help="How many relevant tests to perform for each topic in each round. Larger values reduce the likelihood of prematurely discarding topics whose relevant chunks may not be at the top of the similarity-based ranking, but may result in smaller values of `Relevance test budget` being spread across fewer topics and thus not capturing the full breadth of the data."
)
with c3:
st.number_input(
"Restart on irrelevant topics",
value=sv.irrelevant_community_restart.value,
key=sv.irrelevant_community_restart.key,
min_value=0,
help="When this number of topics in a row fail to return any relevant chunks in their `Tests/topic/round`, return to the start of the topic ranking and continue testing `Tests/topic/round` text chunks from each topic with (a) relevance in the previous round and (b) previously untested text chunks. Higher values can avoid prematurely discarding topics that are relevant but whose relevant chunks are not at the top of the similarity-based ranking, but may result in a larger number of irrelevant topics being tested multiple times."
)
with c4:
st.number_input(
"Test relevant neighbours",
value=sv.adjacent_test_steps.value,
key=sv.adjacent_test_steps.key,
min_value=0,
help="If a text chunk is relevant to the query, then adjacent text chunks in the original document may be able to add additional context to the relevant points. The value of this parameter determines how many chunks before and after each relevant text chunk will be evaluated at the end of the process (or `Relevance test budget`) if they are yet to be tested."
)
with c5:
st.number_input(
"Target chunks per cluster",
value=sv.target_chunks_per_cluster.value,
key=sv.target_chunks_per_cluster.key,
min_value=0,
help="The average number of text chunks to target per cluster, which determines the text chunks that will be evaluated together and in parallel to other clusters. Larger values will generally result in more related text chunks being evaluated in parallel, but may also result in information loss from unprocessed content."
)
with c6:
st.radio(
label="Evidence type",
options=["Source text", "Extracted claims"],
key=sv.search_type.key,
help="If the evidence type is set to 'Source text', the system will generate an answer directly from the text chunks. If the search type is set to 'Extracted claims', the system will extract claims from the text chunks and generate an answer based on the extracted claims in addition to the source text.",
)
with c7:
st.number_input(
"Claim search depth",
value=sv.claim_search_depth.value,
key=sv.claim_search_depth.key,
min_value=0,
help="If the evidence type is set to 'Extracted claims', this parameter sets the number of most-similar text chunks to analyze for each extracted claim, looking for both supporting and contradicting evidence."
)
cl, cr = st.columns([5, 2])
with cl:
st.markdown("**Search options**")
c1, c2, c3, c4, c5 = st.columns(5)
with c1:
st.number_input(
"Relevance test budget",
value=sv.relevance_test_budget.value,
key=sv.relevance_test_budget.key,
min_value=0,
help="The query method works by asking an LLM to evaluate the relevance of potentially-relevant text chunks, returning a single token, yes/no judgement. This parameter allows the user to cap the number of relvance tests that may be performed prior to generating an answer using all relevant chunks. Larger budgets will generally give better answers for a greater cost."
)
with c2:
st.number_input(
"Tests/topic/round",
value=sv.relevance_test_batch_size.value,
key=sv.relevance_test_batch_size.key,
min_value=0,
help="How many relevant tests to perform for each topic in each round. Larger values reduce the likelihood of prematurely discarding topics whose relevant chunks may not be at the top of the similarity-based ranking, but may result in smaller values of `Relevance test budget` being spread across fewer topics and thus not capturing the full breadth of the data."
)
with c3:
st.number_input(
"Restart on irrelevant topics",
value=sv.irrelevant_community_restart.value,
key=sv.irrelevant_community_restart.key,
min_value=0,
help="When this number of topics in a row fail to return any relevant chunks in their `Tests/topic/round`, return to the start of the topic ranking and continue testing `Tests/topic/round` text chunks from each topic with (a) relevance in the previous round and (b) previously untested text chunks. Higher values can avoid prematurely discarding topics that are relevant but whose relevant chunks are not at the top of the similarity-based ranking, but may result in a larger number of irrelevant topics being tested multiple times."
)
with c4:
st.number_input(
"Test relevant neighbours",
value=sv.adjacent_test_steps.value,
key=sv.adjacent_test_steps.key,
min_value=0,
help="If a text chunk is relevant to the query, then adjacent text chunks in the original document may be able to add additional context to the relevant points. The value of this parameter determines how many chunks before and after each relevant text chunk will be evaluated at the end of the process (or `Relevance test budget`) if they are yet to be tested."
)
with c5:
st.number_input(
"Target chunks per cluster",
value=sv.target_chunks_per_cluster.value,
key=sv.target_chunks_per_cluster.key,
min_value=0,
help="The average number of text chunks to target per cluster, which determines the text chunks that will be evaluated together and in parallel to other clusters. Larger values will generally result in more related text chunks being evaluated in parallel, but may also result in information loss from unprocessed content."
)
with cr:
st.markdown("**Answer options**")
c6, c7 = st.columns([1, 1])
with c6:
st.radio(
label="Evidence type",
options=["Source text", "Extracted claims"],
key=sv.search_type.key,
help="If the evidence type is set to 'Source text', the system will generate an answer directly from the text chunks. If the search type is set to 'Extracted claims', the system will extract claims from the text chunks and generate an answer based on the extracted claims in addition to the source text.",
)
with c7:
st.number_input(
"Claim search depth",
value=sv.claim_search_depth.value,
key=sv.claim_search_depth.key,
min_value=0,
help="If the evidence type is set to 'Extracted claims', this parameter sets the number of most-similar text chunks to analyze for each extracted claim, looking for both supporting and contradicting evidence."
)
c1, c2 = st.columns([6, 1])
with c1:
st.text_input(
Expand Down
7 changes: 4 additions & 3 deletions toolkit/detect_case_patterns/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def generate_graph_model(df, period_col, type_val_sep):


def compute_attribute_counts(df, pattern, period_col, period, type_val_sep):
print(f"Computing attribute counts for pattern: {pattern} with period: {period} for period column: {period_col}")
atts = pattern.split(" & ")
# Combine astype and replace operations
fdf = df_functions.fix_null_ints(df)
fdf = fdf[fdf[period_col] == period]

# Pre-filter columns to avoid unnecessary processing
relevant_columns = [c for c in fdf.columns if c not in ["Subject ID", period_col]]
# fdf = fdf[["Subject ID", period_col, *relevant_columns]]
Expand All @@ -73,14 +73,15 @@ def compute_attribute_counts(df, pattern, period_col, period, type_val_sep):
)
melted = melted[melted["Value"] != ""]
melted["AttributeValue"] = melted["Attribute"] + type_val_sep + melted["Value"]

print(melted)
# Directly use nunique in groupby
return (
count_df = (
melted.groupby("AttributeValue")["Subject ID"]
.nunique()
.reset_index(name="Count")
.sort_values(by="Count", ascending=False)
)
return count_df


def create_time_series_df(model, pattern_df):
Expand Down
Loading

0 comments on commit 75bc3c4

Please sign in to comment.