Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def infer(self, input, start_sign, max_seq_len=30, stop_sign=None, build_output=None):
"""
Inference API for given input
# Arguments
input: a sequence of data feed into encoder, eg: batch x seqLen x featureSize
start_sign: a ndarray which represents start and is fed into decoder
max_seq_len: max sequence length for final output
stop_sign: a ndarray that indicates model should stop infer further if current output
is the same with stopSign
build_output: Feeding model output to buildOutput to generate final result
"""
jinput, input_is_table = Layer.check_input(input)
assert not input_is_table
jstart_sign, start_sign_is_table = Layer.check_input(start_sign)
assert not start_sign_is_table
if stop_sign:
jstop_sign, stop_sign_is_table = Layer.check_input(stop_sign)
assert not start_sign_is_table
else:
jstop_sign = None
results = callZooFunc(self.bigdl_type, "seq2seqInfer",
self.value,
jinput[0],
jstart_sign[0],
max_seq_len,
jstop_sign[0] if jstop_sign else None,
build_output)
return results
def forward(self, y_true, y_pred):
"""
NB: It's for debug only, please use optimizer.optimize() in production.
Takes an input object, and computes the corresponding loss of the criterion,
compared with `target`
:param input: ndarray or list of ndarray
:param target: ndarray or list of ndarray
:return: value of loss
"""
input = y_pred
target = y_true
jinput, input_is_table = Layer.check_input(input)
jtarget, target_is_table = Layer.check_input(target)
output = callZooFunc(self.bigdl_type,
"criterionForward",
self.value,
jinput,
input_is_table,
jtarget,
target_is_table)
return output
def forward(self, input, target):
"""
NB: It's for debug only, please use optimizer.optimize() in production.
Takes an input object, and computes the corresponding loss of the criterion,
compared with `target`
:param input: ndarray or list of ndarray
:param target: ndarray or list of ndarray
:return: value of loss
"""
jinput, input_is_table = Layer.check_input(input)
jtarget, target_is_table = Layer.check_input(target)
output = callBigDlFunc(self.bigdl_type,
"criterionForward",
self.value,
jinput,
input_is_table,
jtarget,
target_is_table)
return output
def backward(self, y_true, y_pred):
"""
NB: It's for debug only, please use optimizer.optimize() in production.
Performs a back-propagation step through the criterion, with respect to the given input.
:param input: ndarray or list of ndarray
:param target: ndarray or list of ndarray
:return: ndarray
"""
input = y_pred
target = y_true
jinput, input_is_table = Layer.check_input(input)
jtarget, target_is_table = Layer.check_input(target)
output = callZooFunc(self.bigdl_type,
"criterionBackward",
self.value,
jinput,
input_is_table,
jtarget,
target_is_table)
return Layer.convert_output(output)
def infer(self, input, start_sign, max_seq_len=30, stop_sign=None, build_output=None):
"""
Inference API for given input
# Arguments
input: a sequence of data feed into encoder, eg: batch x seqLen x featureSize
start_sign: a ndarray which represents start and is fed into decoder
max_seq_len: max sequence length for final output
stop_sign: a ndarray that indicates model should stop infer further if current output
is the same with stopSign
build_output: Feeding model output to buildOutput to generate final result
"""
jinput, input_is_table = Layer.check_input(input)
assert not input_is_table
jstart_sign, start_sign_is_table = Layer.check_input(start_sign)
assert not start_sign_is_table
if stop_sign:
jstop_sign, stop_sign_is_table = Layer.check_input(stop_sign)
assert not start_sign_is_table
else:
jstop_sign = None
results = callZooFunc(self.bigdl_type, "seq2seqInfer",
self.value,
jinput[0],
jstart_sign[0],
max_seq_len,
jstop_sign[0] if jstop_sign else None,
build_output)
return results
def predict(self, inputs):
"""
Do prediction on inputs.
:param inputs: A numpy array or a list of numpy arrays or JTensor or a list of JTensors.
"""
jinputs, input_is_table = Layer.check_input(inputs)
output = callZooFunc(self.bigdl_type,
"inferenceModelPredict",
self.value,
jinputs,
input_is_table)
return KerasNet.convert_output(output)
def backward(self, y_true, y_pred):
"""
NB: It's for debug only, please use optimizer.optimize() in production.
Performs a back-propagation step through the criterion, with respect to the given input.
:param input: ndarray or list of ndarray
:param target: ndarray or list of ndarray
:return: ndarray
"""
input = y_pred
target = y_true
jinput, input_is_table = Layer.check_input(input)
jtarget, target_is_table = Layer.check_input(target)
output = callZooFunc(self.bigdl_type,
"criterionBackward",
self.value,
jinput,
input_is_table,
jtarget,
target_is_table)
return Layer.convert_output(output)
def forward(self, y_true, y_pred):
"""
NB: It's for debug only, please use optimizer.optimize() in production.
Takes an input object, and computes the corresponding loss of the criterion,
compared with `target`
:param input: ndarray or list of ndarray
:param target: ndarray or list of ndarray
:return: value of loss
"""
input = y_pred
target = y_true
jinput, input_is_table = Layer.check_input(input)
jtarget, target_is_table = Layer.check_input(target)
output = callZooFunc(self.bigdl_type,
"criterionForward",
self.value,
jinput,
input_is_table,
jtarget,
target_is_table)
return output
def backward(self, input, target):
"""
NB: It's for debug only, please use optimizer.optimize() in production.
Performs a back-propagation step through the criterion, with respect to the given input.
:param input: ndarray or list of ndarray
:param target: ndarray or list of ndarray
:return: ndarray
"""
jinput, input_is_table = Layer.check_input(input)
jtarget, target_is_table = Layer.check_input(target)
output = callBigDlFunc(self.bigdl_type,
"criterionBackward",
self.value,
jinput,
input_is_table,
jtarget,
target_is_table)
return Layer.convert_output(output)