Skip to content

Instantly share code, notes, and snippets.

View santhalakshminarayana's full-sized avatar

Santha Lakshmi Narayana santhalakshminarayana

View GitHub Profile
@santhalakshminarayana
santhalakshminarayana / Quotes_reading.py
Created January 6, 2020 05:59
Quotes Reading - Medium
quotes = []
max_len = 0
min_len = 5
sent_len_dic = defaultdict(int)
with open('quotes.txt', 'r') as f:
while True:
quote = f.readline()
if not quote:
break
words = quote.split(' ')
@santhalakshminarayana
santhalakshminarayana / web_scrapping_quotes_2.py
Created January 6, 2020 05:36
Web Scrapping 2 - Medium
def get_quotes(url):
i = 1
quotes = []
while True:
curr_quotes = []
quote_url = url + 'page-' + str(i) + '/'
i += 1
quote_r = requests.get(quote_url)
quote_soup = BeautifulSoup(quote_r.content, 'html5lib')
quote_list = quote_soup.find('div', attrs = {'class':'quote_list'})
@santhalakshminarayana
santhalakshminarayana / web_scrapping_quotes_1.py
Created January 6, 2020 05:30
Web scrapping 1 - Medium
import requests
from bs4 import BeautifulSoup
import re
import os
import time
home_url = 'http://www.wiseoldsayings.com'
r = requests.get(home_url)
soup = BeautifulSoup(r.content, 'html5lib')
quote_classes = []
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_generate_example.py
Created December 13, 2019 07:08
Indian Name Generator - Generator Example - Medium
text_count = 0
input_text = 'PRIYA'
while text_count < 50:
gen_text = generate(input_text)
gen_text = gen_text.strip('.')
if len(gen_text) > 6 and gen_text not in names:
text_count += 1
input_text = gen_text
print(gen_text)
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_name_generation.py
Last active December 13, 2019 07:07
Indian Name Generator - Name Generation - Medium
def generate(base_name):
if len(base_name):
base_name = base_name[:window]
x = np.zeros((1,window,len(int_to_char)))
seq_word = []
ind_list = [char_to_int[i] for i in base_name]
for i,ind in enumerate(ind_list):
x[0 ,i ,ind] = 1
seq_word.append(ind)
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_model.py
Created December 13, 2019 06:51
Indian Name Generator - Model - Medium
model = Sequential()
model.add(LSTM(units=32, recurrent_dropout=0.5, input_shape=(window, len(int_to_char))))
model.add(Dense(len(int_to_char), activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='adam')
model.fit(X, Y, batch_size=1024, epochs=10 ,steps_per_epoch=3000)
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_input_generation.py
Created December 13, 2019 06:29
Indian Name Generator - Input generation - Medium
X = np.zeros(shape = (len(sequences), window, len(int_to_char)))
Y = np.zeros(shape = (len(next_chars),len(int_to_char)))
for i in range(len(sequences)):
for j in range(window):
X[i, j, char_to_int[sequences[i][j]]] = 1
Y[i, char_to_int[next_chars[i]]] = 1
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_sequence_generation.py
Created December 13, 2019 06:03
Indian Name Genarator - Sequence Generation - Medium
sequences, next_chars = [], []
window = 5
for name in names:
if len(name) < window:
sequences.append(name+'.'*(window-len(name)))
next_chars.append('.')
seq_lengths.append(len(name))
else:
for i in range(0,len(name) - window + 1):
sequences.append(name[i:i+window])
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_group_names.py
Last active December 13, 2019 05:55
Indian Name Generator - Group names and unique chars - Medium
group_names = []
for name in names:
name_list = name.split(' ')
group_names.extend(name_list)
group_names = set(group_names)
unique_chars=set()
names = []
for name in group_names:
@santhalakshminarayana
santhalakshminarayana / Indian_Name_Generator_reading.py
Created December 13, 2019 05:22
Indian Name Generator - Reading - Medium
import pandas as pd
import numpy as np
names_df = pd.read_csv('Indian Names.txt',error_bad_lines=False)
names_df = names_df.drop_duplicates(keep='first').reset_index(drop=True)
names_df = np.squeeze(names_df).values.tolist()