Skip to content

Commit

Permalink
Use commas for numbers and don't ground the stats in the intro
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 01ccac3f20b2347951d77cb9cb4870228fd1ac42
  • Loading branch information
alyssachvasta authored and copybara-github committed Dec 18, 2024
1 parent b52fbb0 commit 2ab0a91
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
26 changes: 19 additions & 7 deletions src/sensemaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { summaryContainsStats } from "./tasks/stats_checker";
* @param errorMsg the error message to throw
* @param retryDelayMS how long to wait in miliseconds between calls
* @param funcArgs the args for func and isValid
* @param isValidArgs the args for isValid
* @returns the valid response from func
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
Expand All @@ -51,13 +52,14 @@ async function retryCall<T>(
maxRetries: number,
errorMsg: string,
retryDelayMS: number = RETRY_DELAY_MS,
...funcArgs: any[]
funcArgs: any[],
isValidArgs: any[]
) {
/* eslint-enable @typescript-eslint/no-explicit-any */
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await func(...funcArgs);
if (isValid(response, ...funcArgs)) {
if (isValid(response, ...isValidArgs)) {
return response;
}
console.error(`Attempt ${attempt} failed. Invalid response:`, response);
Expand Down Expand Up @@ -146,18 +148,27 @@ export class Sensemaker {
}
comments = await this.categorizeComments(comments, true, topics, additionalInstructions);
}
const summaryStats = new SummaryStats(comments);
const summary = await retryCall(
async function (model: Model, summaryStats: SummaryStats): Promise<string> {
async function (
model: Model,
summaryStats: SummaryStats,
summarizationType: SummarizationType
): Promise<string> {
return summarizeByType(model, summaryStats, summarizationType, additionalInstructions);
},
function (summary: string, summaryStats: SummaryStats): boolean {
function (
summary: string,
summaryStats: SummaryStats,
summarizationType: SummarizationType
): boolean {
return summaryContainsStats(summary, summaryStats, summarizationType);
},
MAX_RETRIES,
"The statistics don't match what's in the summary.",
undefined,
this.getModel("summarizationModel"),
new SummaryStats(comments)
[this.getModel("summarizationModel"), summaryStats, summarizationType],
[summaryStats, summarizationType]
);

return groundSummary(this.getModel("groundingModel"), summary, comments);
Expand Down Expand Up @@ -199,7 +210,8 @@ export class Sensemaker {
MAX_RETRIES,
"Topic modeling failed.",
undefined,
this.getModel("categorizationModel")
[this.getModel("categorizationModel")],
[]
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/tasks/grounding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ However, prefer marking segments of texts that identify atomic or singular claim
Do not ground topic and subtopics names (like "Infrastructure (5 comments)").
Do not ground claims about the number of total comments in the conversation or the number of total votes.
THIS IS IMPORTANT! Leave any portion of text from the original summary that does not need to be grounded alone. The overall structure of the summary text should not change, and all text, punctuation, indentation and aspects of markdown notation should be left as is. The only changes to the original text you should make are in the addition of brackets as described above.
Here is the summary for grounding:
Expand Down
10 changes: 6 additions & 4 deletions src/tasks/stats_checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ export function summaryContainsStats(
summaryStats: SummaryStats,
summarizationType: SummarizationType
): boolean {
if (!summary.includes(`${summaryStats.commentCount} comments`)) {
const commentCount = summaryStats.commentCount.toLocaleString();
if (!summary.includes(`${commentCount} comments`)) {
console.error(`Summary does not contain the correct number of total comments from the
deliberation. commentCount=${summaryStats.commentCount} and summary=${summary}`);
deliberation. commentCount=${commentCount} and summary=${summary}`);
return false;
}

const voteCount = summaryStats.voteCount.toLocaleString();
if (
summarizationType == SummarizationType.VOTE_TALLY &&
!summary.includes(`${summaryStats.voteCount} votes`)
!summary.includes(`${voteCount} votes`)
) {
console.error(`Summary does not contain the correct number of total votes from the
deliberation. voteCount=${summaryStats.voteCount} and summary=${summary}`);
deliberation. voteCount=${voteCount} and summary=${summary}`);
return false;
}

Expand Down
5 changes: 4 additions & 1 deletion src/tasks/summarization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export function getSummarizationInstructions(
const sortedTopics = _sortTopicsByComments(topicStats);
const quantifiedTopics = _quantifyTopicNames(sortedTopics);

const commentCount = summaryStats.commentCount.toLocaleString();
const voteCount = summaryStats.voteCount.toLocaleString();

return `You’re analyzing the results of a public deliberation on a topic. It contains comments and associated votes.
You will summarize with the summary having all of the following categories and subcategories:
Expand Down Expand Up @@ -68,7 +71,7 @@ ${includeGroups ? "## Description of Groups" : ""}
## Conclusion
The introduction should be one paragraph long and contain ${includeGroups ? "five" : "four"} sentences.
The first sentence should include the information that there were ${summaryStats.commentCount} comments ${includeGroups ? `that had ${summaryStats.voteCount} votes` : ""}.
The first sentence should include the information that there were ${commentCount} comments ${includeGroups ? `that had ${voteCount} votes` : ""}.
The second sentence should include what topics were discussed.
${
includeGroups
Expand Down

0 comments on commit 2ab0a91

Please sign in to comment.