|
|
@@ -1,5 +1,39 @@ |
|
|
|
""" |
|
|
|
API.API 的文档 |
|
|
|
api.api的介绍文档 |
|
|
|
直接缩进会把上面的文字变成标题 |
|
|
|
|
|
|
|
空行缩进的写法比较合理 |
|
|
|
|
|
|
|
比较合理 |
|
|
|
|
|
|
|
*这里是斜体内容* |
|
|
|
|
|
|
|
**这里是粗体内容** |
|
|
|
|
|
|
|
数学公式块 |
|
|
|
|
|
|
|
.. math:: |
|
|
|
E = mc^2 |
|
|
|
|
|
|
|
.. note:: |
|
|
|
注解型提示。 |
|
|
|
|
|
|
|
.. warning:: |
|
|
|
警告型提示。 |
|
|
|
|
|
|
|
.. seealso:: |
|
|
|
`参考与超链接 <https://willqvq.github.io/doc_guide/%E6%B3%A8%E9%87%8A%E6%8C%87%E5%AF%BC>`_ |
|
|
|
|
|
|
|
普通代码块需要空一行, Example:: |
|
|
|
|
|
|
|
from fitlog import fitlog |
|
|
|
fitlog.commit() |
|
|
|
|
|
|
|
普通下标和上标: |
|
|
|
|
|
|
|
H\ :sub:`2`\ O |
|
|
|
|
|
|
|
E = mc\ :sup:`2` |
|
|
|
|
|
|
|
""" |
|
|
|
import warnings |
|
|
@@ -28,6 +62,9 @@ model_urls = { |
|
|
|
|
|
|
|
|
|
|
|
class API: |
|
|
|
""" |
|
|
|
这是 API 类的文档 |
|
|
|
""" |
|
|
|
def __init__(self): |
|
|
|
self.pipeline = None |
|
|
|
self._dict = None |
|
|
@@ -73,8 +110,9 @@ class POS(API): |
|
|
|
self.load(model_path, device) |
|
|
|
|
|
|
|
def predict(self, content): |
|
|
|
""" |
|
|
|
|
|
|
|
"""predict函数的介绍, |
|
|
|
函数介绍的第二句,这句话不会换行 |
|
|
|
|
|
|
|
:param content: list of list of str. Each string is a token(word). |
|
|
|
:return answer: list of list of str. Each string is a tag. |
|
|
|
""" |
|
|
@@ -140,13 +178,14 @@ class POS(API): |
|
|
|
|
|
|
|
|
|
|
|
class CWS(API): |
|
|
|
def __init__(self, model_path=None, device='cpu'): |
|
|
|
""" |
|
|
|
中文分词高级接口。 |
|
|
|
""" |
|
|
|
中文分词高级接口。 |
|
|
|
|
|
|
|
:param model_path: 当model_path为None,使用默认位置的model。如果默认位置不存在,则自动下载模型 |
|
|
|
:param device: str,可以为'cpu', 'cuda'或'cuda:0'等。会将模型load到相应device进行推断。 |
|
|
|
""" |
|
|
|
:param model_path: 当model_path为None,使用默认位置的model。如果默认位置不存在,则自动下载模型 |
|
|
|
:param device: str,可以为'cpu', 'cuda'或'cuda:0'等。会将模型load到相应device进行推断。 |
|
|
|
""" |
|
|
|
def __init__(self, model_path=None, device='cpu'): |
|
|
|
|
|
|
|
super(CWS, self).__init__() |
|
|
|
if model_path is None: |
|
|
|
model_path = model_urls['cws'] |
|
|
@@ -187,18 +226,20 @@ class CWS(API): |
|
|
|
def test(self, filepath): |
|
|
|
""" |
|
|
|
传入一个分词文件路径,返回该数据集上分词f1, precision, recall。 |
|
|
|
分词文件应该为: |
|
|
|
1 编者按 编者按 NN O 11 nmod:topic |
|
|
|
2 : : PU O 11 punct |
|
|
|
3 7月 7月 NT DATE 4 compound:nn |
|
|
|
4 12日 12日 NT DATE 11 nmod:tmod |
|
|
|
5 , , PU O 11 punct |
|
|
|
|
|
|
|
1 这 这 DT O 3 det |
|
|
|
2 款 款 M O 1 mark:clf |
|
|
|
3 飞行 飞行 NN O 8 nsubj |
|
|
|
4 从 从 P O 5 case |
|
|
|
5 外型 外型 NN O 8 nmod:prep |
|
|
|
分词文件应该为:: |
|
|
|
|
|
|
|
1 编者按 编者按 NN O 11 nmod:topic |
|
|
|
2 : : PU O 11 punct |
|
|
|
3 7月 7月 NT DATE 4 compound:nn |
|
|
|
4 12日 12日 NT DATE 11 nmod:tmod |
|
|
|
5 , , PU O 11 punct |
|
|
|
|
|
|
|
1 这 这 DT O 3 det |
|
|
|
2 款 款 M O 1 mark:clf |
|
|
|
3 飞行 飞行 NN O 8 nsubj |
|
|
|
4 从 从 P O 5 case |
|
|
|
5 外型 外型 NN O 8 nmod:prep |
|
|
|
|
|
|
|
以空行分割两个句子,有内容的每行有7列。 |
|
|
|
|
|
|
|
:param filepath: str, 文件路径路径。 |
|
|
|