-
Notifications
You must be signed in to change notification settings - Fork 71
/
PKG-INFO
207 lines (144 loc) · 7.98 KB
/
PKG-INFO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Metadata-Version: 1.1
Name: pyrouge
Version: 0.1.3
Summary: A Python wrapper for the ROUGE summarization evaluation package.
Home-page: https://github.com/noutenki/pyrouge
Author: Benjamin Heinzerling, Anders Johannsen
Author-email: benjamin.heinzerling@h-its.org
License: LICENSE.txt
Description: pyrouge
=======
pyrouge is a Python wrapper for the ROUGE summarization evaluation
package. Getting ROUGE to work can require quite a bit of time. pyrouge
is designed to make getting ROUGE scores easier by automatically
converting your summaries into a format ROUGE understands, and
automatically generating the ROUGE configuration file.
Usage Examples
--------------
I have summarizations in plain text format and want to get the ROUGE scores
===========================================================================
You can evaluate your plain text summaries like this:
::
from pyrouge import Rouge155
r = Rouge155()
r.system_dir = 'path/to/system_summaries'
r.model_dir = 'path/to/model_summaries'
r.system_filename_pattern = 'some_name.(\d+).txt'
r.model_filename_pattern = 'some_name.[A-Z].#ID#.txt'
output = r.convert_and_evaluate()
print(output)
output_dict = r.output_to_dict(output)
In order to evaluate summaries, ROUGE needs to know where your summaries
and the gold standard summaries are, and how to match them. In ROUGE
parlance, your summaries are 'system' summaries and the gold standard
summaries are 'model' summaries. The summaries should be in separate
folders, whose paths are set with the ``system_dir`` and ``model_dir``
variables. All summaries should contain one sentence per line.
To automatically match a system summary with the corresponding model
summaries, pyrouge uses regular expressions. For example, let's assume
your system summaries are named with a combination of a fixed name and a
variable numeric ID like this:
| some\_name.001.txt
| some\_name.002.txt
| some\_name.003.txt
| ...
and the model summaries like this, with uppercase letters identifying
multiple model summaries for a given document:
| some\_name.A.001.txt
| some\_name.B.001.txt
| some\_name.C.001.txt
| some\_name.A.002.txt
| some\_name.B.002.txt
| ...
The group in the ``system_filename_pattern`` tells pyrouge which part of
the filename is the ID -- in this case ``(\d+)``. You have to use round
brackets to indicate a group, or else pyrouge won't be able to tell
apart the ID from the rest of the filename. pyrouge then uses that ID to
find all matching model summaries. The special placeholder ``#ID#``
tells pyrouge where it should expect the ID in the
``model_filename_pattern``. The ``[A-Z]`` part matches multiple model
summaries for that ID.
With the configuration done, invoking ``convert_and_evaluate()`` gets
you the ROUGE scores as a string. If you want to further process the
scores, you can parse the output into a dict with
``output_to_dict(output)``.
I only want to preprocess my summaries and then run ROUGE on my own
===================================================================
To convert plain text summaries into a format ROUGE understands, do:
::
from pyrouge import Rouge155
Rouge155.convert_summaries_to_rouge_format(system_input_dir, system_output_dir)
Rouge155.convert_summaries_to_rouge_format(model_input_dir, model_output_dir)
This will convert all summaries in ``system_input_dir`` and
``model_input_dir``, and save them to their respective output
directories.
To generate the configuration file that ROUGE uses to match system and
model summaries, do:
::
from pyrouge import Rouge155
Rouge155.write_config_static(
system_dir, system_filename_pattern,
model_dir, model_filename_pattern,
config_file_path)
The first four arguments are explained above. ``config_file_path``
specifies where to save the configuration file.
Using pyrouge from the command line
===================================
If you prefer the command line to Python and the pyrouge module, you can
use the following scripts, which are automatically installed and should
be runnable from anywhere on your system:
- **pyrouge\_evaluate\_plain\_text\_files** gets you ROUGE scores
for your plain text summaries. Example:
::
pyrouge_evaluate_plain_text_files -s systems_plain/ -sfp "some_name.(\d+).txt" -m models_plain/ -mfp some_name.[A-Z].#ID#.txt
- **pyrouge\_evaluate\_rouge\_format\_files** gets you ROUGE scores
for summaries already converted to ROUGE format. Example usage for
the ``sample-test/SL2003`` data that comes with ROUGE:
::
pyrouge_evaluate_rouge_format_files -s systems -sfp "SL.P.10.R.11.SL062003-(\d+).html" -m models -mfp SL.P.10.R.[A-Z].SL062003-#ID#.html
Note that the system filename pattern is enclosed in quotation marks
because it contains special characters.
- **pyrouge\_convert\_plain\_text\_to\_rouge\_format** converts
plain text files into a format ROUGE understands. If your plain text
files do not contain one sentence per line, this script can also
split sentences, provided you have nltk and its Punkt sentence
splitter installed. Example:
::
pyrouge_convert_plain_text_to_rouge_format -i models_plain/ -o models_rouge
- **pyrouge\_write\_config\_file** creates a configuration file you
can use to run ROUGE on your own. Example:
::
pyrouge_write_config_file -s systems -sfp "SL.P.10.R.11.SL062003-(\d+).html" -m models -mfp SL.P.10.R.[A-Z].SL062003-#ID#.html -c sl2003_config.xml
Running any of these with the ``-h`` option will display a usage message
explaining the various command line options.
Installation
------------
Instruction on installing ROUGE can be found
`here <http://jpbalb.in/post/42675198985/figuring-out-rouge>`__.
Depending on your system, you might have to run the following commands
as root.
To install pyrouge, run:
::
pip install pyrouge
Assuming a working ROUGE-1.5.5. installation, tell pyrouge the ROUGE
path with this command:
::
pyrouge_set_rouge_path /absolute/path/to/ROUGE-1.5.5/directory
To test if everything is installed correctly, run:
::
python -m pyrouge.test
If everything works, you should see something like:
::
Ran 10 tests in 18.055s
OK
If you want to uninstall pyrouge:
::
pip uninstall pyrouge
Platform: UNKNOWN
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Linguistic