MCPcopy Create free account
hub / github.com/baidu/lac / texts2tensor

Method texts2tensor

python/LAC/models.py:259–270  ·  view source on GitHub ↗

文本输入转为Paddle输入的Tensor

(self, texts)

Source from the content-addressed store, hash-verified

257 return result
258
259 def texts2tensor(self, texts):
260 """文本输入转为Paddle输入的Tensor"""
261 lod, data, words_length = [0], [], []
262 for i, text in enumerate(texts):
263
264 text_inds = self.dataset.word_to_ids(text)
265 data += text_inds
266 lod.append(len(text_inds) + lod[i])
267
268 tensor = self.to_tensor(data, lod) if len(data) != 0 else None
269
270 return tensor, words_length
271
272 def parse_result(self, lines, crf_decode, dataset, words_length):
273 """将SEG模型输出的Tensor转为明文"""

Callers

nothing calls this directly

Calls 2

word_to_idsMethod · 0.80
to_tensorMethod · 0.80

Tested by

no test coverage detected