This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |