eheguy commited on
Commit
70a15ea
Β·
1 Parent(s): c0238b9

Improved few-shot examples and natural burstiness in Enhanced mode

Browse files
Files changed (1) hide show
  1. humanizer.py +90 -64
humanizer.py CHANGED
@@ -6,40 +6,48 @@ from groq import Groq
6
  # what natural human prose looks like β€” varied, imperfect, personal.
7
 
8
  FEW_SHOT_EXAMPLES = """
9
- Here are examples of genuine human writing. Study the rhythm, word choice,
10
- sentence variety, and natural imperfections. Imitate this style:
11
-
12
- EXAMPLE 1 (Blog/Casual):
13
- "I've been thinking about this for weeks now, and I still don't have a clean answer.
14
- Social media is weird. Not bad-weird necessarily, just... complicated. You get on
15
- there to stay in touch with people, and somehow you end up knowing the political
16
- opinions of your dentist's cousin. Nobody asked for that. And yet here we are,
17
- scrolling at midnight, wondering why we feel vaguely terrible.
18
- The thing nobody tells you is that the platform is working exactly as intended."
19
-
20
- EXAMPLE 2 (Professional/Analytical):
21
- "The numbers don't lie, but they don't tell the whole story either. Last quarter
22
- looked rough on paper β€” revenue down 8%, customer churn up slightly. But dig
23
- into the cohort data and a different picture emerges. The customers we acquired
24
- after the rebrand are sticking around. The ones leaving? Almost entirely
25
- pre-2022 signups who never really fit the new direction anyway.
26
- That's not a crisis. That's a transition."
27
-
28
- EXAMPLE 3 (Academic/Formal):
29
- "The assumption that technological adoption follows a predictable S-curve has
30
- shaped product strategy for decades. What this model fails to account for,
31
- however, is the role of social trust in accelerating or stalling diffusion.
32
- When communities perceive a technology as threatening existing power structures β€”
33
- regardless of its actual utility β€” adoption stalls in ways the curve simply
34
- cannot predict. The data from the 2019 contact tracing rollout illustrates
35
- this precisely."
36
-
37
- EXAMPLE 4 (Personal/Reflective):
38
- "My grandfather never owned a computer. He died at 91, having written every
39
- letter by hand, remembered every phone number, and navigated every city
40
- with a paper map he'd fold wrong every single time. I used to think that
41
- was a limitation. I'm less sure now. There's something to be said for a
42
- life where the information you carry is only what your mind decided to keep."
 
 
 
 
 
 
 
 
43
  """
44
 
45
  # ── SIMPLE ────────────────────────────────────────────────────────────────────
@@ -75,46 +83,64 @@ Rules:
75
  11. Output ONLY the rewritten text. No preamble. No explanation."""
76
 
77
  # ── ENHANCED ──────────────────────────────────────────────────────────────────
78
- ENHANCED_PROMPT = """You are an expert human writer. Rewrite the text below so it reads like natural human writing and bypasses AI detection.
 
79
 
80
- Study these human writing examples first:
81
 
82
  {few_shot_examples}
83
 
84
- SENTENCE STRUCTURE RULES (follow exactly):
85
- - Every paragraph must contain at least one sentence under 7 words.
86
- - Every paragraph must contain at least one sentence over 25 words.
87
- - Never write two sentences of similar length back to back.
88
- - Use sentence fragments occasionally. Like this. They work.
89
- - One sentence per paragraph can be a question the writer asks themselves.
90
-
91
- WORD CHOICE RULES:
92
- - Never use these words: tapestry, delve, testament, beacon, foster, align, overarching, landscape, seamlessly, groundbreaking, revolutionary, pivotal, crucial, vital, robust, leverage, utilize, facilitate, commence, endeavor, multifaceted.
93
- - Avoid the most obvious word choice. Pick the second or third most natural option.
94
- - Mix formal and casual words in the same paragraph deliberately.
95
- - Use contractions naturally in 30% of sentences.
96
-
97
- STYLE RULES:
98
- - Remove these phrases entirely: "It is important to note", "Furthermore", "Moreover", "In conclusion", "When it comes to", "It is worth noting", "Needless to say", "It goes without saying", "It is crucial to", "One must consider".
99
- - No hyphens (-), em dashes (β€”), or en dashes (–). Use commas or new sentences.
100
- - No perfectly balanced bullet lists. Break them into prose.
101
- - Add one parenthetical thought somewhere that sounds natural.
102
- - Add one personal observation or opinion β€” one moment that sounds like a real person wrote this.
103
- - Flip passive voice to active voice throughout.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
  WHAT NOT TO DO:
106
- - Do not chain clauses together with endless commas.
107
- - Do not write run-on sentences stuffed with comma-connected phrases.
108
- - Do not repeat the same sentence structure twice in a row.
109
- - Do not add filler phrases to make sentences longer.
110
- - Do not use hyphenated compound words like "not-so-great" or "laid-back".
111
- Rewrite them as plain phrases instead (e.g. "not great", "relaxed").
112
  - Do not change the core meaning, facts, or argument.
113
 
114
  OUTPUT:
115
  - Rewritten text only.
116
- - No introduction, no explanation, no "Here is the rewritten version".
117
- - Clean, readable, natural prose that sounds like a human wrote it."""
118
 
119
  # ── READABILITY MODIFIERS ─────────────────────────────────────────────────────
120
  READABILITY_MODIFIERS = {
 
6
  # what natural human prose looks like β€” varied, imperfect, personal.
7
 
8
  FEW_SHOT_EXAMPLES = """
