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 apk(actual, predicted, k=3): | |
""" | |
Computes the average precision at k. | |
This function computes the average prescision at k between two lists of | |
items. | |
Parameters | |
---------- | |
actual : list | |
A list of elements that are to be predicted (order doesn't matter) | |
predicted : 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 numpy as np | |
import pandas as pd | |
from sklearn.metrics import f1_score | |
from copy import deepcopy | |
from collections import namedtuple | |
# Evaluation metric for Innoplexus NER Challenge | |
def collect_named_entities(tokens): # Helper Function for score calculation |
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
''' | |
# Baseline script by Supreet Manyam (Ziron) | |
''' | |
import pandas as pd | |
import numpy as np | |
import gc | |
train = pd.read_csv("data/train.csv", |
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 tensorflow as tf | |
x = tf.constant([1,2,3,4,5]) | |
y = tf.constant([1,1,1,1,1]) | |
a = tf.add(x,y) | |
print(a) |
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
try: | |
# %tensorflow_version only exists in Colab. | |
%tensorflow_version 2.x | |
except Exception: | |
pass |
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
# TensorFlow and tf.keras | |
import tensorflow as tf | |
from tensorflow import keras | |
# Helper libraries | |
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from tqdm import tqdm | |
from keras.preprocessing import image |
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 google.colab import drive | |
drive.mount('/content/drive') |
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
!unzip /content/drive/My\ Drive/train_LbELtWX.zip | |
train = pd.read_csv('train.csv') |
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
# We have grayscale images, so while loading the images we will keep grayscale=True, if you have RGB images, you should set grayscale as False | |
train_image = [] | |
for i in tqdm(range(train.shape[0])): | |
img = image.load_img('train/'+train['id'][i].astype('str')+'.png', target_size=(28,28,1), color_mode="grayscale") | |
img = image.img_to_array(img) | |
img = img/255 | |
train_image.append(img) | |
X = np.array(train_image) | |
# Preprocessing the Target |
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 Train and validation data to check the performance at each epoch | |
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, test_size=0.2) | |
# Using Keras Sequential API to add neural network layers | |
model = keras.Sequential() | |
model.add(keras.layers.Conv2D(32, kernel_size=(3, 3),activation='relu',input_shape=(28,28,1))) | |
model.add(keras.layers.Conv2D(64, (3, 3), activation='relu')) | |
model.add(keras.layers.MaxPooling2D(pool_size=(2, 2))) | |
model.add(keras.layers.Dropout(0.25)) | |
model.add(keras.layers.Flatten()) |
OlderNewer