Paddle
Paddle copied to clipboard
使用python预测工具, 如果output是id类型会出错
序列标注模型预测的时候, 如果ouput layer是id类型的, 例如 crf_decoding 或者 maxid
if use_crf:
Layer(
name = "%s_label" % name_,
type = "crf_decoding",
size = slot_conf_dict[name_]['dim'],
inputs = [
Input("output_%s" % name_, parameter_name="crfw_%s" % name_),
]
)
else:
Layer(
name = "%s_label" % name_,
type = "maxid",
inputs = "output_%s" % name_,
)
forwardTest会出错
raceback (most recent call last):
File "deep_tagger_new_paddle.py", line 87, in <module>
outputs = do_tag(text, conf='output_tag')
File "deep_tagger_new_paddle.py", line 57, in do_tag
outputs_ = networks[0].forwardTest(inst_)
File "/home/aladdin/.jumbo/lib/python2.7/site-packages/py_paddle/util.py", line 149, in forwardTest
for i in xrange(outArgs.getSlotNum())
File "/home/aladdin/.jumbo/lib/python2.7/site-packages/py_paddle/util.py", line 89, in __arguments_to_numpy__
if ids is not None:
UnboundLocalError: local variable 'ids' referenced before assignment
如果输出是概率分布, e.g.,
Layer(
name = "output_%s" % name_,
type = "mixed",
active_type = "softmax",
size = slot_conf_dict[name_]['dim'],
bias = False,
inputs = [
FullMatrixProjection("decoder_state_final_%s" % name_),
]
)
则不会出错. 这是为什么呢?
diff --git a/paddle/py_paddle/util.py b/paddle/py_paddle/util.py
index 8ebcb34..e1f3105 100644
--- a/paddle/py_paddle/util.py
+++ b/paddle/py_paddle/util.py
@@ -82,10 +82,10 @@ class __ParameterCallbackWrapper__(swig_paddle.UpdateCallback):
def __arguments_to_numpy__(i, arg):
assert isinstance(arg, swig_paddle.Arguments)
value = arg.getSlotValue(i)
+ ids = arg.getSlotIds(i)
if value is not None:
assert isinstance(value, swig_paddle.Matrix)
value = value.copyToNumpyMat()
- ids = arg.getSlotIds(i)
if ids is not None:
assert isinstance(ids, swig_paddle.IVector)
ids = ids.copyToNumpyArray()
@linrongyi 先用这个patch修改一下那个util.py,看起来像是写bug了。不过,这个bug更像是一开始写对了,后来merge出错了。
完整的fix我尽快看一下,主要是得把这个单元测试补上,增加这段逻辑的覆盖。
恩, 改了一下util.py 可以了, 多谢
unittest not add