from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf # from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np neg = open( r'F:\havingnewinPython\machineLearning\Sandextutorial\DeepLearning\neg.txt' ) pos = open( 'F:\havingnewinPython\machineLearning\Sandextutorial\DeepLearning\pos.txt', 'r') train_x, train_y, test_x, test_y = create_feature_sets_and_labels(neg, pos) n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = { 'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = {
# Youtube video: https://www.youtube.com/watch?list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v&time_continue=1&v=6rDWwL6irG0 from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf # from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np # Data files are downloaded from: # Positive data: https://pythonprogramming.net/static/downloads/machine-learning-data/pos.txt # Negative data: https://pythonprogramming.net/static/downloads/machine-learning-data/neg.txt pos_file = 'data/pos.txt' neg_file = 'data/neg.txt' pickle_file = 'data/sentiment_set.pickle' train_x, train_y, test_x, test_y = create_feature_sets_and_labels(pos_file, neg_file) n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = {'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1]))}
from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf # from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels( '/home/alon/PycharmProjects/cnn-text-classification-tf/data/rt-polaritydata/rt-polarity.pos', '/home/alon/PycharmProjects/cnn-text-classification-tf/data/rt-polaritydata/rt-polarity.neg' ) n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = { 'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = { 'f_fum': n_nodes_hl2, 'weight': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])),
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from create_sentiment_featuresets import create_feature_sets_and_labels import numpy as np trainX, trainY, testX, testY = create_feature_sets_and_labels( 'pos.txt', 'neg.txt') numNodesHL1 = 1500 numNodesHL2 = 1500 numNodesHL3 = 1500 numClasses = 2 batchSize = 100 x = tf.placeholder('float') y = tf.placeholder('float') hiddenLayer1 = { 'f_fum': numNodesHL1, 'weight': tf.Variable(tf.random_normal([len(trainX[0]), numNodesHL1])), 'bias': tf.Variable(tf.random_normal([numNodesHL1])) } hiddenLayer2 = { 'f_fum': numNodesHL2, 'weight': tf.Variable(tf.random_normal([numNodesHL1, numNodesHL2])), 'bias': tf.Variable(tf.random_normal([numNodesHL2])) } hiddenLayer3 = { 'f_fum': numNodesHL3, 'weight': tf.Variable(tf.random_normal([numNodesHL2, numNodesHL3])),
import tensorflow as tf from create_sentiment_featuresets import create_feature_sets_and_labels import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels( "pos.txt", "neg.txt") """ Feed forward: Input > weight > hiddenlayer 1 (activationfunction) > weight > hiddenlayer 2 (activation function) > weights > output layer Compare output to intended output > cost function (cross entropy) Back propogation: Optimization function (optimizer) > minimize the cost (AdamOptimizer, Stochastic gradient descent, AdaGrad) """ # Nodes in the hidden layers n_nodes_hl1 = 1000 n_nodes_hl2 = 1000 n_nodes_hl3 = 1000 n_classes = 2 batch_size = 100 X = tf.placeholder('float', [None, len(train_x[0])]) # Label y = tf.placeholder('float') hidden_1_layer = { 'weights': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])),
more likely we'd get better results. The act of sending the data straight through our network means we're operating a feed forward neural network. The adjustments of weights backwards is our back propagation. We do feeding forward and back propagation however many times we want. The cycle is called an Epoch. We can pick any number for number of epochs. After each epoch, we've hopefully further fine-tuned our weights lowering our cost and improving accuracy. ''' # one_hot means one eleent out of others is literally "hot" or on. This is useful for a # in the case of sentiment prediction, it's either positive or negative # sentiments, so we will model output as # positive = [1,0] # negative = [0,1] train_x, train_y, test_x, test_y = create_feature_sets_and_labels( 'ident_nn_pos.txt', 'ident_nn_neg.txt') ''' in building the model, we consider the number of nodes each hidden layer will have. Nodes in each layer need not be identical, but it can be tweaked, depending on what we are trying to model (TBD). Batches are used to control how many features we are going to optimize at once, as computers are limited by memory. ''' n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 14
from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf # from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels( '/path/to/pos.txt') n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = { 'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = { 'f_fum': n_nodes_hl2, 'weight': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl2])) }
from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf #from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels( 'D:\Data\Desktop\pos.txt', 'D:\Data\Desktop\pos2.txt') n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = { 'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = { 'f_fum': n_nodes_hl2, 'weight': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl2])) }
Note: This script requires tensorflow, numpy dependencies to be installed ''' from create_sentiment_featuresets import create_feature_sets_and_labels from RecordAudioData import recordAudioTest from AudioToSpectrogram import getAudioData from AudioToSpectrogram import saveSpectrogramData from sklearn.preprocessing import LabelEncoder from sklearn.preprocessing import OneHotEncoder import tensorflow as tf import numpy as np from numpy import argmax import os orginal_path = os.getcwd() train_x, train_y, test_x, test_y, lexicon = create_feature_sets_and_labels() n_classes = 10 batch_size = 10 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') def conv2d(x, W): return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') def maxpool2d(x): # size of window movement of window
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data from create_sentiment_featuresets import create_feature_sets_and_labels import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels('/Users/surthi/gitrepos/tensorflow/ml-data/pos.txt', '/Users/surthi/gitrepos/tensorflow/ml-data/neg.txt') num_nodes_hl1 = 500 num_nodes_hl2 = 500 num_nodes_hl3 = 500 n_classes = 2 batch_size= 100 # x matrix size = height x width (None x 784). (784 = 28x28 image) x = tf.placeholder('float', [None, len(train_x[0])]) y = tf.placeholder('float') def nn_model(data): hidden_layer_1 = {'weights': tf.Variable(tf.random_normal([len(train_x[0]), num_nodes_hl1])), 'biases':tf.Variable(tf.random_normal([num_nodes_hl1]))} hidden_layer_2 = {'weights': tf.Variable(tf.random_normal([num_nodes_hl1, num_nodes_hl2])), 'biases':tf.Variable(tf.random_normal([num_nodes_hl2]))} hidden_layer_3 = {'weights': tf.Variable(tf.random_normal([num_nodes_hl2, num_nodes_hl3])), 'biases':tf.Variable(tf.random_normal([num_nodes_hl3]))} output_layer = {'weights': tf.Variable(tf.random_normal([num_nodes_hl3, n_classes])), 'biases':tf.Variable(tf.random_normal([n_classes]))} # (input_data * weights + biases) l1 = tf.add(tf.matmul(data, hidden_layer_1['weights']), hidden_layer_1['biases']) l1 = tf.nn.relu(l1) l2 = tf.add(tf.matmul(l1, hidden_layer_2['weights']), hidden_layer_2['biases'])
from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels( 'dataFiles/pos.txt', 'dataFiles/neg.txt') n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = { 'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = { 'f_fum': n_nodes_hl2, 'weight': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl2])) } hidden_3_layer = {
from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf # from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels('/home/alon/PycharmProjects/cnn-text-classification-tf/data/rt-polaritydata/rt-polarity.pos', '/home/alon/PycharmProjects/cnn-text-classification-tf/data/rt-polaritydata/rt-polarity.pos') n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = {'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1]))} hidden_2_layer = {'f_fum': n_nodes_hl2, 'weight': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl2]))} hidden_3_layer = {'f_fum': n_nodes_hl3, 'weight': tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl3]))}
import tensorflow as tf # from tensorflow.examples.tutorials.mnist import input_data # mnist = input_data.read_data_sets("/tmp/data/", one_hot = True) from create_sentiment_featuresets import create_feature_sets_and_labels import numpy as np train_x,train_y,test_x,test_y = create_feature_sets_and_labels('pos.txt','neg.txt') n_nodes_hl1 = 500 n_nodes_hl2 = 500 n_nodes_hl3 = 500 n_classes = 2 # m batch_size = 100 # height * width x = tf.placeholder('float',[None, len(train_x[0])]) # m y = tf.placeholder('float') def neural_network_model(data): # input_data * weights + biases # m // hidden_1_layer = {'weights':tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'biases':tf.Variable(tf.random_normal([n_nodes_hl1]))} # // m hidden_2_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'biases':tf.Variable(tf.random_normal([n_nodes_hl2]))} hidden_3_layer = {'weights':tf.Variable(tf.random_normal([n_nodes_hl2, n_nodes_hl3])),
import tensorflow as tf import numpy as np import os from create_sentiment_featuresets import create_feature_sets_and_labels BASE_FOLDER = os.path.abspath(os.path.dirname(__file__)) pos_path = os.path.join(BASE_FOLDER, "resources/pos.txt") neg_path = os.path.join(BASE_FOLDER, "resources/neg.txt") train_x, train_y, test_x, test_y = create_feature_sets_and_labels( pos_path, neg_path) # 10 classes, from 0 to 9 # 0 = [1,0,0,0,0,0,0,0,0,0] # 5 = [0,0,0,0,0,1,0,0,0,0] n_nodes_hl1 = 500 n_nodes_hl2 = 500 n_nodes_hl3 = 500 n_classes = 2 batch_size = 100 # height x width x = tf.placeholder('float', [None, len(train_x[0])]) y = tf.placeholder('float') def neural_network_model(data): hidden_1_layer = {
# coding: utf-8 # In[2]: from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf #from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np train_x,train_y,test_x,test_y = create_feature_sets_and_labels('/home/SMO/Documents/ML_Harrison_Python/pos.txt','/home/SMO/Documents/ML_Harrison_Python/neg.txt') n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = {'f_fum':n_nodes_hl1, 'weight':tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias':tf.Variable(tf.random_normal([n_nodes_hl1]))} hidden_2_layer = {'f_fum':n_nodes_hl2, 'weight':tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])),
import tensorflow as tf import numpy as np from create_sentiment_featuresets import create_feature_sets_and_labels train_x, train_y, test_x, test_y = create_feature_sets_and_labels( 'pos.txt', 'neg.txt') n_nodes_hl1 = 500 n_nodes_hl2 = 500 n_nodes_hl3 = 500 n_classes = 2 batch_size = 100 x = tf.placeholder('float', [None, len(train_x[0])]) y = tf.placeholder('float') def neural_network_model(data): hidden_1_layer = { 'weights': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'biases': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = { 'weights': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'biases': tf.Variable(tf.random_normal([n_nodes_hl2])) } hidden_3_layer = {
from create_sentiment_featuresets import create_feature_sets_and_labels import tensorflow as tf #from tensorflow.examples.tutorials.mnist import input_data import pickle import numpy as np train_x, train_y, test_x, test_y = create_feature_sets_and_labels( './samplefiles/positive.txt', './samplefiles/negetive.txt') n_nodes_hl1 = 1500 n_nodes_hl2 = 1500 n_nodes_hl3 = 1500 n_classes = 2 batch_size = 100 hm_epochs = 10 x = tf.placeholder('float') y = tf.placeholder('float') hidden_1_layer = { 'f_fum': n_nodes_hl1, 'weight': tf.Variable(tf.random_normal([len(train_x[0]), n_nodes_hl1])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl1])) } hidden_2_layer = { 'f_fum': n_nodes_hl2, 'weight': tf.Variable(tf.random_normal([n_nodes_hl1, n_nodes_hl2])), 'bias': tf.Variable(tf.random_normal([n_nodes_hl2])) }