I am trying to follow Google video to create a Q&A system with Vertex AI. (https://www.youtube.com/watch?v=5iSmX8sqtx8)
But it is suck that the video didn’t come with any source code or github repo. So, I typed the codes by myself and I am newbie to Python and TF
Here is my code:
import numpy as np
import tensorflow as tf
import tensorflow_hub as hub
from tensorflow import keras
class CustomModel(keras.Model):
def __init__(self):
super(CustomModel, self).__init__()
module = hub.load('https://tfhub.dev/google/universal-sentence-encoder-qa/3')
self.encoder = module.signatures['question_encoder']
self.built = True
def call(self, inputs):
print(inputs)
print(self.encoder)
return self.encoder(input=inputs)['outputs']
model = CustomModel()
model(tf.constant(["this is hello world"]))
model.save('path_to_my_model')
And the error happened at model.save
AssertionError: Called a function referencing variables which have been deleted. This likely means that function-local variables were created and not referenced elsewhere in the program. This is generally a mistake; consider storing variables in an object attribute on first call.
Anyone can help?