🙇♂️
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
class TrieNode: | |
def __init__(self): | |
self.child = {} | |
self.last = False | |
class Trie: | |
def __init__(self): | |
self.root = TrieNode() | |
def insert(self, data): |
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
class TrieNode: | |
def __init__(self): | |
self.child = {} | |
self.last = False | |
class Trie: | |
def __init__(self): | |
self.root = TrieNode() | |
def insert(self, data): |
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
class TrieNode: | |
def __init__(self): | |
self.child = {} | |
self.last = False | |
class Trie: | |
def __init__(self): | |
self.root = TrieNode() | |
def insert(self, data): |
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
class TrieNode: | |
def __init__(self): | |
self.child = {} | |
self.last = False | |
class Trie: | |
def __init__(self): | |
self.root = TrieNode() | |
def insert(self, data): |
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
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) |
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 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'), |
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 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()) |
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 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: |
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 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], |
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
#!/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(): |