-
Notifications
You must be signed in to change notification settings - Fork 2
Added NSFW text validator #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rkritika1508
wants to merge
41
commits into
main
Choose a base branch
from
feat/toxicity-huggingface-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
650369c
added toxicity detection validators
rkritika1508 949647d
fixed import error
rkritika1508 da50537
removed redundant validators
rkritika1508 9ab64c7
Added NSFW text validator
rkritika1508 b64d0e9
fixed test
rkritika1508 57d97b2
Merge branch 'feat/toxicity-hub-validators' into feat/toxicity-huggin…
rkritika1508 09b6a05
fix: profanity free validator description
dennyabrain f4a11fa
doc: updated details of sentence parameter
dennyabrain f330f1b
fix: remove vscode files
dennyabrain 51c9266
Added integration tests
rkritika1508 141e5fc
Merge branch 'main' into feat/toxicity-hub-validators
rkritika1508 c76f829
added integration tests
rkritika1508 baac9e4
fix: profanity free validator description
dennyabrain 627fb4f
Added integration tests
rkritika1508 8b3da89
validator config: add name to config (#79)
nishika26 cc0bb14
added integration tests
rkritika1508 3037eb8
Merge branch 'feat/toxicity-hub-validators' into feat/toxicity-huggin…
rkritika1508 b69883d
added integration tests
rkritika1508 8f67176
updated readme
rkritika1508 affe72d
Added installation of huggingface model in dockerfile
rkritika1508 8b0a183
resolved comment
rkritika1508 14f6dc1
removed blank line
rkritika1508 74f8a82
updated policies for llama guard
rkritika1508 6676414
fixed tests
rkritika1508 0d15d0c
Merge branch 'feat/toxicity-hub-validators' into feat/toxicity-huggin…
rkritika1508 6443c1b
updated readme and fixed llama guard inference
rkritika1508 af933ef
fixed test
rkritika1508 9b6616a
Merge branch 'feat/toxicity-hub-validators' into feat/toxicity-huggin…
rkritika1508 9aca5f2
Merge branch 'main' into feat/toxicity-hub-validators
rkritika1508 664ded8
resolved comments
rkritika1508 0ce6ebb
Added evaluation readme (#82)
rkritika1508 ba27b80
resolved comments
rkritika1508 d7c5eba
resolved comments
rkritika1508 02fd043
fixed llama guard
rkritika1508 d9569ba
Merge branch 'feat/toxicity-hub-validators' into feat/toxicity-huggin…
rkritika1508 31af2f6
Toxicity Detection validators (#80)
rkritika1508 a061af8
Merge branch 'main' into feat/toxicity-huggingface-model
rkritika1508 88c1b56
removed unnecessary changes
rkritika1508 5b2fe3b
fix: update default nsfw_text model to michellejieli/NSFW_text_classi…
rkritika1508 fd3cddc
fix: use textdetox/xlmr-large-toxicity-classifier as default nsfw_tex…
rkritika1508 7264771
updated readme
rkritika1508 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
backend/app/core/validators/config/llamaguard_7b_safety_validator_config.py
This file contains hidden or 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,16 @@ | ||
| from typing import List, Literal, Optional | ||
|
|
||
| from guardrails.hub import LlamaGuard7B | ||
|
|
||
| from app.core.validators.config.base_validator_config import BaseValidatorConfig | ||
|
|
||
|
|
||
| class LlamaGuard7BSafetyValidatorConfig(BaseValidatorConfig): | ||
| type: Literal["llamaguard_7b"] | ||
| policies: Optional[List[str]] = None | ||
|
|
||
| def build(self): | ||
| return LlamaGuard7B( | ||
| policies=self.policies, | ||
| on_fail=self.resolve_on_fail(), | ||
| ) |
22 changes: 22 additions & 0 deletions
22
backend/app/core/validators/config/nsfw_text_safety_validator_config.py
This file contains hidden or 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,22 @@ | ||
| from typing import Literal, Optional | ||
|
|
||
| from guardrails.hub import NSFWText | ||
|
|
||
| from app.core.validators.config.base_validator_config import BaseValidatorConfig | ||
|
|
||
|
|
||
| class NSFWTextSafetyValidatorConfig(BaseValidatorConfig): | ||
| type: Literal["nsfw_text"] | ||
| threshold: float = 0.8 | ||
| validation_method: str = "sentence" | ||
| device: Optional[str] = "cpu" | ||
| model_name: Optional[str] = "textdetox/xlmr-large-toxicity-classifier" | ||
|
|
||
| def build(self): | ||
| return NSFWText( | ||
| threshold=self.threshold, | ||
| validation_method=self.validation_method, | ||
| device=self.device, | ||
| model_name=self.model_name, | ||
| on_fail=self.resolve_on_fail(), | ||
| ) | ||
14 changes: 14 additions & 0 deletions
14
backend/app/core/validators/config/profanity_free_safety_validator_config.py
This file contains hidden or 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,14 @@ | ||
| from typing import Literal | ||
|
|
||
| from guardrails.hub import ProfanityFree | ||
|
|
||
| from app.core.validators.config.base_validator_config import BaseValidatorConfig | ||
|
|
||
|
|
||
| class ProfanityFreeSafetyValidatorConfig(BaseValidatorConfig): | ||
| type: Literal["profanity_free"] | ||
|
|
||
| def build(self): | ||
| return ProfanityFree( | ||
| on_fail=self.resolve_on_fail(), | ||
| ) |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.