def __call__(self, text, wid):
if text in self.__cache:
#trace('cache hit: ' + text)
return self.__cache[text]
#trace('cache new: ' + text)
self.__reset_state()
c_list = [XP.iarray([min(ord(c), 0x7f)]) for c in text]
x_list = [functions.tanh(self.c_x(c)) for c in c_list]
for x in x_list:
f = self.x_f(x)
for x in reversed(x_list):
b = self.x_b(x)
e = functions.tanh(self.w_e(XP.iarray([wid])) + self.f_e(f) + self.b_e(b))
self.__cache[text] = e
return e
评论列表
文章目录