Skip to content

Instantly share code, notes, and snippets.

View AmrutaKoshe's full-sized avatar
💭
LIving in quarantine

Amruta Koshe AmrutaKoshe

💭
LIving in quarantine
View GitHub Profile
@AmrutaKoshe
AmrutaKoshe / pre.py
Last active June 24, 2021 13:27
Pre-processing resume
#pre-processing of data to remove special characters, hashtags, urls etc
import re
def cleanResume(resumeText):
resumeText = re.sub('http\S+\s*', ' ', resumeText) # remove URLs
resumeText = re.sub('RT|cc', ' ', resumeText) # remove RT and cc
resumeText = re.sub('#\S+', '', resumeText) # remove hashtags
resumeText = re.sub('@\S+', ' ', resumeText) # remove mentions
resumeText = re.sub('[%s]' % re.escape("""!"#$%&'()*+,-./:;<=>[email protected][\]^_`{|}~"""), ' ', resumeText) # remove punctuations
resumeText = re.sub(r'[^\x00-\x7f]',r' ', resumeText)
resumeText = re.sub('\s+', ' ', resumeText) # remove extra whitespace
@AmrutaKoshe
AmrutaKoshe / token.py
Created June 24, 2021 13:32
Tokenizing features
#tokenize features and labels
import tensorflow as tf
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.preprocessing.text import Tokenizer
# Tokenize feature data
vocab_size = 6000
oov_tok = '<>'
@AmrutaKoshe
AmrutaKoshe / label.py
Created June 24, 2021 13:34
Tokenizing labels
# Tokenize label data
label_tokenizer = Tokenizer(lower=True)
label_tokenizer.fit_on_texts(labels)
label_index = label_tokenizer.word_index
print(dict(list(label_index.items())))
# Print example label encodings from train and test datasets
train_label_sequences = label_tokenizer.texts_to_sequences(train_labels)
@AmrutaKoshe
AmrutaKoshe / sequential.py
Created June 24, 2021 13:35
Sequential model
#Train a sequential model
# Define the neural network
embedding_dim = 64
model = tf.keras.Sequential([
# Add an Embedding layer expecting input vocab of size 6000, and output embedding dimension of size 64 we set at the top
tf.keras.layers.Embedding(vocab_size, embedding_dim, input_length=1),
tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(embedding_dim)),
#tf.keras.layers.Dense(embedding_dim, activation='relu'),
@AmrutaKoshe
AmrutaKoshe / pred.py
Created June 25, 2021 17:20
Make predictions
# let's create an array containing the previous three examples to predict and use our model to get predictions
to_predict = [test_feature_padded[3],test_feature_padded[8],test_feature_padded[17]]
prediction = model.predict_classes(np.array(to_predict))
print(test_labels[3])
print(test_labels[8])
print(test_labels[17])
@AmrutaKoshe
AmrutaKoshe / import.py
Created July 4, 2021 10:11
import statements
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import wget
import os
!wget -N "https://cainvas-static.s3.amazonaws.com/media/user_data/AmrutaKoshe/dog_photos.zip"
!unzip -qo dog_photos.zip
Name=[]
for file in os.listdir(directory):
Name+=[file]
print(Name)
print(len(Name))
Breed = 'dog breed/Akita dog'
import os
sub_class = os.listdir(Breed)
fig = plt.figure(figsize=(10,5))
for e in range(len(sub_class[:10])):
plt.subplot(2,5,e+1)
img = plt.imread(os.path.join(Breed,sub_class[e]))
plt.imshow(img, cmap=plt.get_cmap('gray'))
plt.axis('off')