NLG(自然语言生成)的各种无监督自动指标的评估代码。它将其作为输入假设文件,一个或多个引用文件和输出指标值。这些文件之间的行应对应于同一示例。
安装Java 1.8.0(或更高)。
安装Python依赖项,运行:
pip install git+https://github.com/Maluuba/nlg-eval.git@master如果您使用的是MacOS High Sierra或更高版本,请运行以允许多线程:
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES简单设置(下载必需的数据(例如模型,嵌入)和外部代码文件),运行:
nlg-eval --setup如果您是从源代码设置的,或者您正在使用Windows而不是使用Bash终端,则可能会发现有关未找到nlg-eval的错误。您将需要找到nlg-eval脚本。有关详细信息,请参见此处。
# If you don't like the default path (~/.cache/nlgeval) for the downloaded data,
# then specify a path where you want the files to be downloaded.
# The value for the data path is stored in ~/.config/nlgeval/rc.json and can be overwritten by
# setting the NLGEVAL_DATA environment variable.
nlg-eval --setup ${data_path}(这些示例是用窗户上的git bash制作的)
所有数据文件都应下载,您应该看到大小,例如:
$ ls -l ~/.cache/nlgeval/
total 6003048
-rw-r--r-- 1 ... 289340074 Sep 12 2018 bi_skip.npz
-rw-r--r-- 1 ... 689 Sep 12 2018 bi_skip.npz.pkl
-rw-r--r-- 1 ... 2342138474 Sep 12 2018 btable.npy
-rw-r--r-- 1 ... 7996547 Sep 12 2018 dictionary.txt
-rw-r--r-- 1 ... 21494787 Jan 22 2019 glove.6B.300d.model.bin
-rw-r--r-- 1 ... 480000128 Jan 22 2019 glove.6B.300d.model.bin.vectors.npy
-rw-r--r-- 1 ... 663989216 Sep 12 2018 uni_skip.npz
-rw-r--r-- 1 ... 693 Sep 12 2018 uni_skip.npz.pkl
-rw-r--r-- 1 ... 2342138474 Sep 12 2018 utable.npy
您还可以验证一些校验和
$ cd ~/.cache/nlgeval/
$ md5sum *
9a15429d694a0e035f9ee1efcb1406f3 *bi_skip.npz
c9b86840e1dedb05837735d8bf94cee2 *bi_skip.npz.pkl
022b5b15f53a84c785e3153a2c383df6 *btable.npy
26d8a3e6458500013723b380a4b4b55e *dictionary.txt
f561ab0b379e23cbf827a054f0e7c28e *glove.6B.300d.model.bin
be5553e91156471fe35a46f7dcdfc44e *glove.6B.300d.model.bin.vectors.npy
8eb7c6948001740c3111d71a2fa446c1 *uni_skip.npz
e1a0ead377877ff3ea5388bb11cfe8d7 *uni_skip.npz.pkl
5871cc62fc01b79788c79c219b175617 *utable.npy
$ sha256sum *
8ab7965d2db5d146a907956d103badfa723b57e0acffb75e10198ba9f124edb0 *bi_skip.npz
d7e81430fcdcbc60b36b92b3f879200919c75d3015505ee76ae3b206634a0eb6 *bi_skip.npz.pkl
4a4ed9d7560bb87f91f241739a8f80d8f2ba787a871da96e1119e913ccd61c53 *btable.npy
4dc5622978a30cddea8c975c871ea8b6382423efb107d27248ed7b6cfa490c7c *dictionary.txt
10c731626e1874effc4b1a08d156482aa602f7f2ca971ae2a2f2cd5d70998397 *glove.6B.300d.model.bin
20dfb1f44719e2d934bfee5d39a6ffb4f248bae2a00a0d59f953ab7d0a39c879 *glove.6B.300d.model.bin.vectors.npy
7f40ff16ff5c54ce9b02bd1a3eb24db3e6adaf7712a7a714f160af3a158899c8 *uni_skip.npz
d58740d46cba28417cbc026af577f530c603d81ac9de43ffd098f207c7dc4411 *uni_skip.npz.pkl
790951d4b08e843e3bca0563570f4134ffd17b6bd4ab8d237d2e5ae15e4febb3 *utable.npy
如果您确保设置成功,则可以运行测试:
pip install pytest
pytest可能需要几分钟,您可能会看到警告,但应该通过。
设置完成后,可以使用Python API或在命令行中评估指标。
可以在test_nlgeval.py中找到Python API的示例。
nlg-eval --hypothesis=examples/hyp.txt --references=examples/ref1.txt --references=examples/ref2.txt
假设文件中的每一行都是生成句子,而参考文件上的相应行是相应假设的基础真实参考句子。
from nlgeval import compute_metrics
metrics_dict = compute_metrics ( hypothesis = 'examples/hyp.txt' ,
references = [ 'examples/ref1.txt' , 'examples/ref2.txt' ]) from nlgeval import compute_individual_metrics
metrics_dict = compute_individual_metrics ( references , hypothesis ) references是地面真理参考文本字符串和hypothesis的列表是假设文本字符串。
from nlgeval import NLGEval
nlgeval = NLGEval () # loads the models
metrics_dict = nlgeval . compute_individual_metrics ( references , hypothesis ) references是地面真理参考文本字符串和hypothesis的列表是假设文本字符串。
from nlgeval import NLGEval
nlgeval = NLGEval () # loads the models
metrics_dict = nlgeval . compute_metrics ( references , hypothesis ) references是地面真理参考文本字符串和hypothesis的列表,是假设文本字符串的列表。 references中的每个内部列表都是假设的一组引用(以相同顺序为hypothesis的每个句子的单个参考字符串列表)。
如果您将此代码作为任何已发表研究的一部分,请引用以下论文:
Shikhar Sharma,Layla El Asri,Hannes Schulz和Jeremie Zumer。 “无监督指标在评估自然语言生成的任务对话中的相关性” Arxiv Preprint Arxiv:1706.09799 (2017)
@article { sharma2017nlgeval ,
author = { Sharma, Shikhar and El Asri, Layla and Schulz, Hannes and Zumer, Jeremie } ,
title = { Relevance of Unsupervised Metrics in Task-Oriented Dialogue for Evaluating Natural Language Generation } ,
journal = { CoRR } ,
volume = { abs/1706.09799 } ,
year = { 2017 } ,
url = { http://arxiv.org/abs/1706.09799 }
}跑步
nlg-eval --hypothesis=examples/hyp.txt --references=examples/ref1.txt --references=examples/ref2.txt
给予
Bleu_1: 0.550000
Bleu_2: 0.428174
Bleu_3: 0.284043
Bleu_4: 0.201143
METEOR: 0.295797
ROUGE_L: 0.522104
CIDEr: 1.242192
SPICE: 0.312331
SkipThoughtsCosineSimilarity: 0.626149
EmbeddingAverageCosineSimilarity: 0.884690
VectorExtremaCosineSimilarity: 0.568696
GreedyMatchingScore: 0.784205
如果您对流星有问题,则可以尝试降低MEM.PY中的mem变量
默认情况下(将IDF参数设置为“语料库”模式)使用提供的参考句子来计算IDF值。因此,只有1个图像(或NLG的示例)的参考数据集的CIDER分数为零。使用一个(或几个)图像评估时,将IDF设置为“ Coco-Val-DF”,该IDF使用MSCOCO VAILDATION数据集中的IDF以获得可靠的结果。此代码尚未对此进行调整。对于此用例,请应用Vrama91/Coco-Caption的补丁。
要将已经准备好的数据目录安装到Docker容器中或在用户之间共享它,您可以设置NLGEVAL_DATA环境变量,让NLG-Eval知道在哪里可以找到其模型和数据。例如
NLGEVAL_DATA=~/workspace/nlg-eval/nlgeval/data
该变量覆盖了设置过程中提供的值(存储在~/.config/nlgeval/rc.json中)
该项目采用了Microsoft开源的行为代码。有关更多信息,请参见《行为守则常见问题守则》或与其他问题或评论联系[email protected]。
请参阅许可证。