Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yvielcastillejos authored Nov 13, 2020
1 parent 0604f7c commit 2c10412
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 0 deletions.
Binary file added Neural Network/__pycache__/bot.cpython-38.pyc
Binary file not shown.
Binary file added Neural Network/__pycache__/model.cpython-38.pyc
Binary file not shown.
115 changes: 115 additions & 0 deletions Neural Network/get_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import random
import json
import torch
import torch
import torch.optim as optim
import matplotlib.pyplot as plt
import torchtext
from torchtext import data
import spacy
import pandas as pd
import numpy as np
import time
import torch.nn.utils.rnn as tnt
import sklearn
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix

# Download spacy
#!python -m spacy download en

# Get the data in tsv form

#device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
file = "/content/drive/My Drive/Colab Notebooks/Chat bot/intents.json"
path = "/content/drive/My Drive/Colab Notebooks/Chat bot"

data2 = dict()

def get_dataframe(filename):
global label
global tags
global labeldecode
with open(file, 'r') as json_data:
intents = json.load(json_data)

# Converting to dataframe
tags = []
patterns = []
patterns_full = []
for intent in intents['intents']:
tag = intent['tag']
# add to tag list
tags.append(tag)
for pattern in intent['patterns']:
patterns.append(pattern)
patterns_full.append(patterns)
patterns = []

label = []
# Label encode the labels
for i, tag in enumerate(tags):
label.append(i)

labeldecode = dict()
for i in range(len(label)):
labeldecode[label[i]] = tags[i]
print(labeldecode)

data1 = dict()
# Dictionary
print(len(patterns_full[0]))
for i in range(len(tags)):
for j in range(len(patterns_full[i])):
data1[str(patterns_full[i][j])] = int(label[i])

print(data1)
df = pd.DataFrame(list(data1.items()),columns = ['text','label'])
print(df)
print("=================================")
df.value_counts('label')
return df

df = get_dataframe(file)
print(label)
print(labeldecode)

train = df
validation = train
train.to_csv('/content/drive/My Drive/Colab Notebooks/Chat bot/train.tsv', sep='\t', index=False)
validation.to_csv('/content/drive/My Drive/Colab Notebooks/Chat bot/valid.tsv', sep='\t', index=False)




# Get data in tabular and bucket iterator form by tokenizing it

TEXT = data.Field(sequential=True, lower=True, tokenize='spacy', include_lengths=True)
LABELS = data.Field(sequential=False, use_vocab=False)
def Tokenize(path):
global TEXT
TEXT = data.Field(sequential=True, lower=True, tokenize='spacy', include_lengths=True)
global LABELS
LABELS = data.Field(sequential=False, use_vocab=False)
train_data, val_data = data.TabularDataset.splits( path=path, train='train.tsv',
validation='valid.tsv', format='tsv', skip_header=True,
fields=[('text', TEXT), ('label', LABELS)])

train_iter, val_iter = data.BucketIterator.splits((train_data, val_data),
batch_sizes=(9, 9),
sort_key=lambda x: len(x.text),
device=None, sort_within_batch=True,
repeat=False)

return train_iter, val_iter, train_data, val_data

train_iter, val_iter, train_data, val_data = Tokenize(path)


# Build the vocab data

