-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GSK-852] Change Tensorflow to latest version, to enable arm64 test a…
…gain
- Loading branch information
Showing
12 changed files
with
772 additions
and
667 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pandas as pd | ||
from transformers import pipeline | ||
|
||
|
||
# Re-implementation based on https://github.com/unitaryai/detoxify/issues/15#issuecomment-900443551 | ||
class Detoxify: | ||
def __init__( | ||
self, | ||
): | ||
super().__init__() | ||
self.pipeline = pipeline( | ||
"text-classification", | ||
model="unitary/unbiased-toxic-roberta", | ||
tokenizer="unitary/unbiased-toxic-roberta", | ||
function_to_apply="sigmoid", | ||
return_all_scores=True, | ||
) | ||
|
||
def predict(self, text) -> pd.DataFrame: | ||
inputs = [text] if isinstance(text, str) else text | ||
results = self.pipeline(inputs) | ||
output = [] | ||
for one_result in results: | ||
res = {} | ||
for single_label_result in one_result: | ||
res[single_label_result["label"]] = single_label_result["score"] | ||
output.append(res) | ||
output = pd.DataFrame(output) | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.