NimaBoscarino commited on
Commit
b4f5e30
1 Parent(s): fcf596e

WIP: Intended Purpose check

Browse files
Files changed (3) hide show
  1. app.py +1 -0
  2. compliance_checks.py +25 -15
  3. tests/test_compliance_checks.py +3 -5
app.py CHANGED
@@ -6,6 +6,7 @@ from compliance_checks import (
6
  IntendedPurposeCheck
7
  )
8
 
 
9
  def run_compliance_check(repo_name):
10
  model_card = ModelCard.load(repo_id_or_path=repo_name).content
11
 
 
6
  IntendedPurposeCheck
7
  )
8
 
9
+
10
  def run_compliance_check(repo_name):
11
  model_card = ModelCard.load(repo_id_or_path=repo_name).content
12
 
compliance_checks.py CHANGED
@@ -25,27 +25,37 @@ class ModelProviderIdentityCheck(ComplianceCheck):
25
  return False, None
26
 
27
 
28
- class IntendedPurposeCheck(ComplianceCheck):
29
- def run_check(self, card: BeautifulSoup):
30
- try:
31
- direct_use = card.find("h3", string="Direct Use")
32
 
33
- direct_use_content = ""
34
 
35
- sibling_gen = direct_use.nextSiblingGenerator()
 
 
 
 
 
36
  sibling = next(sibling_gen)
37
 
38
- while sibling.name != "h3":
39
- if not isinstance(sibling, Comment):
40
- direct_use_content = direct_use_content + sibling.text
41
- sibling = next(sibling_gen)
42
 
43
- if direct_use_content.strip() == "[More Information Needed]":
44
- return False, None
 
45
 
46
- return True, None
47
- except AttributeError:
48
- return False, None
 
 
 
 
 
 
 
49
 
50
 
51
  class ComplianceSuite:
 
25
  return False, None
26
 
27
 
28
+ def walk_to_next_heading(card, heading, heading_text):
29
+ try:
30
+ heading_node = card.find(heading, string=heading_text)
 
31
 
32
+ content = ""
33
 
34
+ sibling_gen = heading_node.nextSiblingGenerator()
35
+ sibling = next(sibling_gen)
36
+
37
+ while not (sibling.name is not None and sibling.name.startswith("h")) or sibling.name is None:
38
+ if not isinstance(sibling, Comment):
39
+ content = content + sibling.text.strip()
40
  sibling = next(sibling_gen)
41
 
42
+ if content.strip() == "[More Information Needed]":
43
+ return False, None
 
 
44
 
45
+ return True, content
46
+ except AttributeError:
47
+ return False, None
48
 
49
+
50
+ class IntendedPurposeCheck(ComplianceCheck):
51
+ def run_check(self, card: BeautifulSoup):
52
+ direct_use_check, direct_use_content = walk_to_next_heading(card, "h3", "Direct Use")
53
+ downstream_use_check, downstream_use_content = walk_to_next_heading(card, "h3", "Downstream Use [optional]")
54
+ out_of_scope_use_check, out_of_scope_use_content = walk_to_next_heading(card, "h3", "Out-of-Scope Use")
55
+ return (
56
+ direct_use_check and out_of_scope_use_check,
57
+ [direct_use_content, downstream_use_content, out_of_scope_use_content]
58
+ )
59
 
60
 
61
  class ComplianceSuite:
tests/test_compliance_checks.py CHANGED
@@ -52,8 +52,6 @@ Some random info...
52
 
53
  ### Direct Use
54
 
55
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
56
-
57
  Here is some info about direct uses...
58
 
59
  ### Downstream Use [optional]
@@ -66,7 +64,7 @@ Here is some info about direct uses...
66
 
67
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
68
 
69
- [More Information Needed]
70
 
71
  ## Bias, Risks, and Limitations
72
 
@@ -114,8 +112,8 @@ Some random info...
114
  @pytest.mark.parametrize("check, card,check_passed,values", [
115
  (ModelProviderIdentityCheck(), "provider_identity_model_card", True, "Nima Boscarino"),
116
  (ModelProviderIdentityCheck(), "bad_provider_identity_model_card", False, None),
117
- (IntendedPurposeCheck(), "intended_purpose_model_card", True, None),
118
- (IntendedPurposeCheck(), "bad_intended_purpose_model_card", False, None),
119
  ])
120
  def test_run_model_provider_identity_check(self, check, card, check_passed, values, request):
121
  card = request.getfixturevalue(card)
 
52
 
53
  ### Direct Use
54
 
 
 
55
  Here is some info about direct uses...
56
 
57
  ### Downstream Use [optional]
 
64
 
65
  <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
66
 
67
+ Here is some info about out-of-scope uses...
68
 
69
  ## Bias, Risks, and Limitations
70
 
 
112
  @pytest.mark.parametrize("check, card,check_passed,values", [
113
  (ModelProviderIdentityCheck(), "provider_identity_model_card", True, "Nima Boscarino"),
114
  (ModelProviderIdentityCheck(), "bad_provider_identity_model_card", False, None),
115
+ (IntendedPurposeCheck(), "intended_purpose_model_card", True, ["Here is some info about direct uses...", None, "Here is some info about out-of-scope uses..."]),
116
+ (IntendedPurposeCheck(), "bad_intended_purpose_model_card", False, [None, None, None]),
117
  ])
118
  def test_run_model_provider_identity_check(self, check, card, check_passed, values, request):
119
  card = request.getfixturevalue(card)