Skip to content

Commit 3f15572

Browse files
authored
add pytorch nlp example missing files (#630)
1 parent 401caf7 commit 3f15572

File tree

3 files changed

+687
-1
lines changed

3 files changed

+687
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2020 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import re
15+
16+
from filelock import FileLock
17+
18+
19+
try:
20+
import nltk
21+
22+
NLTK_AVAILABLE = True
23+
except (ImportError, ModuleNotFoundError):
24+
NLTK_AVAILABLE = False
25+
26+
if NLTK_AVAILABLE:
27+
with FileLock(".lock") as lock:
28+
nltk.download("punkt", quiet=True)
29+
30+
31+
def add_newline_to_end_of_each_sentence(x: str) -> str:
32+
"""This was added to get rougeLsum scores matching published rougeL scores for BART and PEGASUS."""
33+
re.sub("<n>", "", x) # remove pegasus newline char
34+
assert NLTK_AVAILABLE, "nltk must be installed to separate newlines between sentences. (pip install nltk)"
35+
return "\n".join(nltk.sent_tokenize(x))

0 commit comments

Comments
 (0)