Spaces:
Running
Running
eheguy commited on
Commit Β·
70a15ea
1
Parent(s): c0238b9
Improved few-shot examples and natural burstiness in Enhanced mode
Browse files- 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 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 79 |
|
| 80 |
-
Study these
|
| 81 |
|
| 82 |
{few_shot_examples}
|
| 83 |
|
| 84 |
-
|
| 85 |
-
-
|
| 86 |
-
-
|
| 87 |
-
-
|
| 88 |
-
-
|
| 89 |
-
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
-
|
| 95 |
-
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
-
|
| 99 |
-
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
WHAT NOT TO DO:
|
| 106 |
-
- Do not
|
| 107 |
-
|
| 108 |
-
- Do not
|
| 109 |
-
- Do not
|
| 110 |
-
- Do not
|
| 111 |
-
|
| 112 |
- Do not change the core meaning, facts, or argument.
|
| 113 |
|
| 114 |
OUTPUT:
|
| 115 |
- Rewritten text only.
|
| 116 |
-
- No introduction,
|
| 117 |
-
- Clean, readable
|
| 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 = {
|