提交 f952497d 编写于 作者: W wangjiawei04 提交者: MRXLT

modify lac python script

上级 4032f9b9
wget --no-check-certificate https://paddle-serving.bj.bcebos.com/lac/lac_model.tar.gz
tar -zxvf lac_model.tar.gz
wget --no-check-certificate https://paddle-serving.bj.bcebos.com/lac/lac_model_jieba_web.tar.gz
tar -zxvf lac_model_jieba_web.tar.gz
......@@ -22,7 +22,7 @@ import io
client = Client()
client.load_client_config(sys.argv[1])
client.connect(["127.0.0.1:9280"])
client.connect(["127.0.0.1:9292"])
reader = LACReader(sys.argv[2])
for line in sys.stdin:
......
......@@ -99,3 +99,30 @@ class LACReader(object):
words = sent.strip()
word_ids = self.word_to_ids(words)
return word_ids
def parse_result(self, words, crf_decode):
tags = [
self.id2label_dict[str(x)] for x in crf_decode
]
sent_out = []
tags_out = []
partial_word = ""
for ind, tag in enumerate(tags):
if partial_word == "":
partial_word = words[ind]
tags_out.append(tag.split('-')[0])
continue
if tag.endswith("-B") or (tag == "O" and tag[ind - 1] != "O"):
sent_out.append(partial_word)
tags_out.append(tag.split('-')[0])
partial_word = words[ind]
continue
partial_word += words[ind]
if len(sent_out) < len(tags_out):
sent_out.append(partial_word)
return sent_out
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册