Skip to content

Commit

Permalink
Add support for Hugging Face Transformers 4.x, upgrade libraries.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunneis committed Jul 31, 2023
1 parent 1776ced commit 5aef5ad
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 194 deletions.
3 changes: 3 additions & 0 deletions ernie/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 79
ignore = W503
9 changes: 9 additions & 0 deletions ernie/.style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[style]
based_on_style=pep8
column_limit=79
split_before_arithmetic_operator=true
split_before_logical_operator=true
split_before_named_assigns=true
split_before_first_argument=true
allow_split_before_dict_value=false
dedent_closing_brackets=true
4 changes: 2 additions & 2 deletions ernie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tensorflow.python.client import device_lib
import logging

__version__ = '1.0.1'
__version__ = '1.2307.0'

logging.getLogger().setLevel(logging.WARNING)
logging.getLogger("transformers.tokenization_utils").setLevel(logging.ERROR)
Expand All @@ -18,7 +18,7 @@
def _get_cpu_name():
import cpuinfo
cpu_info = cpuinfo.get_cpu_info()
cpu_name = f"{cpu_info['brand']}, {cpu_info['count']} vCores"
cpu_name = f"{cpu_info['brand_raw']}, {cpu_info['count']} vCores"
return cpu_name


Expand Down
33 changes: 10 additions & 23 deletions ernie/aggregation_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

class AggregationStrategy:
def __init__(
self,
method,
max_items=None,
top_items=True,
sorting_class_index=1
self, method, max_items=None, top_items=True, sorting_class_index=1
):
self.method = method
self.max_items = max_items
Expand All @@ -36,35 +32,26 @@ def aggregate(self, softmax_tuples):

softmax_list = []
for key in softmax_dicts[0].keys():
softmax_list.append(self.method(
[probabilities[key] for probabilities in softmax_dicts]))
softmax_list.append(
self.method(
[probabilities[key] for probabilities in softmax_dicts]
)
)
softmax_tuple = tuple(softmax_list)
return softmax_tuple


class AggregationStrategies:
Mean = AggregationStrategy(method=mean)
MeanTopFiveBinaryClassification = AggregationStrategy(
method=mean,
max_items=5,
top_items=True,
sorting_class_index=1
method=mean, max_items=5, top_items=True, sorting_class_index=1
)
MeanTopTenBinaryClassification = AggregationStrategy(
method=mean,
max_items=10,
top_items=True,
sorting_class_index=1
method=mean, max_items=10, top_items=True, sorting_class_index=1
)
MeanTopFifteenBinaryClassification = AggregationStrategy(
method=mean,
max_items=15,
top_items=True,
sorting_class_index=1
method=mean, max_items=15, top_items=True, sorting_class_index=1
)
MeanTopTwentyBinaryClassification = AggregationStrategy(
method=mean,
max_items=20,
top_items=True,
sorting_class_index=1
method=mean, max_items=20, top_items=True, sorting_class_index=1
)
Loading

0 comments on commit 5aef5ad

Please sign in to comment.