Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
497e3cea
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
497e3cea
编写于
12月 29, 2022
作者:
jm_12138
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update lac (#2187)
上级
3fcf01d5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
53 addition
and
67 deletion
+53
-67
modules/text/lexical_analysis/lac/README.md
modules/text/lexical_analysis/lac/README.md
+7
-2
modules/text/lexical_analysis/lac/ahocorasick.py
modules/text/lexical_analysis/lac/ahocorasick.py
+0
-1
modules/text/lexical_analysis/lac/custom.py
modules/text/lexical_analysis/lac/custom.py
+0
-2
modules/text/lexical_analysis/lac/module.py
modules/text/lexical_analysis/lac/module.py
+9
-2
modules/text/lexical_analysis/lac/processor.py
modules/text/lexical_analysis/lac/processor.py
+0
-1
modules/text/lexical_analysis/lac/test.py
modules/text/lexical_analysis/lac/test.py
+37
-59
未找到文件。
modules/text/lexical_analysis/lac/README.md
浏览文件 @
497e3cea
...
...
@@ -245,7 +245,8 @@
-
关于PaddleHub Serving更多信息参考:
[
服务部署
](
../../../../docs/docs_ch/tutorial/serving.md
)
-
### Gradio APP 支持
从 PaddleHub 2.3.1 开始支持使用链接 http://127.0.0.1:8866/gradio/lac 在浏览器中访问 lac 的 Gradio APP。
## 五、更新历史
...
...
@@ -287,6 +288,10 @@
移除 fluid api
*
2.4.0
添加 Gradio APP 支持
-
```shell
$ hub install lac==2.
3
.0
$ hub install lac==2.
4
.0
```
modules/text/lexical_analysis/lac/ahocorasick.py
浏览文件 @
497e3cea
# -*- coding: UTF-8 -*-
"""
本模块实现AC自动机封装为Ahocorasick类,用于进行词典的多模匹配。
"""
...
...
modules/text/lexical_analysis/lac/custom.py
浏览文件 @
497e3cea
# -*- coding: UTF-8 -*-
"""
该模块实现用户自定义词典的功能
"""
from
io
import
open
from
.ahocorasick
import
Ahocorasick
...
...
modules/text/lexical_analysis/lac/module.py
浏览文件 @
497e3cea
# -*- coding:utf-8 -*-
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
...
...
@@ -33,7 +32,7 @@ class DataFormatError(Exception):
@
moduleinfo
(
name
=
"lac"
,
version
=
"2.
3
.0"
,
version
=
"2.
4
.0"
,
summary
=
"Baidu's open-source lexical analysis tool for Chinese, including word segmentation, part-of-speech tagging & named entity recognition"
,
author
=
"baidu-nlp"
,
...
...
@@ -412,3 +411,11 @@ class LAC:
raise
DataFormatError
return
input_data
def
create_gradio_app
(
self
):
import
gradio
as
gr
return
gr
.
Interface
(
self
.
cut
,
gr
.
Text
(
label
=
'text'
),
gr
.
JSON
(
label
=
'results'
),
title
=
'lac'
,
allow_flagging
=
'never'
)
modules/text/lexical_analysis/lac/processor.py
浏览文件 @
497e3cea
# -*- coding:utf-8 -*-
import
io
import
numpy
as
np
...
...
modules/text/lexical_analysis/lac/test.py
浏览文件 @
497e3cea
...
...
@@ -8,6 +8,7 @@ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
class
TestHubModule
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
)
->
None
:
cls
.
text
=
"今天是个好日子"
...
...
@@ -19,74 +20,51 @@ class TestHubModule(unittest.TestCase):
shutil
.
rmtree
(
'inference'
)
def
test_cut1
(
self
):
results
=
self
.
module
.
cut
(
text
=
self
.
text
,
use_gpu
=
False
,
batch_size
=
1
,
return_tag
=
False
)
results
=
self
.
module
.
cut
(
text
=
self
.
text
,
use_gpu
=
False
,
batch_size
=
1
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[
'今天'
,
'是'
,
'个'
,
'好日子'
])
def
test_cut2
(
self
):
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
False
,
batch_size
=
1
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[
{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
]},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
]},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
]}
])
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
False
,
batch_size
=
1
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
]
},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
]
},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
]
}])
def
test_cut3
(
self
):
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
False
,
batch_size
=
2
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[
{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
]},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
]},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
]}
])
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
False
,
batch_size
=
2
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
]
},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
]
},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
]
}])
def
test_cut4
(
self
):
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
True
,
batch_size
=
2
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[
{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
]},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
]},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
]}
])
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
True
,
batch_size
=
2
,
return_tag
=
False
)
self
.
assertEqual
(
results
,
[{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
]
},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
]
},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
]
}])
def
test_cut5
(
self
):
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
True
,
batch_size
=
2
,
return_tag
=
True
)
self
.
assertEqual
(
results
,
[
{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
],
'tag'
:
[
'TIME'
,
'v'
,
'q'
,
'n'
]
},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
],
'tag'
:
[
'n'
,
'v'
,
'TIME'
,
'v'
,
'v'
]
},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
],
'tag'
:
[
'f'
,
'm'
,
'n'
,
'd'
,
'v'
,
'v'
,
'xc'
]
}
])
results
=
self
.
module
.
cut
(
text
=
self
.
texts
,
use_gpu
=
True
,
batch_size
=
2
,
return_tag
=
True
)
self
.
assertEqual
(
results
,
[{
'word'
:
[
'今天'
,
'是'
,
'个'
,
'好日子'
],
'tag'
:
[
'TIME'
,
'v'
,
'q'
,
'n'
]
},
{
'word'
:
[
'天气预报'
,
'说'
,
'今天'
,
'要'
,
'下雨'
],
'tag'
:
[
'n'
,
'v'
,
'TIME'
,
'v'
,
'v'
]
},
{
'word'
:
[
'下'
,
'一班'
,
'地铁'
,
'马上'
,
'就要'
,
'到'
,
'了'
],
'tag'
:
[
'f'
,
'm'
,
'n'
,
'd'
,
'v'
,
'v'
,
'xc'
]
}])
def
test_save_inference_model
(
self
):
self
.
module
.
save_inference_model
(
'./inference/model'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录