title: Saving a really simple tensorFlow model
body: <p>I am in the process of creating a really simple tensor flow network as part of a Django/ React native web app, I have managed to create a training set which works and produces the following output when run with plt:</p>
  
  <p><a href="https://i.stack.imgur.com/6GcQm.png" rel="nofollow noreferrer">Training output</a></p>
  
  <p>However, as im a total noob when it comes to neural networks and Tensor Flow im finding saving this trained set challenging, I have tried saving using saver() and had a look at session but neither has really worked so far. What I want is to save this trained model so that i can use it in my application to match User entered questions(represented by integers) and pre-set answers. Also, I'm aware that the data is super basic and can easily be done by hardcoding the responses, this project is more about learning rather than getting reults in the most effecient way possible. Any feedback is really appreciated, source code listed below!</p>
  
  <h1>machine_learn.py</h1>
  
  <pre><code>def loss(self, predicted_y, desired_y):
      return tf.reduce_mean(tf.square(predicted_y - desired_y))    
  
  def train(self, model, inputs, outputs, learning_rate):
      with tf.GradientTape() as t:
          current_loss = self.loss(model(inputs), outputs)
  
      dQ = t.gradient(current_loss, model.Q)
      model.Q.assign_sub(learning_rate * dQ)
  
  def train_network(self, value_set):
      model = TrainingModel(value_set)
      desired_list = [4.00, 3.00, 2.00, 1.00]
      num_examples = 10000
      desired_ans = desired_list[0]
      inputs = tf.random_normal(shape=[num_examples])
      Qs = []
      epochs = range(150)
      for _ in epochs:
          Qs.append(model.Q.numpy())
          current_loss = self.loss(model.Q, desired_list)
          self.train(model, inputs, desired_list, 0.1)
          print(current_loss)
      plt.plot(epochs, Qs, 'r')
      plt.plot([desired_ans] * len(epochs), 'r--')
      plt.legend(['Q', 'true q'])
  
      plt.show()
  </code></pre>
  
  <h1>training_model.py</h1>
  
  <pre><code>class TrainingModel(object):
  
  def __init__(self, questions):
      self.questions = questions
      self.Q = tfe.Variable(questions)
  
  def __call__(self, inputs):
      return self.Q
  </code></pre>