Code Monkey home page Code Monkey logo

Comments (7)

dougvalenta avatar dougvalenta commented on June 22, 2024

When humans craft prose (and especially poetry), they often use repetition to construct meaning. A classic example is the last two lines of Robert Frost's "Stopping By the Woods On a Snowy Evening." In "The Prophets' Paradise," the repetition (which almost always introduces some variation, either a reordering of phrases, dropping, adding, or changing an adjective or adverb, et cetera) is a lot of what adds a ritualistic and mystical quality to the writing.

On the other hand, repetition is a common undesirable artifact of machine-generated work. So for me, I think the central problem I'm trying to address is creating a repetitious machine that doesn't seem mechanically repetitive -- the repetition should seem meaningful, and invite the reader to play off the repeated (and varied) elements to try to construct additional meaning in their mind.

from 2017.

dougvalenta avatar dougvalenta commented on June 22, 2024

Last night I wrote a replacement grammar engine for Java (similar to Tracery), and a little L-System processor. I'm seeing that the biggest impact on this project is going to be developing and tuning good, large grammars and corpora, so I'm trying to build as much tooling around this as early as possible.

The syntax for the replacement grammar is very natural (at least to me). It's basically a properties file (newline-delimited key-value pairs in the form key=value), where the key is a symbol, and the value is the replacement rule. Inside the rule, additional symbols can be inserted by name wrapped in square brackets. Any text or symbols inside parens are optional (50-50 chance of appearing). Segments inside parens divided by bars ("|") will be selected from (even chance for each option). In this sense, parens with no bar is really shorthand for "(optional text|)"

Here's a sample grammar:

root = Hello, [place](, how are you?)
place = (world|NaNoGenMo)

Piggybacking of the Java properties file format gets me proper trimming of leading and trailing whitespace (incl. whitespace around the first equal sign) and comments (demarcated with a "#") for free.

The L-system processor is what I'm planning on using to define the form of my stanzas. It's syntax is much similar, also based on properties file.

+ = ++|++-|+++--
- = +-|++--|+++---

Again, the bars are dividing different potential selections (so this is a stochastic system). It doesn't really have a concept of terminal vs. non-terminal symbols (I don't really need that for my purposes), you just feed it an iteration count. If a symbol in the input doesn't have a rule in the grammar, it just gets copied to the output. So with a properly designed grammar and sufficient iterations, you could end up with all terminal symbols, but the engine won't detect that for you.

from 2017.

dougvalenta avatar dougvalenta commented on June 22, 2024

Things are beginning to come together. I combined together a grammar and an L-system to compose a stanza generator. Right now I have it generating boring little prose poems about nature. Here's an example:

"Ode to a Pond"

O, twisting boughs.
Worried reeds tangling wildly.
Softly, needles.
Worried reeds tangling wildly.
O, twisting boughs.
Eerily, green boughs bobbing.

The title and each line are generated by a replacement grammar, and the order of the lines and their repetition is generated by an L-system.

The end goal is to produce output like this where when each line repeats it mutates in some way (reorganization of clauses, changing a word, lobbing off a clause, et cetera). This will require retaining some of the structural information about how the line is created, not just the string, so that individual elements can be tweaked.

Yesterday I also wrote an algorithm for selecting from corpora without replacement, and a system for inflecting terms (e.g. for case, tense, number, et cetera). Need to combine that together with a big to-do item which is a reference system (for symbolism, imagery, character, time and place, et cetera).

from 2017.

enkiv2 avatar enkiv2 commented on June 22, 2024

from 2017.

dougvalenta avatar dougvalenta commented on June 22, 2024

It's a fairly representative example of what I'm outputting right now, but not at all of what my end goal is. (Not sure which you meant.) Here's the grammar I'm working with (syntax explained above):

title = (On |Ode to |The Mysteries of )(Nature|a Pond|Wilderness)
first_line = O, [gerund] [plant_part].
line = ([line_adverb]|[line_adjective])
line_adverb = [adverb], ([adjective] )[plant_part]( [gerund]).
line_adjective = [adjective] [plant_part]( [gerund]( [adverb])).
adjective = (ruffled|salty|rickety|green|fresh|withered|wilted|worried|golden)
plant_part = (reeds|leaves|twigs|boughs|needles|berries|cobs)
gerund = (blowing|twisting|tangling|bobbing|whistling|drooping|breaking)
adverb = (lustily|brightly|wildly|eerily|softly|in the (summer |winter |autumn |spring |)(wind|breeze|water|rain|mist|haze|moonlight|sunlight|shade))

Some of the poems generated by this grammar are a little boring, but this isn't the grammar (or even the full line generation method, just one of the technologies) I'll be using for my final product, so I'm ready to move on.

from 2017.

dougvalenta avatar dougvalenta commented on June 22, 2024

Okay, getting somewhere. Now on each appearance, each repeated line chooses a new "template," which determines phrase order and inclusion and punctuation, but the phrases themselves are retained from appearance to appearance.

Still not where I want to be, but a functioning technique:

"Fall"

Swaying softly in the tattered dusk, pale reeds rustle.
And crackling, red reeds snap in the glistening afternoon.
Then pale reeds rustle softly, swaying.
And crackling, red reeds snap softly.
Then in the tattered dusk, pale reeds rustle softly, swaying.

The pattern of lines is ABABA, but each time a line repeats it is rephrased.

from 2017.

dougvalenta avatar dougvalenta commented on June 22, 2024

Took the day off, but was getting some interesting output last night, now aping the symbolist mood of Chambers:

Death stares in the shade.
He says, "If it is untrue, then go alone."
Beneath the willow, Death laughs, forgotten.

from 2017.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.