Skip to content

Commit

Permalink
Add ChatGPT summarization approach
Browse files Browse the repository at this point in the history
  • Loading branch information
HHousen committed Jul 23, 2023
1 parent 58d8640 commit daa5466
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 15 additions & 1 deletion lecture2notes/end_to_end/summarization_approaches.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,17 @@ def generic_extractive_sumy(

return " ".join(sentence_list)

def summarize_chatgpt(text, model="gpt-3.5-turbo"):
import openai
response = openai.ChatCompletion.create(
model=model,
messages=[
{"role": "user", "content": f"Can you provide a comprehensive summary of the given transcript? The summary should cover all the key points presented in the original transcript, while also condensing the information into a concise and easy-to-understand format. Please ensure that the summary includes relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition. The length of the summary should be appropriate for the length and complexity of the original transcript, providing a clear and accurate overview without omitting any important information. Write just the summary and nothing else. Do not reference the original transcript.\n\n{text}"},
]
)
summary = response["choices"][0]["message"]["content"]
return summary


def structured_joined_sum(
ssa_path,
Expand Down Expand Up @@ -884,9 +895,10 @@ def structured_joined_sum(
if summarization_method not in [
"abstractive",
"extractive",
"chatgpt",
"none",
]:
raise AssertionError("Invalid summarization method")
raise AssertionError(f"Invalid summarization method: {summarization_method}")

first_slide_frame_num = int(first_slide_frame_num)

Expand Down Expand Up @@ -1075,6 +1087,8 @@ def structured_joined_sum(
*args,
**kwargs
)
elif summarization_method == "chatgpt":
final_dict[title]["transcript"] = summarize_chatgpt(content)
else:
final_dict[title]["transcript"] = generic_extractive_sumy(
content, algorithm=ext_summarizer, *args, **kwargs
Expand Down
14 changes: 9 additions & 5 deletions lecture2notes/end_to_end/summarizer_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
cluster,
full_sents,
generic_abstractive,
summarize_chatgpt,
generic_extractive_sumy,
get_complete_sentences,
keyword_based_ext,
Expand Down Expand Up @@ -681,11 +682,14 @@ def step_summarize(self):
self.params.summarization_abs != "none"
and self.params.summarization_abs is not None
): # if abstractive method was specified
lecture_summarized = generic_abstractive(
summarized_ext,
self.params.summarization_abs,
hf_inference_api=self.params.abs_hf_api_overall,
)
if self.params.summarization_abs == "chatgpt":
lecture_summarized = summarize_chatgpt(summarized_ext, model="gpt-3.5-turbo-16k")
else:
lecture_summarized = generic_abstractive(
summarized_ext,
self.params.summarization_abs,
hf_inference_api=self.params.abs_hf_api_overall,
)
else: # if no abstractive summarization method was specified
lecture_summarized = summarized_ext
logger.debug("Skipping summarization_abs")
Expand Down

0 comments on commit daa5466

Please sign in to comment.