Skip to content

Commit d209d9a

Browse files
authored
Remove unnessasary load NER task of taskflow (#1135)
1 parent 1ea856e commit d209d9a

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

paddlenlp/taskflow/knowledge_mining.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def __init__(self, model, task, **kwargs):
145145
self._static_mode = False
146146
self._log_name = self.kwargs[
147147
'log_name'] if 'log_name' in self.kwargs else 'wordtag'
148+
self._linking = self.kwargs[
149+
'linking'] if 'linking' in self.kwargs else False
148150
term_schema_path = download_file(
149151
self._task_path, "termtree_type.csv", URLS['termtree_type'][0],
150152
URLS['termtree_type'][1], self._log_name)
@@ -156,9 +158,8 @@ def __init__(self, model, task, **kwargs):
156158
URLS['termtree_tags_pos'][1])
157159
self._tags_to_index, self._index_to_tags = self._load_labels(tag_path)
158160

159-
self._termtree = TermTree.from_dir(term_schema_path, term_data_path)
160-
self._linking = self.kwargs[
161-
'linking'] if 'linking' in self.kwargs else False
161+
self._termtree = TermTree.from_dir(term_schema_path, term_data_path,
162+
self._linking)
162163
self._construct_tokenizer(model)
163164
self._usage = usage
164165
self._summary_num = 2

paddlenlp/taskflow/utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,19 @@ def find_term(self, term: str, term_type: Optional[str]=None) -> Tuple[
420420
else:
421421
return False, None
422422

423-
def build_from_dir(self, term_schema_path, term_data_path):
423+
def build_from_dir(self, term_schema_path, term_data_path, linking=True):
424424
"""Build TermTree from a directory which should contain type schema and term data.
425425
426426
Args:
427427
dir ([type]): [description]
428428
"""
429429
self.__load_type(term_schema_path)
430-
self.__load_file(term_data_path)
431-
self.__build_sons()
430+
if linking:
431+
self.__load_file(term_data_path)
432+
self.__build_sons()
432433

433434
@classmethod
434-
def from_dir(cls, term_schema_path, term_data_path) -> "TermTree":
435+
def from_dir(cls, term_schema_path, term_data_path, linking) -> "TermTree":
435436
"""Build TermTree from a directory which should contain type schema and term data.
436437
437438
Args:
@@ -441,7 +442,7 @@ def from_dir(cls, term_schema_path, term_data_path) -> "TermTree":
441442
TermTree: [description]
442443
"""
443444
term_tree = cls()
444-
term_tree.build_from_dir(term_schema_path, term_data_path)
445+
term_tree.build_from_dir(term_schema_path, term_data_path, linking)
445446
return term_tree
446447

447448
def __dfs(self,

0 commit comments

Comments
 (0)