-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Benchmarked Resiliparse & added flag to evaluate parsers individually #25
Open
KhoomeiK
wants to merge
2
commits into
scrapinghub:master
Choose a base branch
from
KhoomeiK:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import re | ||
import statistics | ||
from typing import Any, Dict, Tuple, List | ||
import importlib | ||
|
||
|
||
def main(): | ||
|
@@ -19,19 +20,41 @@ def main(): | |
parser.add_argument('--bootstrap-differences', action='store_true', | ||
help='run bootstrap for differences') | ||
parser.add_argument('--output', type=Path, help='output results as json') | ||
parser.add_argument('--parser', type=str, help='Specify a parser name to evaluate only that parser') | ||
|
||
args = parser.parse_args() | ||
ground_truth = load_json(Path('ground-truth.json')) | ||
metrics_by_name = {} | ||
for path in sorted(Path('output').glob('*.json')): | ||
name = path.stem | ||
|
||
if args.parser: | ||
name = args.parser | ||
path = Path('output') / f'{name}.json' | ||
if not path.exists(): | ||
try: | ||
extractor_module = importlib.import_module(f'extractors.run_{name}') | ||
extractor_module.main() | ||
except: | ||
raise ValueError(f'Parser {name} not found') | ||
|
||
metrics = evaluate(ground_truth, load_json(path), args.n_bootstrap) | ||
print('{name:<20} ' | ||
'precision={precision:.3f} ± {precision_std:.3f} ' | ||
'recall={recall:.3f} ± {recall_std:.3f} ' | ||
'F1={f1:.3f} ± {f1_std:.3f} ' | ||
'accuracy={accuracy:.3f} ± {accuracy_std:.3f} ' | ||
.format(name=name, **metrics)) | ||
'precision={precision:.3f} ± {precision_std:.3f} ' | ||
'recall={recall:.3f} ± {recall_std:.3f} ' | ||
'F1={f1:.3f} ± {f1_std:.3f} ' | ||
'accuracy={accuracy:.3f} ± {accuracy_std:.3f} ' | ||
.format(name=name, **metrics)) | ||
metrics_by_name[name] = metrics | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be best to refactor the code in a way which does not leave to having to repeat the reporting. For example, we could pass |
||
for path in sorted(Path('output').glob('*.json')): | ||
name = path.stem | ||
metrics = evaluate(ground_truth, load_json(path), args.n_bootstrap) | ||
print('{name:<20} ' | ||
'precision={precision:.3f} ± {precision_std:.3f} ' | ||
'recall={recall:.3f} ± {recall_std:.3f} ' | ||
'F1={f1:.3f} ± {f1_std:.3f} ' | ||
'accuracy={accuracy:.3f} ± {accuracy_std:.3f} ' | ||
.format(name=name, **metrics)) | ||
metrics_by_name[name] = metrics | ||
|
||
if args.bootstrap_differences: | ||
# check differences with bootstrap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python3 | ||
import gzip | ||
import json | ||
from pathlib import Path | ||
|
||
from resiliparse.extract.html2text import extract_plain_text | ||
|
||
|
||
def main(): | ||
output = {} | ||
for path in Path('html').glob('*.html.gz'): | ||
with gzip.open(path, 'rt', encoding='utf8') as f: | ||
html = f.read() | ||
item_id = path.stem.split('.')[0] | ||
output[item_id] = {'articleBody': extract_plain_text(html, main_content=True)} | ||
(Path('output') / 'resiliparse.json').write_text( | ||
json.dumps(output, sort_keys=True, ensure_ascii=False, indent=4), | ||
encoding='utf8') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather catch
Exception
here, e.g. see motivation in this (rejected) PEP https://peps.python.org/pep-0760/#motivation