Skip to content

Instantly share code, notes, and snippets.

>>> 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,
>>> 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 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 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.'
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
states = list(indian_state['name'])
staff = list(indian_state['literacy_rate'])
staff_color = [i * 0.000045 for i in staff]
fig, ax = plt.subplots(figsize=(15, 8), dpi=100)
ax.barh(states, staff,align='center',
# width = 0.5,
color=cm.Blues([i / 0.006 for i in staff_color])
states = list(reddit_subgroup_df['subgroup'])
staff = list(reddit_subgroup_df['count'])
fig, ax = plt.subplots(figsize=(15, 8), dpi=800)
ax.bar(states, staff,align='center',
width = 0.5,
color=cm.Blues([i / 1000 for i in staff])
)
states = list(reddit_subgroup_df['subgroup'])
staff = list(reddit_subgroup_df['count'])
fig, ax = plt.subplots(figsize=(15, 8), dpi=400)
x = np.arange(len(states)) # the label locations
width = 0.35 # the width of the bars
rects1 = ax.bar(states, staff, width)
states = list(reuters_comment['trigram'])
staff = list(reuters_comment['count'])
staff_color = [i * 0.00045 for i in staff]
fig, ax = plt.subplots(figsize=(15, 8), dpi=100)
ax.barh(states, staff,align='center',
# width = 0.5,
color=cm.Blues([i / 0.006 for i in staff_color])
states = list(indian_state['name'])
staff = list(indian_state['literacy_rate'])
staff_color = [i * 0.000045 for i in staff]
fig, ax = plt.subplots(figsize=(15, 8), dpi=100)
ax.set_xlim(70, 100)
ax.barh(states, staff,align='center',
# width = 0.5,