9
+ Study these human writing samples. Pay attention to how short sentences
10
+ arise NATURALLY from the content β€” they are never inserted randomly.
11
+ Notice how specific details make the writing feel real.
12
+ Notice how paragraphs have integrity β€” they develop one idea fully.
13
+
14
+ EXAMPLE 1 (Student Essay / Neutral):
15
+ "The relationship between sleep and academic performance is more complicated
16
+ than most students realize. It is not simply a matter of getting eight hours.
17
+ The timing matters, the quality matters, and the consistency across the week
18
+ matters more than any single night of good rest. Students who sleep well before
19
+ exams but stay up until 3am on weekdays are not doing themselves any favors.
20
+ The brain consolidates memory during sleep, and disrupting that process even
21
+ occasionally can set back retention in ways that are hard to recover from."
22
+
23
+ EXAMPLE 2 (Blog / Casual):
24
+ "Nobody tells you how strange it feels to delete Instagram for the first time.
25
+ You expect to feel free. Instead, you keep reaching for your phone out of habit,
26
+ unlocking it, staring at the home screen, and then putting it back down. The
27
+ app is gone but the impulse isn't. That takes weeks to fade. And once it does,
28
+ you start noticing things you missed β€” conversations, meals, the specific quality
29
+ of light at 4pm that you used to photograph instead of just watch."
30
+
31
+ EXAMPLE 3 (Academic / Formal):
32
+ "Research into adolescent social media use has consistently identified a
33
+ correlation between time spent on image-based platforms and self-reported
34
+ measures of body dissatisfaction. What remains less clear is the direction
35
+ of causality. Adolescents who already experience low self-esteem may be
36
+ drawn to platforms where social comparison is constant, rather than
37
+ developing low self-esteem as a result of those platforms. Disentangling
38
+ these two pathways requires longitudinal data that most existing studies
39
+ lack. The policy implications differ significantly depending on which
40
+ explanation proves more accurate."
41
+
42
+ EXAMPLE 4 (Personal / Reflective):
43
+ "My grandmother kept a garden her entire adult life. Not a beautiful garden β€”
44
+ a practical one, full of tomatoes and peppers and herbs she actually used.
45
+ She never posted photos of it. Never thought to. The garden existed for its
46
+ own sake, and for the people she fed, and that was enough. I think about
47
+ that sometimes when I catch myself arranging food on a plate before eating
48
+ it, trying to get the light right, framing the shot. Something has shifted
49
+ in how we understand the value of an experience. I am not sure the shift
50
+ has been entirely good."
51
  """
52
 
53
  # ── SIMPLE ────────────────────────────────────────────────────────────────────
 
83
  11. Output ONLY the rewritten text. No preamble. No explanation."""
84
 
85
  # ── ENHANCED ──────────────────────────────────────────────────────────────────
86
+ ENHANCED_PROMPT = """You are an expert human writer and editor. Your job is to
87
+ rewrite the provided text so it reads like authentic human writing.
88
 
89
+ Study these examples of genuine human prose carefully:
90
 
91
  {few_shot_examples}
92
 
93
+ Notice what makes them human:
94
+ - Short sentences arise from the content naturally, never inserted randomly
95
+ - Paragraphs develop one idea fully before moving on
96
+ - Specific concrete details instead of vague gestures
97
+ - The writer's perspective shows up occasionally, never forced
98
+ - Transitions feel earned, not mechanical
99
+
100
+ Now rewrite the user's text following these rules:
101
+
102
+ STRUCTURE:
103
+ - Preserve the original paragraph structure. Do not break paragraphs apart randomly.
104
+ - Within each paragraph, vary sentence length naturally. Let short sentences
105
+ emerge from the content β€” a short sentence works when it lands a point,
106
+ not just to break up length.
107
+ - Never write three sentences of similar length in a row.
108
+ - One sentence fragment per 2-3 paragraphs is fine if it feels natural.
109
+
110
+ WORD CHOICE:
111
+ - Never use: tapestry, delve, testament, beacon, foster, align, overarching,
112
+ landscape, seamlessly, groundbreaking, revolutionary, pivotal, crucial, vital,
113
+ robust, leverage, utilize, facilitate, commence, endeavor, multifaceted.
114
+ - Remove: "It is important to note", "Furthermore", "Moreover", "In conclusion",
115
+ "When it comes to", "It is worth noting", "Needless to say",
116
+ "It goes without saying", "It is crucial to", "One must consider".
117
+ - Avoid the most predictable word choice. Pick the second or third most
118
+ natural synonym.
119
+ - Use specific concrete details where the original is vague.
120
+ - Mix formal and casual register occasionally β€” one plain word in a formal
121
+ sentence, one precise word in a casual sentence.
122
+
123
+ VOICE:
124
+ - Add one moment per essay where the writer's perspective shows β€” a brief
125
+ observation, not a forced aside. It should feel earned by the surrounding text.
126
+ - Use contractions in 25-35% of sentences.
127
+ - Flip passive voice to active where it sounds more natural.
128
+ - No hyphens (-), em dashes (β€”), en dashes (–), or hyphenated compound words.
129
+ Rewrite them as plain phrases.
130
 
131
  WHAT NOT TO DO:
132
+ - Do not insert short sentences randomly to hit a length target.
133
+ Short sentences must arise from the content.
134
+ - Do not chain clauses with endless commas.
135
+ - Do not break up paragraphs that belong together.
136
+ - Do not add filler phrases to pad length.
137
+ - Do not use hyphenated compounds like "not-so-great" or "laid-back".
138
  - Do not change the core meaning, facts, or argument.
139
 
140
  OUTPUT:
141
  - Rewritten text only.
142
+ - No introduction, explanation, or "Here is the rewritten version".
143
+ - Clean, readable prose that sounds like a thoughtful human wrote it."""
144
 
145
  # ── READABILITY MODIFIERS ─────────────────────────────────────────────────────
146
  READABILITY_MODIFIERS = {