Skip to content

Instantly share code, notes, and snippets.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
list1x = list(reddit_subgroup_name_df['subgroup'])
list1y = list(reddit_subgroup_name_df['positive'])
list1z = list(reddit_subgroup_name_df['negative'])
x = np.arange(len(list1x)) # the label locations
>>> from summarizer import TransformerSummarizer
>>> xlnet_model = TransformerSummarizer(transformer_type="XLNet",transformer_model_key="xlnet-base-cased")
>>> text = " ".join(comment_section)
>>> summerize = ''.join(xlnet_model(text, min_length=60, max_length=120))
>>> summerize
'You can also get one for your 60th wedding anniversary and possibly some others. Only those who apply get one.
you get one at 100 and one every year from 105.except there is no queen of england she died over 100 years ago.'
>>> from summarizer import TransformerSummarizer
>>> import re
>>> GPT2_model = TransformerSummarizer(transformer_type="GPT2",transformer_model_key="gpt2-medium")
>>> text = " ".join(comment_section)
>>> summerize = ''.join(GPT2_model(text, min_length=60, max_length=120))
>>> summerize
'The queen trolls her staff by leaving little bowls of snacks around the palace and marking the level of the snacks with a sharpie.
If the snacks dip below that level she starts trolling them about who ate her snacks.
The queen has a history of doing exactly that sort of thing in very sly ways.'
>>> from transformers import pipeline
>>> summarizer = pipeline('summarization', model='facebook/bart-large-cnn', tokenizer='facebook/bart-large-cnn')
>>> text = ".".join(comment_section)
>>> summarizer(text, min_length = round(0.1 * len(text.split(' '))), max_length = round(0.2 * len(text.split(' '))), do_sample=False)
[{'summary_text': "england would fall before there comes a day when the queen doesn't have tea.
She also regularly has wine with her meals. When someone gets to 100 years old in england they get a letter from the queen."}]
>>> from transformers import T5Tokenizer, T5ForConditionalGeneration
2020-11-10 18:10:11.206223: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1
>>> model = T5ForConditionalGeneration.from_pretrained('t5-base')
>>> tokenizer = T5Tokenizer.from_pretrained('t5-base')
>>> text = ".".join(comment_section)
>>> Preprocessed_text = "summarize: " + text
>>> tokens_input = tokenizer.encode(Preprocessed_text,return_tensors="pt", max_length=512, truncation=True)
>>> summary_ids = model.generate(tokens_input,
... min_length=60,
... max_length=180,
In [1]: import praw
In [2]: import re
In [3]: reddit = praw.Reddit(client_id='client id',
...: client_secret='client secret',
...: user_agent='user agent')
In [4]: top_posts = reddit.subreddit('showerthoughts').top('week', limit=1)
>>> from summarizer import TransformerSummarizer
>>> import re
>>> xlnet_model = TransformerSummarizer(transformer_type="XLNet",transformer_model_key="xlnet-base-cased")
>>> text = " ".join(tweet_data)
>>> TEXT_CLEANING_RE = "@\S+|https?:\S+|http?:\S|[^A-Za-z0-9]+"
>>> text = re.sub(TEXT_CLEANING_RE, ' ', str(text).lower()).strip()
>>> summerize = ''.join(xlnet_model(text, min_length=60, max_length=120))
>>> summerize
"The fixwithohimai and chidiodinkalu look ahead to tomorrow's presidential election. The uselections2020 overnight show will feature guests on both sides of the at trump s defeat.
A new poll shows potus leading in one of the most important swing states pennsylvania."
>>> from summarizer import TransformerSummarizer
>>> import re
>>> GPT2_model = TransformerSummarizer(transformer_type="GPT2",transformer_model_key="gpt2-medium")
>>> text = " ".join(tweet_data)
>>> TEXT_CLEANING_RE = "@\S+|https?:\S+|http?:\S|[^A-Za-z0-9]+"
>>> text = re.sub(TEXT_CLEANING_RE, ' ', str(text).lower()).strip()
>>> summerize = ''.join(GPT2_model(text, min_length=60, max_length=120))
>>> summerize
'Overnight show with me and a host of brilliant guests on both sides of the at trump s defeat will expose narendramodi to international censure change in the white house likely to force the in in a choice between a clown and a gaffe prone plagiarist tarred by his son s alleged corruption trump deserves th see a detailed map of'
>>> from transformers import pipeline
>>> summarizer = pipeline('summarization', model='facebook/bart-large-cnn', tokenizer='facebook/bart-large-cnn')
>>> text = " ".join(tweet_data)
>>> TEXT_CLEANING_RE = "@\S+|https?:\S+|http?:\S|[^A-Za-z0-9]+"
>>> text = re.sub(TEXT_CLEANING_RE, ' ', str(text).lower()).strip()
>>> summarizer(text, min_length = round(0.1 * len(text.split(' '))), max_length = round(0.2 * len(text.split(' '))), do_sample=False)
[{'summary_text': "Don't miss the most comprehensive non stop uselections2020 coverage on india s only global news channel wionews.
A reminder as you seek comfort food in the days ahead that calories don t count if you don't use a plate handtomouth.
A new poll shows potus leading in one of the most important swing states pennsylvania."}]
In [1]: import tweepy
In [2]: # Twitter API credentials
...: consumer_key = "consumer key"
...: consumer_secret = "consumer secret"
...: access_key = "access key"
...: access_secret = "access secret"
In [3]: auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
...: auth.set_access_token(access_key, access_secret)