Skip to content

Instantly share code, notes, and snippets.

@koaning
Last active August 11, 2022 14:05
Show Gist options
  • Save koaning/f73503e8cd0a7cddafa206c656068df4 to your computer and use it in GitHub Desktop.
Save koaning/f73503e8cd0a7cddafa206c656068df4 to your computer and use it in GitHub Desktop.
A custom recipe for Prodigy that mimics Bionic Reading.
import pyphen
import prodigy
from prodigy.components.loaders import JSONL
from prodigy.components.db import connect
hyphenator = pyphen.Pyphen(lang="en_US")
def construct_html(text):
hyphend = hyphenator.inserted(text)
result = ""
for word in hyphend.split(" "):
if word[0] == "-":
word = word[1:]
if "-" not in word:
result += f"<span><b>{word[0]}</b>{word[1:]} </span>"
else:
first_dash = word.find("-")
word = word.replace("-", "")
result += f"<span><b>{word[:first_dash]}</b>{word[first_dash:]} </span>"
return result
@prodigy.recipe("bionic")
def bionic(dataset):
def get_stream():
data = [
{"text": "Bionic Reading is a new method of facilitating the reading process by guiding the eyes through text with artificial fixation points. As a result, the reader is only focusing on the highlighted initial letters and lets the brain center complete the word. In a digital world dominated by shallow forms of reading Bionic Reading aims to encourage a more in-depth reading and understanding of written content."}
]
for d in data:
d["html"] = construct_html(d["text"])
d["label"] = "DEMO"
yield d
return {
"dataset": dataset,
"view_id": "html",
"stream": get_stream(),
"config": {
# "global_css": ".prodigy-content{font-family: 'Courier New', monospace;} .prodigy-content b{font-weight: 900} .prodigy-content span{font-weight: 100}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment