用于帧语义分析的数据处理的python模块
pyfn的Python项目详细描述
Pyfn
欢迎使用pyfn,一个处理framenet注释的python模块。
pyfn
可用于:
- 将数据与framenet xml、semeval xml、semafor conll、bios和conll-x进行转换
- 使用标准化的最新管道对framenet数据进行预处理
- 在framenet 1.5、1.6和1.7数据集上运行用于帧和/或参数标识的semafor、open-sesame和simpleframeid帧语义分析器
- 构建自己的帧语义解析器,使用一组标准的python模型来封送/解封framenet xml数据< > >
此存储库还附带了(Kabbach等人,2018)论文:
@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
依赖关系
在UNIX上,您可能需要安装以下软件包:
libxml2 libxml2-dev libxslt1-dev python-3.x-dev
安装
pip3 install pyfn
使用
当使用
pyfn
时,您的framenet拆分目录结构应该遵循:. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
转换
pyfn
可用于将数据转换为- framenet xml:发布的framenet xml数据的格式
- semeval xml:semeval 2007框架语义结构提取共享任务19的格式
- semafor conll:semafor解析器使用的格式
- bios:open-sesame解析器使用的格式
- conll-x:各种最新pos标记和依赖项使用的格式 解析器(请参见帧语义分析的预处理注意事项 <预处理和帧语义分析" rel="nofollow">如下)
以及生成Semafor和 open-sesame解析器集成层次结构功能(有关详细信息,请参见(kshirsagar et al.,2015)。
有关所有格式的详细说明,请查看format.md。
如何
以下各节提供了转换fn数据的命令示例 不同的格式。所有命令都可以使用以下选项:
--splits
:指定应转换哪些splits。--splits train
将生成所有 根据在fndata-1.x/{train/dev/test}下找到的数据,对train/dev/test进行拆分 目录。--splits dev
将根据下面的数据生成dev和test splits fndata-1.x/{dev/test}目录。此选项将跳过列车分流,但生成 与使用--splits train
生成的dev/test splits相同。--拆分测试 根据fndata-1.x/test目录下的数据生成测试拆分,并跳过 列车/开发人员分开。用
--splits test
生成的测试拆分与 用--splits train
和--splits dev
生成。默认为--splits test
--输出句子
:如果指定,将输出一个。句子
文件 在此过程中,包含所有原始注释句子,每行一个句子。--with_examples
:如果指定,将处理示例(数据lu
目录)以及全文。--filter
:指定数据筛选选项(请参见下面的详细信息)。 < > >- MXPost(Ratnaparkhi,1996年)
- NLP4J(Choi,2016年)
- MST(McDonald等人,2006年)
- Bist Barch(Kiperwasser和Goldberg,2016年)
- BIST BMST(Kiperwasser和Goldberg,2016年)
- SimpleFrameID(Hartmann等人,2017)用于帧识别
- Semafor(kshirsagar等人,2015)用于参数标识
- open-sesame(swayamdipta等人,2017)用于参数识别
data.7z
包含fn 1.5和fn 1.7的所有framenet拆分lib.7z
包含所有不同的外部软件(标记器、解析器等)资源.7z
包含所有必需的资源scripts.7z
包含一组bash脚本,用于调用不同的解析器和预处理工具包
有关
pyfn
用法的详细信息,请执行:pyfn --help pyfn generate --help pyfn convert --help
从fn xml到bios
要将数据从framenet xml格式转换为bios格式,请执行以下操作:
pyfn convert \ --from fnxml \ --to bios \ --source /abs/path/to/fndata-1.x \ --target /abs/path/to/xp/data/output/dir \ --splits train \ --output_sentences \ --filter overlap_fes
使用
--filter overlap\u fes
将跳过具有重叠的所有注释集 帧元素,因为BIOS格式不支持这些情况。从fn xml到semafor conll
生成用于训练semafor的
train.frame.elements
文件,以及{dev,test}.frames
用于解码的文件,do:pyfn convert \ --from fnxml \ --to semafor \ --source /abs/path/to/fndata-1.x \ --target /abs/path/to/xp/data/output/dir \ --splits train \ --output_sentences
从fn xml到semeval xml
要以semeval格式生成评分用的
{dev,test}.gold.xml
gold文件,请执行以下操作:pyfn convert \ --from fnxml \ --to semeval \ --source /abs/path/to/fndata-1.x \ --target /abs/path/to/xp/data/output/dir \ --splits {dev,test}
从bios到semeval xml
要转换解码的bios文件{dev,test}.bios.semeval.decoded open-sesame to semeval xml格式评分,do:
pyfn convert \ --from bios \ --to semeval \ --source /abs/path/to/{dev,test}.bios.semeval.decoded \ --target /abs/path/to/output/{dev,test}.predicted.xml \ --sent /abs/path/to/{dev,test}.sentences
从semafor conll到semeval xml
要将semafor的解码
{dev,test}.frame.elements
文件转换为 评分用semeval xml格式,do:@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
0生成层次结构
.csv
文件@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
1要同时处理示例,请添加
--with_examples
选项预处理和帧语义分析
pyfn
附带一组bash脚本,用于预处理framenet数据 各种pos标记器和依赖分析器,以及执行frame 使用各种开源解析器进行语义分析。当前支持的POS标记包括:
当前支持的依赖项分析器包括:
当前支持的帧语义分析器包括:
请求对pos标记、依赖性解析器或帧语义的支持 解析器,请创建关于github/gitlab的问题。
下载
要运行预处理和帧语义分析脚本,请首先下载:
@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
2@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
3@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
4@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
5从 名为
pyfn
的目录。PyFN文件夹结构应如下所示:@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
6请严格遵循此目录结构以避免意外错误。
pyfn
依赖于许多相对路径分辨率来缩短脚本调用,更改此目录结构可能会破坏所有内容设置NLP4J进行POS标记
要使用nlp4j进行pos标记,请修改
resources/config-decode-pos.xml 将models.pos绝对路径替换为 您的
资源/nlp4j.plemma.model.all.xz
:@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
7为bist或open-sesame设置dynet
如果打算使用bist解析器进行依赖性分析,或者 open-sesame用于框架语义分析,您将需要 要安装Dynet 2.0.2,请通过:
@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
8如果在通过PIP安装dynet时遇到问题,请执行以下操作:
@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
9设置semafor
要使用SemaFor框架语义分析器,请修改
scripts/setup.sh
文件:
0libxml2 libxml2-dev libxslt1-dev python-3.x-dev
设置simpleframeid
如果要使用simpleframeid进行帧标识,则需要安装以下软件包(在python 2.7上):
1libxml2 libxml2-dev libxslt1-dev python-3.x-dev
使用semeval perl评估脚本
如果要使用semeval perl评估脚本,请确保 安装
app::cpanminus
和xml::parser
模块:
2libxml2 libxml2-dev libxslt1-dev python-3.x-dev
使用bash脚本
每个脚本都有一个助手:使用
--help
查看它!小心!大多数脚本都希望通过
pyfn convert…
位于pyfn/experiments/xp xyz/data
下,其中xyz
代表 实验编号和是使用-x xyz
参数指定的,其中实验
目录与脚本位于同一级别 目录。事实证明,这种固执己见的选择对发射极为有用。 在一组大型实验上按批编写脚本,因为这样可以避免输入 每次的完整路径。
确保使用
3libxml2 libxml2-dev libxslt1-dev python-3.x-dev
在调用
preprocess.sh之前,
准备.sh,
semafor.sh
芝麻开门.sh
预处理.sh
使用
preprocess.sh
对生成的pos标记和依赖项解析framenet splits 使用pyfn convert…
。助手应显示:
4libxml2 libxml2-dev libxslt1-dev python-3.x-dev
假设您使用:
5libxml2 libxml2-dev libxslt1-dev python-3.x-dev
可以使用nlp4j和bmst预处理这些拆分
6libxml2 libxml2-dev libxslt1-dev python-3.x-dev
准备.sh
使用
prepare.sh
自动生成杂项。所需数据 框架语义解析管道,如用于评分的gold semeval xml文件, framenet.frame.element.map和层次结构.csv
文件 由Semafor使用,或由 芝麻和芝麻。助手应显示:
7libxml2 libxml2-dev libxslt1-dev python-3.x-dev
假设您使用:
5libxml2 libxml2-dev libxslt1-dev python-3.x-dev
您可以使用:
9libxml2 libxml2-dev libxslt1-dev python-3.x-dev
frameid.sh
使用
小精灵α30frameid.sh
使用simpleframeid执行帧标识。 助手应显示:假设您使用:
1pip3 install pyfn
预处理之后,您可以使用:
2pip3 install pyfn
并使用:
3pip3 install pyfn
semafor.sh
使用
semafor.sh
训练semafor解析器或解码测试/开发拆分。 助手应显示:
4pip3 install pyfn
假设您使用:
5libxml2 libxml2-dev libxslt1-dev python-3.x-dev
在预处理和准备之后,您可以使用:
6pip3 install pyfn
并使用:
7pip3 install pyfn
芝麻开门.sh
使用
open sesame.sh
训练open-sesmae解析器或解码测试/开发拆分。 助手应显示:
8pip3 install pyfn
假设您使用:
9pip3 install pyfn
在预处理和准备之后,您可以使用:
0. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
并使用:
1. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
得分.sh
使用
score.sh
获取上的帧语义分析的P/R/F1分数 dev/test使用semeval评分脚本,使用预测帧的黄金分割。 助手应显示:
2. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
请注意,评分是使用semeval perl脚本的更新版本完成的, 以便在设置中获得更可靠的分数。为了一个完整的帐户 有关修改,请参阅(Kabbach等人,2018)和Perl脚本 位于
lib/semeval/
下要在分割测试中使用金色框架获得Semafor的分数,请使用:
3. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
若要使用测试拆分时的预测帧获得Semafor的分数,请使用:
4. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
复制
实验
目录为 在实验中复制(Kabbach等人,2018)中报告的所有结果 框架语义分析中的蝴蝶效应。这些说明可以使用 比较不同帧语义分析器在不同环境下的性能 实验设置。编组和解编组framenet xml数据
pyfn
提供了一组处理framenet xml数据的python模型。 这些可以帮助您构建自己的框架语义分析器。pyfn模型的核心是对应于 xml
<;注释集>;
标记。它存储各种信息 关于给定语句中给定目标的给定framenet注释集。 值得注意的创新是labelstore
和valenceunitstore
,它们 将framenet标签(fe/pt/gf)存储为其原始格式和自定义格式 可能对帧语义分析有用的格式。在
pyfn的
pyfn.models
目录下探索各种模型 包装:解组framenet xml数据
将fulltext.xml文件和/或lu.xml文件的列表转换为生成器 在
pyfn.annotationset
对象上,列车/dev/test分段之间没有重叠,使用:
5. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
splits\u dirpath
应该指向包含train/dev/test的目录 拆分目录(请参见上面的详细结构)。get_annosets_dict
将向annotationset generator dict返回一个字符串。 它将确保列车/开发/测试分离之间没有重叠。调用
splits='test'
上的get\u annosets\u dict将返回字典 使用一个
'test'
键。在splits=dev'上调用
get\u annosets\u dict
将返回带两个键的字典:'dev'
和'test'
。 调用splits='train'
上的get\u annosets\u dict将返回字典 有三个键:
'train'
,'dev'
和'test'
要遍历每个键的注释集对象列表,可以 然后做:
6. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
简单地说,迭代特定的键值(例如train annosets):
7. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
请注意,对于性能,annosets不是一个列表,而是一个生成器。
解组开放式芝麻bios数据
将
.bios
文件及其相应的语句转换为 一个生成器覆盖
pyfn.annotationset
对象,使用:
8. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
重要!必须已生成
.bios
和语句文件 使用
pyfn convert…--到BIOS…
和--过滤器重叠 参数。
为conll数据解组semaar
转换
.frame.elements
文件及其相应的语句 通过
pyfn.annotationset
对象将文件发送到生成器,使用:
9. |-- fndata-1.x-with-dev | |-- train | | |-- fulltext | | |-- lu | |-- dev | | |-- fulltext | | |-- lu | |-- test | | |-- fulltext | | |-- lu | |-- frame | |-- frRelation.xml | |-- semTypes.xml
解组semeval xml数据
转换semeval
.xml
文件及其相应的语句 通过
pyfn.annotationset
对象将文件发送到生成器,使用:pyfn --help pyfn generate --help pyfn convert --help
0默认情况下,semeval的unmarshall_annosets将返回嵌入注释集上的生成器。要在单个注释集上迭代,请使用:
pyfn --help pyfn generate --help pyfn convert --help
1要返回注释的"平面"列表,请传入
flatten=true
参数:pyfn --help pyfn generate --help pyfn convert --help
2编组到open-sesame bios
要将
splits
的指令转换为pyfn.annotationset
对象以打开sesame style.bios
,请参阅pyfn.marshalling.marshallers.bios.marshall\u annosets\u dict
编组到Semafor Conll
要将
splits
的dict转换为pyfn.annotationset
要将对象转换为semafor style.frame.elements
,请参阅pyfn.marshalling.marshallers.semafor.marshall注释命令
编组到semeval xml
要将
pyfn.annotationset
对象的列表转换为semeval style.xml
, 请参阅pyfn.marshalling.marshallers.semeval.marshall注释
编组到.csv层次结构
要将关系列表转换为
.csv
文件,请参阅pyfn.marshalling.marshallers.hierarchy.marshall_relations
引文
如果您使用
pyfn
请引用:@InProceedings{C18-1267, author = "Kabbach, Alexandre and Ribeyre, Corentin and Herbelot, Aur{\'e}lie", title = "Butterfly Effects in Frame Semantic Parsing: impact of data processing on model ranking", booktitle = "Proceedings of the 27th International Conference on Computational Linguistics", year = "2018", publisher = "Association for Computational Linguistics", pages = "3158--3169", location = "Santa Fe, New Mexico, USA", url = "http://aclweb.org/anthology/C18-1267" }
推荐PyPI第三方库