Hi all, My first newbie topic here.
I am trying to generate a summary of a story using gpt3.5 API. It generates the summary well with some things I would like to exclude:
In the end it generates morale of the story
It generates information that is not present in the chapter. e.g. the name of the Authors
How to avoid the above 2?
My prompt:
messages= [{"role": "user", "content":f"Write a summary of the following:{chapter_content}"}]
Thanks, One more doubt, I was thinking to ask this in a new post, but anyway, here it is:
I am summarizing large text content of a book chapter. For that, I am creating chunks of text to adhere to the token limit of 4097. Then call summarizing prompt for each chunk. Question:
Is each API call for a single chunk new a Chat? I feel it is.
If the above is true, I am still getting a summarization of later chunks which contains some info from the previous chunk. How to avoid this. I want a summary of each chunk independently, i.e. don’t want the model to remember the previous context in successive API calls.
Thanks for the update. I have been using GPT for sometime as well and this was what worked the best for me.
Each API should be a chat, considering you are resending the whole prompt alongside it. I don not think it would remember the previous context but you can still instruct it to summarise only this text and do not explain further or add more details to explanations or something along this vein.
It depends on how you’re sending your prompt, which model endpoint you’re using, etc. With GPT-3.5-turbo, you’ll want a system and a user message. If you’re sizing the chunks right, you should only be able to send one and stay within the token limit.
Can we see the prompt or more details on how you’re sending to the API? If you’re not sending it, it shouldn’t summarize something it hasn’t seen. However, if it’s the same topic and same chapter, the summaries might be similar if the chunks aren’t large enough?
def create_summary(chunk):
response = openai.ChatCompletion.create(
model= "gpt-3.5-turbo",
messages= [{"role":"system", "content":"Follow these instructions when writing the summary:\n1. Do not explain the passage.\n2. Do not write title of the book.\n3. Do not write Author name.\n4. Do not use previous context.\n5. Write clear and concise summary."},
{"role": "user", "content":f"Write a summary of the following text:{chunk}\nDETAILED SUMMARY:"}],)
return [response['choices'][0]['message']['content'], response['usage']['prompt_tokens'],
response['usage']['completion_tokens'], response['usage']['total_tokens'],response['choices'][0]['finish_reason']]
Above is the API call prompt I make using for loop for each chunk:
for chunk in chapter_chunks:
summary1, token1, token2, token3,stop_reason = create_summary(
chunk)
These chunks should be treated as different chats then, according to my understanding. it might be simply because of the way you are tokenising it and then asking for the summary, some of the knowledge is seeping through due to the text being interlinked to each other and GPT trying to explain the summary. @PaulBellow might be able to expand a bit better on this.
Also because these are very popular books, possibly it also uses its own knowledge to generate summaries sometimes. (because even if the chunk does not contain the title or author of the book, it was generating these details in the summary)