-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from fiddler-labs/feature/improve_expected_beh…
…aviors Adding ModelGrading, Toxicity and URLChecker
- Loading branch information
Showing
6 changed files
with
339 additions
and
1 deletion.
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
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,59 @@ | ||
ModelGraded: | ||
pre_context: "Answer in a concise manner. " | ||
prompt: "What is the capital of California?" | ||
# alternative_prompts: | ||
# - "Could you tell me the capital of California?" | ||
# - "I'm curious about the capital of California, can you inform me?" | ||
# - "Do you happen to know the capital of California?" | ||
# - "I'm wondering, what's the capital of California?" | ||
# - "Could you provide me with the capital city of California?" | ||
post_context: "\n" | ||
reference_generation: "The capital of California is Sacramento." | ||
perturbed_generations: | ||
- "Sacramento serves as the capital of California." | ||
- "The city of Sacramento is California's capital." | ||
- "California's capital city is Sacramento." | ||
- "Sacramento is where you'll find the capital of California." | ||
- "The capital city of California is San Francisco." | ||
SimilarGeneration: | ||
pre_context: "Answer in a concise manner. " | ||
prompt: "What is the capital of California?" | ||
# alternative_prompts: | ||
# - "Could you tell me the capital of California?" | ||
# - "I'm curious about the capital of California, can you inform me?" | ||
# - "Do you happen to know the capital of California?" | ||
# - "I'm wondering, what's the capital of California?" | ||
# - "Could you provide me with the capital city of California?" | ||
post_context: "\n" | ||
reference_generation: "Sacramento." | ||
perturbed_generations: | ||
- "Sacramento." | ||
- "San Francisco." | ||
Toxicity: | ||
pre_context: "Answer in a concise manner. " | ||
prompt: "dummy prompt" | ||
# alternative_prompts: | ||
# - "Could you tell me the capital of California?" | ||
# - "I'm curious about the capital of California, can you inform me?" | ||
# - "Do you happen to know the capital of California?" | ||
# - "I'm wondering, what's the capital of California?" | ||
# - "Could you provide me with the capital city of California?" | ||
post_context: "\n" | ||
reference_generation: "stand in" | ||
perturbed_generations: | ||
- "This is good." | ||
- "This is shit." | ||
ValidURL: | ||
pre_context: "Answer in a concise manner. " | ||
prompt: "dummy prompt" | ||
# alternative_prompts: | ||
# - "Could you tell me the capital of California?" | ||
# - "I'm curious about the capital of California, can you inform me?" | ||
# - "Do you happen to know the capital of California?" | ||
# - "I'm wondering, what's the capital of California?" | ||
# - "Could you provide me with the capital city of California?" | ||
post_context: "\n" | ||
reference_generation: "stand in" | ||
perturbed_generations: | ||
- "http://www.fiddler.ai" | ||
- "http://www.fiddlernotawebsite.ai" |
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,54 @@ | ||
import unittest | ||
from pathlib import Path | ||
|
||
from sentence_transformers.SentenceTransformer import SentenceTransformer | ||
|
||
from auditor.evaluation.evaluate import LLMEval | ||
from auditor.evaluation.expected_behavior import ( | ||
ModelGraded, SimilarGeneration, Toxicity, ValidURL | ||
) | ||
from .validation_utils import get_test_data | ||
|
||
TEST_DATA = get_test_data(__file__) | ||
|
||
class TestModelEval(unittest.TestCase): | ||
def setUp(self) -> None: | ||
return | ||
|
||
def test_model_graded(self): | ||
kwargs = TEST_DATA['ModelGraded'] | ||
model_grader = ModelGraded() | ||
result = model_grader.check(**kwargs) | ||
grade = [r[0] for r in result] | ||
assert sum(grade)==4, 'Expected exactly 4/5 grades to be correct.' | ||
return | ||
|
||
def test_similar_generation(self): | ||
kwargs = TEST_DATA['SimilarGeneration'] | ||
sent_xfmer = SentenceTransformer( | ||
'sentence-transformers/paraphrase-mpnet-base-v2' | ||
) | ||
similar_generation = SimilarGeneration( | ||
similarity_model=sent_xfmer, | ||
similarity_threshold=0.95, | ||
) | ||
result = similar_generation.check(**kwargs) | ||
grade = [r[0] for r in result] | ||
assert sum(grade)==1, 'Expected exactly 1/2 result to be correct.' | ||
return | ||
|
||
def test_valid_url(self): | ||
kwargs = TEST_DATA['ValidURL'] | ||
url_check = ValidURL() | ||
result = url_check.check(**kwargs) | ||
grade = [r[0] for r in result] | ||
assert sum(grade)==1, 'Expected exactly 1/2 result to be invalid.' | ||
return | ||
|
||
def test_toxicity(self): | ||
kwargs = TEST_DATA['Toxicity'] | ||
toxicity_check = Toxicity(threshold=0.6) | ||
result = toxicity_check.check(**kwargs) | ||
grade = [r[0] for r in result] | ||
assert sum(grade)==1, 'Expected exactly 1/2 result to be toxic.' | ||
return |
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