Skip to content
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

[WIP] add other platforms to CI. #70

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ on:
jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: ${{ matrix.python-version }}
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
Expand All @@ -28,7 +34,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install flake8
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e .
python -m spacy download en_core_web_sm

- name: Cache AutoSummENG
id: cache-autosummeng
Expand Down
35 changes: 21 additions & 14 deletions sacrerouge/metrics/meteor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import argparse
import logging
import os
import requests
import tarfile
from pathlib import Path
from collections import defaultdict
from overrides import overrides
from subprocess import Popen, PIPE
Expand Down Expand Up @@ -36,6 +39,7 @@ def _flatten_summaries(self, summaries_list: List[List[SummaryType]]) -> List[Li

def _parse_meteor_stdout(self, stdout: str) -> Tuple[float, List[float]]:
lines = stdout.splitlines()
print(lines)
assert lines[11].startswith('Segment 1 score'), 'Unexpected Meteor stdout format'

individual_scores = []
Expand Down Expand Up @@ -133,17 +137,20 @@ def add_subparser(self, parser: argparse._SubParsersAction):

@overrides
def run(self, args):
commands = [
f'mkdir -p {DATA_ROOT}/metrics/METEOR',
f'cd {DATA_ROOT}/metrics/METEOR',
f'wget https://www.cs.cmu.edu/~alavie/METEOR/download/meteor-1.5.tar.gz',
f'tar xzvf meteor-1.5.tar.gz'
]
command = ' && '.join(commands)

process = Popen(command, shell=True)
process.communicate()
if process.returncode == 0:
print('METEOR setup success')
else:
print('METEOR setup failure')
output_dir = Path(f'{DATA_ROOT}/metrics/METEOR')
output_dir.mkdir(exist_ok=True, parents=True)

output_file = output_dir / 'meteor-1.5.tar.gz'

if not output_file.exists():
r = requests.get('https://www.cs.cmu.edu/~alavie/METEOR/download/meteor-1.5.tar.gz', stream=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is functionality to download a file from a url here

def download_url_to_file(url: str, file_path: str, force: bool = False) -> None:


if r.status_code != 200:
print('METEOR setup failure.')
return
with open(output_file, 'wb') as f:
for chunk in r.iter_content(1024):
f.write(chunk)
with tarfile.open(output_file, 'r:gz') as f:
f.extractall(path=output_dir)
print('METEOR setup success')
20 changes: 9 additions & 11 deletions sacrerouge/metrics/rouge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import argparse
import logging
import zipfile
import os
import sys
from pathlib import Path
from collections import defaultdict
from overrides import overrides
from subprocess import Popen, PIPE
Expand Down Expand Up @@ -250,19 +252,15 @@ def run(self, args):
# No idea -- default to Linux
file_id = '1K4J2wHGjAyr3LoSgaQuWZ_YyjtUGf26m'

download_file_from_google_drive(file_id, f'{DATA_ROOT}/metrics/ROUGE-1.5.5.zip')

commands = [
f'cd {DATA_ROOT}/metrics',
f'unzip ROUGE-1.5.5.zip',
f'rm ROUGE-1.5.5.zip'
]
command = ' && '.join(commands)
output_dir = Path(f'{DATA_ROOT}/metrics')
output_file = output_dir / 'ROUGE-1.5.5.zip'

if not output_file.exists():
download_file_from_google_drive(file_id, output_file)

process = Popen(command, shell=True)
process.communicate()
if process.returncode != 0:
print('ROUGE setup failure')
with zipfile.ZipFile(output_file) as f:
f.extractall(output_dir)

# ROUGE has data files which may not successfully load. Therefore, if it fails to run on a simple example,
# the user needs to run some perl code within the ROUGE directory to correct the data file
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'pytest',
'requests',
'scipy>=1.5.2',
'networkx'
'networkx',
'spacy~=2.2'
]
)