Skip to content

Instantly share code, notes, and snippets.

View Adilmar's full-sized avatar
:octocat:
Hi !

Adilmar Coelho Dantas Adilmar

:octocat:
Hi !
View GitHub Profile
@Adilmar
Adilmar / classify.py
Created October 23, 2019 13:45
Classify Images - CNN
import tensorflow as tf
import sys
# change this as you see fit
#image_path = sys.argv[1]
image_path = 'teste2.jpg'
# read in the image_data
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
@Adilmar
Adilmar / retrain.txt
Created October 23, 2019 13:08
Retrain Inception V3
python retrain.py --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps 4000 --model_dir=tf_files/inception --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir tf_files/images
@Adilmar
Adilmar / chat-bot-response3.py
Created June 16, 2019 02:50
chat-bot-response3
context = {}
ERROR_THRESHOLD = 0.25
def classify(sentence):
results = model.predict([bow(sentence, words)])[0]
results = [[i,r] for i,r in enumerate(results) if r>ERROR_THRESHOLD]
results.sort(key=lambda x: x[1], reverse=True)
return_list = []
for r in results:
return_list.append((classes[r[0]], r[1]))
@Adilmar
Adilmar / chat-bot-response2.py
Created June 16, 2019 02:42
Chatbot Response 2
def clean_up_sentence(sentence):
# tokenizando frases
sentence_words = nltk.word_tokenize(sentence)
# stem
sentence_words = [stemmer.stem(word.lower()) for word in sentence_words]
return sentence_words
def bow(sentence, words, show_details=False):
sentence_words = clean_up_sentence(sentence)
bag = [0]*len(words)
@Adilmar
Adilmar / chat-bot-response1.py
Last active June 16, 2019 02:37
Chatbot response 1
# NLP
import nltk
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()
# importando bibliotecas
import numpy as np
import tflearn
import tensorflow as tf
import random
@Adilmar
Adilmar / predicit.py
Created May 14, 2019 17:04
Chatbot + Tensorflow
def clean_up_sentence(sentence):
# tokenize the pattern
sentence_words = nltk.word_tokenize(sentence)
# stem each word
sentence_words = [stemmer.stem(word.lower()) for word in sentence_words]
return sentence_words
# return bag of words array: 0 or 1 for each word in the bag that exists in the sentence
def bow(sentence, words, show_details=False):
# tokenize the pattern
@Adilmar
Adilmar / save.py
Created May 14, 2019 16:27
Chatbot + Tensorflow - save model
# save all of our data structures
import pickle
pickle.dump( {'words':words, 'classes':classes, 'train_x':train_x, 'train_y':train_y}, open( "training_data", "wb" ) )
@Adilmar
Adilmar / neural.py
Created May 14, 2019 15:57
Chatbot+ Tensorflow - neural network
# reset underlying graph data
tf.reset_default_graph()
# Build neural network
net = tflearn.input_data(shape=[None, len(train_x[0])])
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, 8)
net = tflearn.fully_connected(net, len(train_y[0]), activation='softmax')
net = tflearn.regression(net)
# Define model and setup tensorboard
@Adilmar
Adilmar / training.py
Created May 14, 2019 13:25
Chatbot + Tensorflow
# create our training data
training = []
output = []
# create an empty array for our output
output_empty = [0] * len(classes)
# training set, bag of words for each sentence
for doc in documents:
# initialize our bag of words
bag = []
@Adilmar
Adilmar / document.py
Created May 13, 2019 19:52
Chatbot+Tensorflow - document
words = []
classes = []
documents = []
ignore_words = ['?']
# loop through each sentence in our intents patterns
for intent in intents['intents']:
for pattern in intent['patterns']:
# tokenize each word in the sentence
w = nltk.word_tokenize(pattern)
# add to our words list