How to use the redisai.BlobTensor.from_numpy function in redisai

To help you get started, we’ve selected a few redisai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RedisAI / redisai-examples / python_client / torch_chatbot / redis_db.py View on Github external
def process(self, nparray, length):
        tensor = rai.BlobTensor.from_numpy(nparray)
        self.con.tensorset('sentence', tensor)
        length_tensor = rai.BlobTensor.from_numpy(length)
        self.con.tensorset('length', length_tensor)
        self.con.modelrun('encoder', input=['sentence', 'length'], output=['e_output', 'd_hidden'])
        sos_tensor = rai.BlobTensor.from_numpy(
            np.array(utils.SOS_token, dtype=np.int64).reshape(1, 1))
        self.con.tensorset('d_input', sos_tensor)
        i = 0
        out = []
        while i < self.max_len:
            i += 1
            self.con.modelrun(
                'decoder',
                input=['d_input', 'd_hidden', 'e_output'],
                output=['d_output', 'd_hidden'])
            d_output = self.con.tensorget('d_output', as_type=rai.BlobTensor).to_numpy()
            d_output_ret = d_output.reshape(1, utils.voc.num_words)
            ind = int(d_output_ret.argmax())