Summarising topics with an LLM (GPT, BERT, ...)?

FWIW:

import openai
import requests
from bs4 import BeautifulSoup

openai.api_key = "KEY"

url = "https://meta.discourse.org/t/summarising-topics-with-an-llm-gpt-bert/254951.json"

response = requests.get(url)
data = response.json()

messages = []
messages.append("Title: " + data["title"])
for post in data['post_stream']['posts']:
    soup = BeautifulSoup(post['cooked'], 'html.parser')
    messages.append("Post #" + str(post["post_number"]) + " by " + post["username"])
    messages.append(soup.get_text())

text_blob = "\n".join(messages)

print(text_blob)

max_chunk_len = 4000  # Maximum length of each chunk

chunks = [text_blob[i:i+max_chunk_len] for i in range(0, len(text_blob), max_chunk_len)]

summaries = []
for chunk in chunks:
    print("processing chunk")
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt="prompt:\n" + chunk + "\nsummary:",
        temperature=0.7,
        max_tokens=200,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0
    )
    summary = response.choices[0].text.strip()
    print("\nSUMMARY")
    print(summary)
    print("\nSUMMARY")

Discourse is exploring the possibility of using an LLM such as GPT-3 or BERT to summarize long threads on demand. This feature would be configured with an openai key and could be especially useful for private communities. The summarization would be inserted in the thread, with a link at the top and a feedback mechanism. The AI team is currently exploring this possibility and will update when they have something to show.

It’s interesting but reasonably uneven

9 Likes