mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-05 13:50:13 +06:00

* Reorganize example folder * Continue reorganization * Change requirements for tests * Final cleanup * Finish regroup with tests all passing * Copyright * Requirements and readme * Make a full link for the documentation * Address review comments * Apply suggestions from code review Co-authored-by: Lysandre Debut <lysandre@huggingface.co> * Add symlink * Reorg again * Apply suggestions from code review Co-authored-by: Thomas Wolf <thomwolf@users.noreply.github.com> * Adapt title * Update to new strucutre * Remove test * Update READMEs Co-authored-by: Lysandre Debut <lysandre@huggingface.co> Co-authored-by: Thomas Wolf <thomwolf@users.noreply.github.com>
23 lines
633 B
Python
23 lines
633 B
Python
import re
|
|
|
|
from filelock import FileLock
|
|
|
|
|
|
try:
|
|
import nltk
|
|
|
|
NLTK_AVAILABLE = True
|
|
except (ImportError, ModuleNotFoundError):
|
|
NLTK_AVAILABLE = False
|
|
|
|
if NLTK_AVAILABLE:
|
|
with FileLock(".lock") as lock:
|
|
nltk.download("punkt", quiet=True)
|
|
|
|
|
|
def add_newline_to_end_of_each_sentence(x: str) -> str:
|
|
"""This was added to get rougeLsum scores matching published rougeL scores for BART and PEGASUS."""
|
|
re.sub("<n>", "", x) # remove pegasus newline char
|
|
assert NLTK_AVAILABLE, "nltk must be installed to separate newlines between sentences. (pip install nltk)"
|
|
return "\n".join(nltk.sent_tokenize(x))
|