gussieIsASuccessfulWarlock commited on
Commit
e5bb175
·
verified ·
1 Parent(s): 0f669b1

Support general forum replies and document Reddit evaluation

Browse files
Files changed (2) hide show
  1. README.md +5 -5
  2. inference.py +8 -3
README.md CHANGED
@@ -9,9 +9,9 @@ tags:
9
  - multi-head-classification
10
  ---
11
 
12
- # Reddit Reply Classifier
13
 
14
- This classifier labels a Reddit reply in context across five dimensions. It uses an [Ettin 400M encoder](https://huggingface.co/jhu-clsp/ettin-encoder-400m) with masked mean pooling and a separate softmax head for intent, style, harm, quality, and tone. The base encoder is MIT-licensed.
15
 
16
  ## Training and evaluation
17
 
@@ -37,7 +37,7 @@ from inference import classify, load
37
  model, tokenizer, groups = load(".", device="cpu")
38
  labels = classify(
39
  model, tokenizer, groups,
40
- subreddit="gardening",
41
  title="Basil on a windowsill",
42
  replying_to="How often should I water it?",
43
  reply="Check the soil first. Water it when the top feels dry.",
@@ -45,8 +45,8 @@ labels = classify(
45
  print({group: result["primary"] for group, result in labels.items()})
46
  ```
47
 
48
- For top-level replies, pass the post title and body together as `replying_to`. For nested replies, pass the immediate parent comment. The tokenizer truncates the context and reply pair to 384 tokens. The label vocabulary is in `info.json`.
49
 
50
  ## Limitations
51
 
52
- The reported scores measure top-1 agreement with Clef on held-out Reddit replies. No human agreement was measured. Per-label accuracy and performance on other platforms were also unevaluated. The student can inherit Clef's errors and the training corpus's biases. The label probabilities are uncalibrated. Use human review for consequential moderation decisions. The `ai_like` label measures a style category and cannot establish who authored a reply.
 
9
  - multi-head-classification
10
  ---
11
 
12
+ # Forum Reply Classifier
13
 
14
+ This classifier labels a forum reply in context across five dimensions. It was trained and evaluated on Reddit replies. It uses an [Ettin 400M encoder](https://huggingface.co/jhu-clsp/ettin-encoder-400m) with masked mean pooling and a separate softmax head for intent, style, harm, quality, and tone. The base encoder is MIT-licensed.
15
 
16
  ## Training and evaluation
17
 
 
37
  model, tokenizer, groups = load(".", device="cpu")
38
  labels = classify(
39
  model, tokenizer, groups,
40
+ community="Gardening",
41
  title="Basil on a windowsill",
42
  replying_to="How often should I water it?",
43
  reply="Check the soil first. Water it when the top feels dry.",
 
45
  print({group: result["primary"] for group, result in labels.items()})
46
  ```
47
 
48
+ Pass the forum or community name as `community`. For Reddit inputs, use `subreddit` with the bare subreddit name to reproduce the training input format. For top-level replies, pass the post title and body together as `replying_to`. For nested replies, pass the immediate parent comment. The tokenizer truncates the context and reply pair to 384 tokens. The label vocabulary is in `info.json`.
49
 
50
  ## Limitations
51
 
52
+ The reported scores measure top-1 agreement with Clef on held-out Reddit replies. No human agreement was measured. Per-label accuracy remains unmeasured. The generic forum input format and performance on other platforms have no benchmark results. The student can inherit Clef's errors and the training corpus's biases. The label probabilities are uncalibrated. Use human review for consequential moderation decisions. The `ai_like` label measures a style category and cannot establish who authored a reply.
inference.py CHANGED
@@ -1,4 +1,4 @@
1
- """Load and run the Clef student on paired Reddit context and replies."""
2
 
3
  import json
4
  from pathlib import Path
@@ -34,8 +34,13 @@ def load(directory, device="cpu"):
34
 
35
 
36
  @torch.inference_mode()
37
- def classify(model, tokenizer, groups, *, subreddit, title, replying_to, reply):
38
- context = f"r/{subreddit} | post: {title[:240]} | replying to: {replying_to[:900]}"
 
 
 
 
 
39
  inputs = tokenizer(context, reply[:1800], truncation=True, max_length=384,
40
  return_tensors="pt").to(next(model.parameters()).device)
41
  return {
 
1
+ """Load and run the Clef student on paired forum context and replies."""
2
 
3
  import json
4
  from pathlib import Path
 
34
 
35
 
36
  @torch.inference_mode()
37
+ def classify(model, tokenizer, groups, *, title, replying_to, reply,
38
+ community=None, subreddit=None):
39
+ """Classify a forum reply. The subreddit keyword preserves Reddit formatting."""
40
+ if (community is None) == (subreddit is None):
41
+ raise ValueError("Provide exactly one of community or subreddit.")
42
+ location = f"r/{subreddit}" if subreddit is not None else f"forum: {community}"
43
+ context = f"{location} | post: {title[:240]} | replying to: {replying_to[:900]}"
44
  inputs = tokenizer(context, reply[:1800], truncation=True, max_length=384,
45
  return_tensors="pt").to(next(model.parameters()).device)
46
  return {