Skip to content

Instantly share code, notes, and snippets.

View mayurmorin's full-sized avatar
🎯
Focusing

MAYUR PETHANI mayurmorin

🎯
Focusing
  • FEATHERLIGHT
View GitHub Profile
def question(request, question_id):
question = get_object_or_404(Question, pk=question_id)
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = AnswerForm(request.POST)
if form.is_valid():
content = form.cleaned_data.get('answer')
if len(content) > 20:
from django.shortcuts import get_object_or_404, render, redirect
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse
from .models import Question, Essay
from .forms import AnswerForm
from .utils.model import *
from .utils.helpers import *
from sklearn.cross_validation import KFold
from sklearn.linear_model import LinearRegression
from sklearn.metrics import cohen_kappa_score
cv = KFold(len(X), n_folds=5, shuffle=True)
results = []
y_pred_list = []
count = 1
from keras.layers import Embedding, LSTM, Dense, Dropout, Lambda, Flatten
from keras.models import Sequential, load_model, model_from_config
import keras.backend as K
def get_model():
"""Define the model."""
model = Sequential()
model.add(LSTM(300, dropout=0.4, recurrent_dropout=0.4, input_shape=[1, 300], return_sequences=True))
model.add(LSTM(64, recurrent_dropout=0.4))
model.add(Dropout(0.5))
import numpy as np
import nltk
import re
from nltk.corpus import stopwords
from gensim.models import Word2Vec
def essay_to_wordlist(essay_v, remove_stopwords):
"""Remove the tagged labels and word tokenize the sentence."""
essay_v = re.sub("[^a-zA-Z]", " ", essay_v)
words = essay_v.lower().split()
Importing the Data
#!pip install -U gensim
#!pip install -U nltk
#!python -m nltk.downloader punkt
#!python -m nltk.downloader stopwords
#!pip install django
!pip install django-widget-tweaks
Collecting django-widget-tweaks
Downloading https://files.pythonhosted.org/packages/eb/16/86c8fdbc774c97a93028846cef1ddbe4f3ebb1ff933b54aed920cf619bf4/django_widget_tweaks-1.4.3-py2.py3-none-any.whl
menpo 0.8.1 has requirement matplotlib<2.0,>=1.4, but you'll have matplotlib 2.2.3 which is incompatible.
Importing the Data
#!pip install -U gensim
#!pip install -U nltk
#!python -m nltk.downloader punkt
#!python -m nltk.downloader stopwords
#!pip install django
!pip install django-widget-tweaks
Collecting django-widget-tweaks
Downloading https://files.pythonhosted.org/packages/eb/16/86c8fdbc774c97a93028846cef1ddbe4f3ebb1ff933b54aed920cf619bf4/django_widget_tweaks-1.4.3-py2.py3-none-any.whl
menpo 0.8.1 has requirement matplotlib<2.0,>=1.4, but you'll have matplotlib 2.2.3 which is incompatible.
{
"pipeline": "spacy_sklearn",
"path":"./models/nlu",
"data":"./data/data.json"
}
{
"text": "Hello",
"intent": "greet",
"entities": []
},
{
"text": "goodbye",
"intent": "goodbye",
"entities": []
},