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
# 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) |
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 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')) |
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
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 |
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
sort = sorted(prep_dict.items(), key = lambda d:(d[1],d[0]), reverse=True) | |
sort[:10] |
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
# 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: | |
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
# 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 |
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
# 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) |
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
# 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} |
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
# 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) |
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
# 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} |