Photo by Eugene Aikimov on Unsplash

Building A Summarisation Chatbot Using Cohere and Telegram

Cobus Greyling
6 min readJul 22, 2022

--

Introduction

Cohere Summarisation Examples & Code

!pip install cohereimport cohere
import time
import pandas as pd
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
co = cohere.Client(api_key)
prompt = '''"Cape Town is a port city on South Africa’s southwest coast, on a peninsula beneath the imposing Table Mountain. Slowly rotating cable cars climb to the mountain’s flat top, from which there are sweeping views of the city, the busy harbor and boats heading for Robben Island,the notorious prison that once held Nelson Mandela, which is now a living museum."
In summary:"'''
print(prompt)
n_generations = 4prediction = co.generate(
model='large',
prompt=prompt,
return_likelihoods = 'GENERATION',
stop_sequences=['"'],
max_tokens=50,
temperature=0.8,
num_generations=n_generations,
k=0,
p=0.75)
# Get list of generations
gens = []
likelihoods = []
for gen in prediction.generations:
gens.append(gen.text)
sum_likelihood = 0
for t in gen.token_likelihoods:
sum_likelihood += t.likelihood
# Get sum of likelihoods
likelihoods.append(sum_likelihood)
pd.options.display.max_colwidth = 200
# Create a dataframe for the generated sentences and their likelihood scores
df = pd.DataFrame({'generation':gens, 'likelihood': likelihoods})
# Drop duplicates
df = df.drop_duplicates(subset=['generation'])
# Sort by highest sum likelihood
df = df.sort_values('likelihood', ascending=False, ignore_index=True)
df

Telegram Integration

In Conclusion

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Cobus Greyling
Cobus Greyling

Written by Cobus Greyling

I’m passionate about exploring the intersection of AI & language. www.cobusgreyling.com

No responses yet

Write a response