File tree Expand file tree Collapse file tree 3 files changed +687
-1
lines changed
examples/pytorch/nlp/huggingface_models
seq2seq/quantization/ptq_dynamic/eager
text-classification/quantization/ptq_static/eager Expand file tree Collapse file tree 3 files changed +687
-1
lines changed Original file line number Diff line number Diff line change 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 ))
You can’t perform that action at this time.
0 commit comments