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

Pip installable package #2

Closed
wants to merge 10 commits into from
Closed
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
160 changes: 160 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
6 changes: 3 additions & 3 deletions NewsRoomEval.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import time
import numpy as np
from metrics.utils import *
from disco_score.metrics.utils import *

# We adapt the evaluation framework of BARTScore to evaluate DiscoScore on NewsRoom.
# See https://github.com/neulab/BARTScore/blob/main/SUM/score.py
Expand Down Expand Up @@ -56,7 +56,7 @@ def score(self):

if self.args.m == 'bart_score' or self.args.m == 'bart_score_cnn' or self.args.m == 'bart_score_para':
""" Vanilla BARTScore, BARTScore-CNN, BARTScore-CNN-Para """
from metrics.bart_score import BARTScorer
from disco_score.metrics.bart_score import BARTScorer
# Set up BARTScore
if 'cnn' in self.args.m:
bart_scorer = BARTScorer(device=self.device, checkpoint='facebook/bart-large-cnn')
Expand Down Expand Up @@ -108,7 +108,7 @@ def score(self):

elif self.args.m.startswith('DS_Focus') or self.args.m.startswith('DS_SENT'):

from metrics.metrics import Metrics
from disco_score.metrics.metrics import Metrics

eval_metric = getattr(Metrics(args = self.args), self.args.m)

Expand Down
2 changes: 1 addition & 1 deletion Newsroom/analysis_Newsroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import collections
import pickle
from metrics.utils import *
from disco_score.metrics.utils import *

class SUMStat:
""" A class used to get stats of SUM trained data """
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ DiscoScore is a parameterized, reference-based evaluation, with parameters on th

# Usage

Install from GitHub with pip:

```bash
pip install "git+https://github.com/AIPHES/DiscoScore.git"
```

Please run [SUMMEval.py](https://github.com/AIPHES/DiscoScore/blob/main/SUMMEval.py) to reproduce the results in our paper.

Note that DS_Focus uses [Conpono](https://drive.google.com/drive/folders/1FE2loCSfdBbYrYk_qHg6W_PTqvA9w46T?usp=sharing) (finetuned BERT on discourse corpora), and DS_SENT uses [BERT-NLI](https://drive.google.com/drive/folders/19-6TgHdfAVL6xzpqzMoTpxXKLkXOCBiO?usp=sharing) (finetuned BERT on NLI). Because this configuration performs best in our intial trials (see the paper for details).
Expand All @@ -23,9 +29,12 @@ Note that if system and reference texts do not contain coherence phenomena (e.g.

```python
from DiscoScorer import DiscoScorer

disco_scorer = DiscoScorer(device='cuda:0', model_name='bert-base-uncased') # use Conpono for DS-Focus and BERT-NLI for DS-SENT for better results

system = ["Paul Merson has restarted his row with andros townsend after the Tottenham midfielder was brought on with only seven minutes remaining in his team 's 0-0 draw with burnley. Townsend was brought on in the 83rd minute for Tottenham as they drew 0-0 against Burnley ."]
references = [["Paul Merson has restarted his row with burnley on sunday. Townsend was brought on in the 83rd minute for tottenham. Andros Townsend scores england 's equaliser in their 1-1 friendly draw. Townsend hit a stunning equaliser for england against italy."]]

for s, refs in zip(system, references):
s = s.lower()
refs = [r.lower() for r in refs]
Expand Down
2 changes: 1 addition & 1 deletion SUMMEval.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def generate_human_scores(self, num_instances, qa):


import argparse
from metrics.metrics import Metrics
from disco_score.metrics.metrics import Metrics
from scipy.stats import kendalltau

parser = argparse.ArgumentParser()
Expand Down
3 changes: 3 additions & 0 deletions disco_score/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = "0.1.0"

from .scorer import DiscoScorer
Empty file added disco_score/metrics/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions metrics/discourse.py → disco_score/metrics/discourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _safe_divide(numerator, denominator):

def DS_Focus(model, tokenizer, sys, ref, is_semantic_entity=False, we=None, threshold=0):

from metrics.focus_diff import get_embeddings
from disco_score.metrics.focus_diff import get_embeddings

scores = []
s_embedding, s_noun_positions = get_embeddings(model, tokenizer, sys, is_semantic_entity,
Expand All @@ -147,7 +147,7 @@ def DS_Focus(model, tokenizer, sys, ref, is_semantic_entity=False, we=None, thre

def DS_Sent(model, tokenizer, sys, ref, is_lexical_graph=False, we=None, threshold=0):

from metrics.sent_graph import get_embeddings
from disco_score.metrics.sent_graph import get_embeddings

scores = []
sys_u_a, num_sentences = EntityGraph(sys, is_lexical_graph, we, threshold)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions metrics/metrics.py → disco_score/metrics/metrics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from metrics import discourse
from metrics.word_embeddings import load_embeddings
from disco_score.metrics import discourse
from disco_score.metrics.word_embeddings import load_embeddings
from transformers import *
import torch

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions DiscoScorer.py → disco_score/scorer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from metrics import discourse
from metrics.word_embeddings import load_embeddings
from disco_score.metrics import discourse
from disco_score.metrics.word_embeddings import load_embeddings
from transformers import BertConfig, BertTokenizer, BertModel
import torch

Expand Down
Binary file removed metrics/__pycache__/discourse.cpython-38.pyc
Binary file not shown.
Binary file removed metrics/__pycache__/focus_diff.cpython-38.pyc
Binary file not shown.
Binary file removed metrics/__pycache__/metrics.cpython-38.pyc
Binary file not shown.
Binary file removed metrics/__pycache__/sent_graph.cpython-38.pyc
Binary file not shown.
Binary file removed metrics/__pycache__/utils.cpython-38.pyc
Binary file not shown.
Binary file removed metrics/__pycache__/word_embeddings.cpython-38.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import setuptools

setuptools.setup(
name="disco_score",
version="0.1.0",
description="DiscoScore: Evaluating Text Generation with BERT and Discourse Coherence",
author="Wei Zhao",
url="https://github.com/AIPHES/DiscoScore",
python_requires=">=3.6",
packages=setuptools.find_packages(),
install_requires=[
"torch>=1.6.0",
"transformers>=4.6.1",
"nltk>=3.7.0",
"spacy>=3.3.1",
"spacy_udpipe>=1.0.0",
"networkx>=2.8.4",
],
)