TEXT.build_vocab(train_data,val_data)
TEXT.vocab.load_vectors(torchtext.vocab.GloVe(name='6B', dim=100))
vocab = TEXT.vocab
print("Shape of Vocab:",TEXT.vocab.vectors.shape)
82 changes: 82 additions & 0 deletions Neural Network/intents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"intents": [
{
"tag": "greeting",
"patterns": [
"Hi",
"What's cracking",
"How've you been?",
"How have you been",
"Hey",
"How are you",
"Is anyone there?",
"Hello",
"Good day",
"Good afternoon",
"Good Morning",
"Hello",
"Good day",
"Howdy",
"What's up",
"Yo",
"Hey there",
"Sup",
"Good to see you",
"Happy to see you"

],
"responses": [
"Hey :-)",
"Hello, thanks for visiting",
"Hi there, what can I do for you?",
"Hi there, how can I help?"
]
},
{
"tag": "goodbye",
"patterns": ["I’m out of here","See ya", "I will see you then","Peace","Peace out","Take Care", "I look forward to our next meeting","Until Then","Have a nice day","I’m off"," I’ve got to get going", "I must be going","Bye","Bye Bye", "See you later", "See you soon", "Talk to you later", "See you later", "Goodbye"],
"responses": [
"See you later, thanks for visiting",
"Have a nice day",
"Bye! Come back again soon."
]
},
{
"tag": "thanks",
"patterns": ["Thanks", "Thank you", "Thank you so much","That's helpful", "Thank's a lot!", "Okay", "Thank thee", "Thank you, you're amazing!", "Thank you kindly", "I’m so thankful for everything you bring to the table", " Thanks a million", "I truly appreciate your hard work", "I truly appreciate you", " From the bottom of my heart, thank you", " Please accept my deepest thanks"
,"Grateful for your support", " I appreciate your thoughtfulness, you’ve made my day!", "Thanks for being in my corner", " Please accept my deepest thanks"],
"responses": ["Happy to help!", "Any time!", "My pleasure"]
},
{
"tag": "bad",
"patterns": [
"You suck so much ",
" I hate you so much",
"You are so bad", "Suck my Suck my","Why are you so bad at this", "You don't help", "You make me want to die", "You are just awful","You are ugly", "F You so much", "You are a retard", "You are very stupid",
"You are lame", "Shut up bastard", "You tick me off", "You are an idiot", "You are lame", "Shut up bastard", "You tick me off", "You are an idiot", "You are a fool", "You are not funny"
],
"responses": [
"Oh Okay...",
"I'm sorry",
"Sorry",
"I didn't mean to be bad, sorry"
]
},
{
"tag": "funny",
"patterns": [
"Tell me a joke!",
"Tell me something funny!",
"Do you know a joke?",
"joke joke joke", "Give me a joke", "Joke to me", "What is funny", "How about a joke",
"Tell me something random", "Give me something funny", "Tell me a random joke",
"What is really funny", "Tell me an anecdote", "Tell me a funny story", "make me laugh",
"I want to laugh", "Can you make me laugh?", "What can make me laugh"
],
"responses": [
"Why did the hipster burn his mouth? He drank the coffee before it was cool.",
"What did the buffalo say when his son left for college? Bison.", "joke joke joke", "What did the Cannibal get when he arrived to the party late? A cold shoulder", "What does a mermaid wear to her math class? An Algae Bra"
]
}
]
}
Binary file added Neural Network/model_cnn.pt
Binary file not shown.
91 changes: 91 additions & 0 deletions Neural Network/train.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
text label
Hi 0
What's cracking 0
How've you been? 0
How have you been 0
Hey 0
How are you 0
Is anyone there? 0
Hello 0
Good day 0
Good afternoon 0
Good Morning 0
Howdy 0
What's up 0
Yo 0
Hey there 0
Sup 0
Good to see you 0
Happy to see you 0
I’m out of here 1
See ya 1
I will see you then 1
Peace 1
Peace out 1
Take Care 1
I look forward to our next meeting 1
Until Then 1
Have a nice day 1
I’m off 1
I’ve got to get going 1
I must be going 1
Bye 1
Bye Bye 1
See you later 1
See you soon 1
Talk to you later 1
Goodbye 1
Thanks 2
Thank you 2
Thank you so much 2
That's helpful 2
Thank's a lot! 2
Okay 2
Thank thee 2
Thank you, you're amazing! 2
Thank you kindly 2
I’m so thankful for everything you bring to the table 2
Thanks a million 2
I truly appreciate your hard work 2
I truly appreciate you 2
From the bottom of my heart, thank you 2
Please accept my deepest thanks 2
Grateful for your support 2
I appreciate your thoughtfulness, you’ve made my day! 2
Thanks for being in my corner 2
You suck so much 3
I hate you so much 3
You are so bad 3
Suck my Suck my 3
Why are you so bad at this 3
You don't help 3
You make me want to die 3
You are just awful 3
You are ugly 3
F You so much 3
You are a retard 3
You are very stupid 3
You are lame 3
Shut up bastard 3
You tick me off 3
You are an idiot 3
You are a fool 3
You are not funny 3
Tell me a joke! 4
Tell me something funny! 4
Do you know a joke? 4
joke joke joke 4
Give me a joke 4
Joke to me 4
What is funny 4
How about a joke 4
Tell me something random 4
Give me something funny 4
Tell me a random joke 4
What is really funny 4
Tell me an anecdote 4
Tell me a funny story 4
make me laugh 4
I want to laugh 4
Can you make me laugh? 4
What can make me laugh 4
91 changes: 91 additions & 0 deletions Neural Network/valid.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
text label
Hi 0
What's cracking 0
How've you been? 0
How have you been 0
Hey 0
How are you 0
Is anyone there? 0
Hello 0
Good day 0
Good afternoon 0
Good Morning 0
Howdy 0
What's up 0
Yo 0
Hey there 0
Sup 0
Good to see you 0
Happy to see you 0
I’m out of here 1
See ya 1
I will see you then 1
Peace 1
Peace out 1
Take Care 1
I look forward to our next meeting 1
Until Then 1
Have a nice day 1
I’m off 1
I’ve got to get going 1
I must be going 1
Bye 1
Bye Bye 1
See you later 1
See you soon 1
Talk to you later 1
Goodbye 1
Thanks 2
Thank you 2
Thank you so much 2
That's helpful 2
Thank's a lot! 2
Okay 2
Thank thee 2
Thank you, you're amazing! 2
Thank you kindly 2
I’m so thankful for everything you bring to the table 2
Thanks a million 2
I truly appreciate your hard work 2
I truly appreciate you 2
From the bottom of my heart, thank you 2
Please accept my deepest thanks 2
Grateful for your support 2
I appreciate your thoughtfulness, you’ve made my day! 2
Thanks for being in my corner 2
You suck so much 3
I hate you so much 3
You are so bad 3
Suck my Suck my 3
Why are you so bad at this 3
You don't help 3
You make me want to die 3
You are just awful 3
You are ugly 3
F You so much 3
You are a retard 3
You are very stupid 3
You are lame 3
Shut up bastard 3
You tick me off 3
You are an idiot 3
You are a fool 3
You are not funny 3
Tell me a joke! 4
Tell me something funny! 4
Do you know a joke? 4
joke joke joke 4
Give me a joke 4
Joke to me 4
What is funny 4
How about a joke 4
Tell me something random 4
Give me something funny 4
Tell me a random joke 4
What is really funny 4
Tell me an anecdote 4
Tell me a funny story 4
make me laugh 4
I want to laugh 4
Can you make me laugh? 4
What can make me laugh 4

0 comments on commit 2c10412

Please sign in to comment.