Skip to content

Instantly share code, notes, and snippets.

View santhalakshminarayana's full-sized avatar

Santha Lakshmi Narayana santhalakshminarayana

View GitHub Profile
tot_pairs = len(co_occ_matrix)
p1, p2,occs = list(), list(), list()
for i in co_occ_matrix.keys():
p1.append(i[0])
p2.append(i[1])
occs.append(co_occ_matrix[i])
p1 = np.array(p1)
p2 = np.array(p2)
occs = np.array(occs)
@santhalakshminarayana
santhalakshminarayana / Quotes_similarity_score.py
Created January 6, 2020 06:17
Quotes Similarity Score - Medium
co_occ_matrix = defaultdict(int)
window = 5 # not greater than 5
for sent in quotes:
words = sent.split(' ')
# first window
for i in range(0, window):
for j in range(i+1, window):
weight = 1/(j-i)
ind_1 = word_to_int[words[i]]
ind_2 = word_to_int[words[j]]
@santhalakshminarayana
santhalakshminarayana / Quotes_vocab_prep.py
Created January 6, 2020 06:05
Quotes Vocabulary Prep - Medium
words_dict = dict()
def unique_words(data_list):
for x in data_list:
for word in x.split(' '):
words_dict[word] = 1
return words_dict.keys()
words = list(unique_words(quotes))
words.sort()
@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