import pandas as pd
import numpy as np
import tensorflow as tf
from collections import Counter
from sklearn.datasets import fetch_20newsgroups
How TensorFlow works
import tensorflow as tf
my_graph = tf.Graph()
with tf.Session(graph=my_graph) as sess:
x = tf.constant([1,3,6])
y = tf.constant([1,1,1])
op = tf.add(x,y)
result = sess.run(fetches=op)
print(result)
[2 4 7]
How to manipulate data and pass it to the Neural Network inputs
vocab = Counter()
text ="Hi from Brazil"for word in text.split(''):
word_lowercase = word.lower()
vocab[word_lowercase]+=1defget_word_2_index(vocab):
word2index = {}
for i,word inenumerate(vocab):
word2index[word] = i
return word2index
word2index = get_word_2_index(vocab)
total_words =len(vocab)
matrix = np.zeros((total_words),dtype=float)
for word in text.split():
matrix[word2index[word.lower()]] +=1print("Hi from Brazil:", matrix)