Skip to content

Instantly share code, notes, and snippets.

Avatar
🙇‍♂️
Working

Prakhar Mishra prakhar21

🙇‍♂️
Working
View GitHub Profile
@prakhar21
prakhar21 / flair_sentence_train.py
Created Jan 19, 2020
Flair Sentence Embeddings and Training a Classifier
View flair_sentence_train.py
document_embeddings = DocumentRNNEmbeddings(word_embeddings, hidden_size=512, reproject_words=True, reproject_words_dimension=256, rnn_type='LSTM', rnn_layers=1, bidirectional=False)
classifier = TextClassifier(document_embeddings, label_dictionary=corpus.make_label_dictionary(), multi_label=False)
trainer = ModelTrainer(classifier, corpus)
trainer.train('./model', max_epochs=20, patience=5, mini_batch_size=32, learning_rate=0.1)
View flair_embeddings.py
def initialize_embeddings():
"""
Summary:
Stacks the list of pre-trained embedding vectors to be used as word representation (in concat.)
Return:
list: Returns list of pretrained embeddings vectors
"""
word_embeddings = [
WordEmbeddings('glove'),
FlairEmbeddings('news-forward'),
View segment_data.py
def segment_data(data_file):
try:
import pandas as pd
except ImportError:
raise
data = pd.read_csv(data_file, encoding='latin-1').sample(frac=1).drop_duplicates()
data = data[['classes', 'title']].rename(columns={"classes":"label", "title":"text"})
data['label'] = '__label__' +data['label'].astype(str)
data['text'] = data['text'].apply(lambda k: k.lower().strip())
@prakhar21
prakhar21 / locustfile.py
Created Feb 16, 2019
Locust Load Testing
View locustfile.py
import random
import os
from locust import HttpLocust, TaskSet, task
TEST_DATA_PATH = 'test.csv'
def load_test_sentences():
utterances = []
with open(TEST_DATA_PATH, 'r') as fp:
for row in fp:
@prakhar21
prakhar21 / map.py
Created Jan 26, 2019
GeoSpatial Data Visualisation using Folium in Python
View map.py
import folium
from folium.plugins import MarkerCluster
city_latlong = {
'Agra': [27.1767, 78.0081], 'Ahmedabad': [23.0225, 72.5714], 'Durgapur': [23.5204, 87.3119],
'Aurangabad': [19.8762, 75.3433], 'Bengaluru': [12.9716, 77.5946], 'Bhopal': [23.2599, 77.4126],
'Coimbatore': [11.0168, 76.9558], 'Delhi': [28.7041, 77.1025], 'Dhanbad': [23.7957, 86.4304],
'Faridabad': [28.4089, 77.3178], 'Ghaziabad': [28.6692, 77.4538], 'Gwalior': [26.2183, 78.1828],
'Hyderabad': [17.3850, 78.4867], 'Indore': [22.7196, 75.8577], 'Jaipur': [26.9124, 75.7873],
'Jabalpur': [23.1815, 79.9864], 'Jamshedpur': [22.8046, 86.2029], 'Jodhpur': [26.2389, 73.0243],
View sample-flask-api.py
#!/usr/bin/env python
from flask import Flask, jsonify, request
import numpy as np
import pickle
app = Flask(__name__)
model_filepath = 'best_model.pickle'
def load_model():
@prakhar21
prakhar21 / api_call.py
Created Jan 23, 2019
Calling Flask API using Python
View api_call.py
import requests
import json
ENDPOINT = 'http://localhost:5555/predict'
response = requests.post(ENDPOINT, data=json.dumps(data), headers={'content-type': 'application/json'})
print (r.status_code)
print (r.json())
@prakhar21
prakhar21 / get_email.py
Created Oct 16, 2018
Fetching unseen emails and filtering by subject string
View get_email.py
#!/usr/bin/env python
import re
import smtplib
import time
import imaplib
import email
import sqlite3
import datetime
@prakhar21
prakhar21 / city_level_analysis.py
Created May 27, 2018
City Level Analysis using Zomato API
View city_level_analysis.py
#!/usr/bin/env python
import collections
import requests
import config
import get_collectionids
from operator import itemgetter
def send_request(parameters, api):
View top_exp_good.json
{
"Delhi": {
"rating": "4.3",
"votes": "3325",
"score": 14297.5,
"name": "Bukhara - ITC Maurya",
"cuisine": "North Indian, Kebab"
},
"Bangalore": {
"rating": "4.2",
You can’t perform that action at this time.