|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
16 | 16 | import json
|
17 |
| -import time |
18 | 17 | import math
|
19 | 18 | import random
|
20 |
| -import numpy as np |
21 |
| -from tqdm import tqdm |
22 |
| - |
23 |
| -from urllib.request import urlopen |
24 |
| -from urllib.request import Request |
| 19 | +import time |
25 | 20 | from urllib.error import URLError
|
26 | 21 | from urllib.parse import urlencode
|
| 22 | +from urllib.request import Request, urlopen |
27 | 23 |
|
| 24 | +import numpy as np |
28 | 25 | import paddle
|
29 |
| - |
30 |
| -MODEL_MAP = { |
31 |
| - "uie-base": { |
32 |
| - "encoding_model": "ernie-3.0-base-zh", |
33 |
| - "resource_file_urls": { |
34 |
| - "model_state.pdparams": "https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base/model_state.pdparams", |
35 |
| - "model_config.json": "https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_base/model_config.json", |
36 |
| - }, |
37 |
| - }, |
38 |
| - "uie-tiny": { |
39 |
| - "encoding_model": "ernie-3.0-medium-zh", |
40 |
| - "resource_file_urls": { |
41 |
| - "model_state.pdparams": "https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_tiny/model_state.pdparams", |
42 |
| - "model_config.json": "https://bj.bcebos.com/paddlenlp/taskflow/information_extraction/uie_tiny/model_config.json", |
43 |
| - }, |
44 |
| - }, |
45 |
| -} |
| 26 | +from tqdm import tqdm |
46 | 27 |
|
47 | 28 |
|
48 | 29 | def set_seed(seed):
|
@@ -83,12 +64,12 @@ def mandarin_asr_api(api_key, secret_key, audio_file, audio_format="wav"):
|
83 | 64 | result_str = urlopen(request).read()
|
84 | 65 | except URLError as error:
|
85 | 66 | print("token http response http code : " + str(error.code))
|
86 |
| - result_str = err.read() |
| 67 | + result_str = error.read() |
87 | 68 | result_str = result_str.decode()
|
88 | 69 |
|
89 | 70 | result = json.loads(result_str)
|
90 | 71 | if "access_token" in result.keys() and "scope" in result.keys():
|
91 |
| - if SCOPE and (not SCOPE in result["scope"].split(" ")): |
| 72 | + if SCOPE and (SCOPE not in result["scope"].split(" ")): |
92 | 73 | raise ASRError("scope is not correct!")
|
93 | 74 | token = result["access_token"]
|
94 | 75 | else:
|
@@ -319,7 +300,7 @@ def convert_ext_examples(raw_examples, negative_ratio):
|
319 | 300 | entity_name_set = []
|
320 | 301 | predicate_set = []
|
321 | 302 |
|
322 |
| - print(f"Converting doccano data...") |
| 303 | + print("Converting doccano data...") |
323 | 304 | with tqdm(total=len(raw_examples)) as pbar:
|
324 | 305 | for line in raw_examples:
|
325 | 306 | items = json.loads(line)
|
@@ -402,13 +383,13 @@ def convert_ext_examples(raw_examples, negative_ratio):
|
402 | 383 | relation_prompts.append(relation_prompt)
|
403 | 384 | pbar.update(1)
|
404 | 385 |
|
405 |
| - print(f"Adding negative samples for first stage prompt...") |
| 386 | + print("Adding negative samples for first stage prompt...") |
406 | 387 | entity_examples = add_negative_example(entity_examples, texts, entity_prompts, entity_label_set, negative_ratio)
|
407 | 388 | if len(predicate_set) != 0:
|
408 |
| - print(f"Constructing relation prompts...") |
| 389 | + print("Constructing relation prompts...") |
409 | 390 | relation_prompt_set = construct_relation_prompt_set(entity_name_set, predicate_set)
|
410 | 391 |
|
411 |
| - print(f"Adding negative samples for second stage prompt...") |
| 392 | + print("Adding negative samples for second stage prompt...") |
412 | 393 | relation_examples = add_negative_example(
|
413 | 394 | relation_examples, texts, relation_prompts, relation_prompt_set, negative_ratio
|
414 | 395 | )
|
|
0 commit comments