paddlenlp
40 строк · 1.6 Кб
1# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import argparse16import json17
18import requests19
20parser = argparse.ArgumentParser()21parser.add_argument(22"--max_seq_len", default=128, type=int, help="The maximum total input sequence length after tokenization."23)
24parser.add_argument("--batch_size", default=2, type=int, help="Batch size per GPU/CPU for predicting.")25args = parser.parse_args()26
27url = "http://0.0.0.0:8189/models/cblue_ner"28headers = {"Content-Type": "application/json"}29
30if __name__ == "__main__":31texts = ["研究证实,细胞减少与肺内病变程度及肺内炎性病变吸收程度密切相关。", "可为不规则发热、稽留热或弛张热,但以不规则发热为多,可能与患儿应用退热药物导致热型不规律有关。"]32texts = [[x.lower() for x in text] for text in texts]33data = {34"data": {35"text": texts,36},37"parameters": {"max_seq_len": args.max_seq_len, "batch_size": args.batch_size, "is_split_into_words": True},38}39r = requests.post(url=url, headers=headers, data=json.dumps(data))40print(r.text)41