Skip to content

Instantly share code, notes, and snippets.

View pranjalAI's full-sized avatar

Pranjal Saxena pranjalAI

View GitHub Profile
# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model(generator)
tflite_model = converter.convert()
class ResidualSep(nn.Module):
def __init__(self, channels, dilation=1):
super().__init__()
self.blocks = nn.Sequential(
nn.ReLU(),
nn.ReflectionPad2d(dilation),
nn.Conv2d(channels, channels, kernel_size=3, stride=1,
padding=0, dilation=dilation,
groups=channels, bias=False),
class ResidualHourglass(nn.Module):
def __init__(self, channels, mult=0.5):
super().__init__()
hidden_channels = int(channels * mult)
self.blocks = nn.Sequential(
nn.ReLU(),
# Downsample
nn.ReflectionPad2d(1),
class TransformerNet(torch.nn.Module):
def __init__(self, width=8):
super().__init__()
self.blocks = nn.Sequential(
nn.ReflectionPad2d(1),
nn.Conv2d(3, width, kernel_size=3, stride=1, padding=0, bias=False),
nn.BatchNorm2d(width, affine=True),
ResidualHourglass(channels=width),
ResidualHourglass(channels=width),
links=[]
pubs=["swlh",'illumination','analytics-vidhya','better-advice','the-post-grad-survival-guide','the-ascent']
stop_words = set(stopwords.words('english'))
for pub in pubs:
links.append("https://medium.com/"+str(pub)+"/latest")
pub_links={}
for link in links:
response = requests.get(link)
soup = BeautifulSoup(response.text, "lxml" )
data = soup.find('div', class_ = 'js-postListHandle')
my_data=data.find('div',class_ = 'js-postListHandle')
final_data=my_data.find_all('div',{'class':'postArticle-content'})
Alinks=[]
for Alink in final_data:
href=Alink.find("a").get('href').split("?")[0]
response = requests.get(data_link)
soup = BeautifulSoup(response.text, "lxml" )
para=soup.find_all("p")
head1=soup.find_all("h1")
head2=soup.find_all("h2")
head3=soup.find_all("h3")
text=[]
for paragraph in para:
text.append(paragraph.text)
for header1 in head1:
text.append(header1.text)
for header2 in head2:
text.append(header2.text)
for header3 in head3:
text.append(header3.text)
doc = processArti(content)
doc = tokenize(doc)
doc = [wd for wd in doc if wd not in stop_words]
doc = sorted(set(doc))
doc = " ".join(doc)
doc = tokens(doc)
doc = removeNum(doc)
doc = [i for i in doc if not i==""]
doc = " ".join(doc)
for pub in pubs:
for data_link in pub_links[pub]:
doc=get_doc(data_link)
to_add = pd.DataFrame({"publication":[pub],"article":[doc]})
data=data.append(to_add, ignore_index = True)