Skip to content

Instantly share code, notes, and snippets.

View aniruddha27's full-sized avatar

Aniruddha Bhandari aniruddha27

View GitHub Profile
# Data generator
# For train data
train_datagen = ImageDataGenerator(rescale=1.0/255,
rotation_range=10,
width_shift_range=0.2,
height_shift_range=0.2,
horizontal_flip=True,
brightness_range=[0.4,0.9],
zoom_range=0.2)
# Model architechture
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(224, 224, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
from keras.models import Sequential
from keras.layers import Dropout, Flatten, Dense, Conv2D, MaxPooling2D, BatchNormalization
from keras.optimizers import SGD
import keras
from sklearn.model_selection import train_test_split
import cv2
sort = sorted(prep_dict.items(), key = lambda d:(d[1],d[0]), reverse=True)
sort[:10]
# Folder path
folders = glob.glob('./UNGD/UNGDC 1970-2018/Converted sessions/Session*')
# Dataframe
df = pd.DataFrame(columns={'Country','Speech','Session','Year'})
# Read speeches by India
i = 0
for file in folders:
# separate noun, preposition and noun
prep_dict = dict()
dis_dict = dict()
dis_list = []
# iterating over all the sentences
for i in range(len(df_show3)):
# sentence containing the output
# select non-empty outputs
df_show3 = pd.DataFrame(columns=df_rule3_all.columns)
for row in range(len(df_rule3_all)):
if len(df_rule3_all.loc[row,'Output'])!=0:
df_show3 = df_show3.append(df_rule3_all.loc[row,:])
# reset the index
df_show3.reset_index(inplace=True)
# create a df containing sentence and its output for rule 3
row_list = []
# df2 contains all the sentences from all the speeches
for i in range(len(df2)):
sent = df2.loc[i,'Sent']
year = df2.loc[i,'Year']
output = rule3(sent)
dict1 = {'Year':year,'Sent':sent,'Output':output}
# create a df containing sentence and its output for rule 3
row_list = []
for i in range(len(df3)):
sent = df3.loc[i,'Sent']
year = df3.loc[i,'Year']
# rule
output = rule3(sent)
# create a df containing sentence and its output for modified rule 1
row_list = []
# df2 contains all the sentences from all the speeches
for i in range(len(df2)):
sent = df2.loc[i,'Sent']
year = df2.loc[i,'Year']
output = rule1_mod(sent)
dict1 = {'Year':year,'Sent':sent,'Output':output}