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

**URL:** <https://meta.discourse.org/t/summarising-topics-with-an-llm-gpt-bert/254951>\
**Category:** Feature\
**Created:** [February 13, 2023, 6:27am UTC](https://meta.discourse.org/t/summarising-topics-with-an-llm-gpt-bert/254951 "2023-02-13T06:27:55Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [February 18, 2023, 10:08am UTC](https://meta.discourse.org/t/summarising-topics-with-an-llm-gpt-bert/254951/4 "2023-02-18T10:08:52Z")

</div>

FWIW:

```python
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

---

_[View the full topic](https://meta.discourse.org/t/summarising-topics-with-an-llm-gpt-bert/254951)._
