Skip to content

Commit

Permalink
🎨 reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlongWY committed Dec 30, 2022
1 parent a683360 commit 13fc1de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
9 changes: 6 additions & 3 deletions python/interface/examples/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ def issue613():
cProfile.run('LTP("LTP/legacy", local_files_only=True)', sort=SortKey.CUMULATIVE)


from tqdm import trange
from matplotlib import pyplot as plt
from tqdm import trange


def issue623():
ltp = LTP("LTP/legacy")

def get_current_memory() -> int:
import os, psutil
import os

import psutil

# 获取当前进程内存占用。
pid = os.getpid()
p = psutil.Process(pid)
Expand All @@ -68,7 +71,7 @@ def get_current_memory() -> int:
for _ in trange(10000):
# ltp.pipeline('他叫汤姆去拿外衣。')
# ltp.pipeline('台湾是中国领土不可分割的一部分。')
ltp.pipeline(['他叫汤姆去拿外衣。', "台湾是中国领土不可分割的一部分。"])
ltp.pipeline(["他叫汤姆去拿外衣。", "台湾是中国领土不可分割的一部分。"])
memory.append(get_current_memory())

memory.append(get_current_memory())
Expand Down
42 changes: 21 additions & 21 deletions python/interface/ltp/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def disable_rule_d(self, a, b):

def _check(self):
for model, task in (
(self.cws_model, "cws"),
(self.pos_model, "pos"),
(self.ner_model, "ner"),
(self.cws_model, "cws"),
(self.pos_model, "pos"),
(self.ner_model, "ner"),
):
if model is not None:
self.supported_tasks.add(task)
Expand All @@ -68,12 +68,12 @@ def __call__(self, *args, **kwargs):
return self.pipeline(*args, **kwargs)

def pipeline(
self,
*args,
tasks: List[str] = None,
raw_format=False,
parallelism=True,
return_dict: bool = True,
self,
*args,
tasks: List[str] = None,
raw_format=False,
parallelism=True,
return_dict: bool = True,
):
if tasks is None:
tasks = ["cws", "pos", "ner"]
Expand Down Expand Up @@ -102,15 +102,15 @@ def pipeline(
words = sentences[idx]
new_store.append(
[
(tag, "".join(words[start: end + 1]))
(tag, "".join(words[start : end + 1]))
for tag, start, end in get_entities(sent)
]
)
ner = new_store
else:
words = args[0]
ner = [
(tag, "".join(words[start: end + 1]))
(tag, "".join(words[start : end + 1]))
for tag, start, end in get_entities(ner)
]
args = (*args, ner)
Expand All @@ -132,16 +132,16 @@ def auto_hook(self, words: Union[List[str], List[List[str]]]):

@classmethod
def _from_pretrained(
cls,
model_id,
revision,
cache_dir,
force_download,
proxies,
resume_download,
local_files_only,
use_auth_token,
**model_kwargs,
cls,
model_id,
revision,
cache_dir,
force_download,
proxies,
resume_download,
local_files_only,
use_auth_token,
**model_kwargs,
):
"""Overwrite this method in case you wish to initialize your model in a different way."""

Expand Down

0 comments on commit 13fc1de

Please sign in to comment.