In [73]:
import spacy
In [74]:
nlp = spacy.load('en_core_web_md')
In [75]:
def vec(s):
    return nlp.vocab[s].vector
In [76]:
import json
prob_lookup = dict(json.load(open("./wordfreq-en-25000-log.json")))
In [77]:
from simpleneighbors import SimpleNeighbors
In [78]:
def vec(s):
    return nlp.vocab[s].vector
In [111]:
lovesong_doc = nlp(open("lovesong.txt").read())
In [112]:
doc = nlp(open("hamlet.txt").read())
In [113]:
import random
chunk_lookup = SimpleNeighbors(300)
for chunk in doc.noun_chunks:
    chunk_text = chunk.text.replace("\n", " ")
    if chunk_text not in chunk_lookup.corpus:
        chunk_lookup.add_one(chunk_text, chunk.vector)
In [114]:
adj_lookup = SimpleNeighbors(300)
for word in doc:
    # .corpus of the lookup lets us determine if the word has already been added
    if word.tag_ == 'JJ' and word.text.lower() not in adj_lookup.corpus:
        adj_lookup.add_one(word.text.lower(), word.vector)
In [118]:
output = []
for word in lovesong_doc:
    if word.is_alpha and word.pos_ == 'NOUN':
        new_word = random.choice(chunk_lookup.nearest(word.vector, 2))
    elif word.is_alpha and word.tag_ == 'JJ':
        new_word = random.choice(adj_lookup.nearest(word.vector, 2))

The Love Song of the Prince of Denmark

Let us go then, you and I,
When the night is spread out against the a heaven-kissing hill
Like a a sleep etherized upon a one table;
Let us go, through certain half-deserted Hamlet,
The muttering his Majesty
Of tardy night in one-night easy his vouchers
And metal two dishes with golden fire--stones:
Hamlet that follow like a tedious reason
Of evil his statutes
To lead you to an lack some necessary question ...
Oh, do not ask, “What is it?”
Let us go and make our this chance.

In the mine own room the these men come and go
Talking of Michelangelo.

The black dust that rubs its his back upon the the doors-the doors,
The grey dust that rubs its Ears on the the door-the doors,
Licked its his mouth into the my edge of the night,
Lingered upon the mountains that stand in weeds,
Let fall upon its his back the earth that falls from seals,
Slipped by the bed, made a sudden absurd pomp,
And seeing that it was a smoothness October Good night,
Curled once about the but in's own house, and fell asleep.

And indeed there will be time
For the grey dust that slides along the ' right, old Jephthah,
Rubbing its his back upon the the door-the door;
There will be time, there will be time
To prepare a their faces to meet the his face that you meet;
There will be time to murder and create,
And this time for all the work and day of hands
That lift and drop a the question on your a glass;
time for you and this time for me,
And time yet for a hundred blench,
And for a hundred imagination and the mandate,
Before the some act of a maids' legs and two dishes.

In the mine own room the men come and go
Talking of Michelangelo.

And indeed there will be time
To wonder, “Do I dare?” and, “Do I dare?”
this time to turn back and descend the the stair,
With a pale the ulcerous place in the but in's own house of my some complexion —
(They will say: “How his your lips is growing soft!”)
My night some complexion, my toe mounting firmly to the his jaw,
My hangers sweet and generous, but asserted by a quick a pin's fee —
(They will say: “But how his this arm and our withers are soft!”)
Do I dare
Disturb the how infinite in faculties?
In a two hours there is this time
For actions and the mandate which a What hour will reverse.

For I have known them all already, known them all:
Have known the all occasions, day, all occasions,
I have measured out my my life with bread wassail;
I know the merriment dying with a dying the winter's flaw
Beneath the healthful music from a outward bed.
               So how should I presume?

And I have known the Eyes already, known them all—
The Eyes that fix you in a formulated the proverb,
And when I am formulated, sprawling on a a pin's fee,
When I am pinned and wriggling on the the stair,
Then how should I begin
To spit out all the a bunghole-our ends of my time and more things?
               And how should I presume?

And I have known the this arm already, known them all—
this arm that are braceleted and grey and thick
(But in the dust, downed with pale grey some complexion!)
Is it wax from a fashion
That makes me so digress?
this arm that lie along a the table, or wrap about a grey beards.
               And should I then presume?
               And how should I begin?

Shall I say, I have gone at heaven through long their graves
And watched the thick amber and plum-tree gum that rises from the vapours
Of dejected men in my beard-toe, leaning out of the door? ...

I should have been a one of bloody bones
Scuttling across the a glass of unseen deep ere.

And the Good night, the Good night, sleeps so peacefully!
Smoothed by short your fingers,
asleep ... weary ... or it a dew,
Stretched on the the doors, here beside you and me.
Should I, after drink and the candied tongue and snow,
Have the The spirit to force the moment to its calamity?
But though I have wept and fasted, wept and prayed,
Though I have seen my Head (grown slightly bare) brought in upon a parchment,
I am no O my prophetic soul — and here’s no great the matter;
I have seen the happy time of my absurd pomp awake,
And I have seen the divine Footman hold my some complexion, and snicker,
And in short, I was wrong.

And would it have been much it, after all,
After the parchment, the thick amber and plum-tree gum, the two dishes,
Among the complete steel, among some what of you and me,
Would it have been worth while,
To have bitten off the the matter with a tristful visage,
To have squeezed the how infinite in faculties into a the basket creep
To roll it towards some lack the question,
To say: “I am Lazarus, come from the epitaph,
Come back to tell you all, I shall tell you all”—
If one, settling a Queen by her his head
               Should say: “That is not what I meant at all;
               That is not it, at all.”

And would it have been much it, after all,
Would it have been much while,
After the midnight and the a man and the plentiful Hamlet,
After the many several sorts, after the shapes, after the grey beards that trail along the the doors—
And this, and so much more?—
It is possible to say just what I mean!
But as if a secret golden fire- threw the the lungs in these ventages on a the image:
Would it have been much while
If one, settling a Queen or throwing off a grey beards,
And turning toward the the door, should say:
               “That is not it at all,
               That is not what I meant, at all.”

No! I am not Prince Hamlet, nor was meant to be;
Am an a courtier lord, one that will do
To swell a our achievements, start a the comedy or two,
Advise the King; no doubt, an easy use,
earnest, glad to be of use,
liberal, heedful, and judicious;
complete of well prison, but a this too too solid flesh ignorant;
At such times, indeed, almost absurd—
Almost, at such times, the Fool.

I grow little ... I grow old ...
I shall wear the grey beards of my grey beards rolled.

Shall I part my your lips behind?   Do I dare to eat a blush?
I shall wear black sheepskins grey beards, and walk upon the the sun.
I have heard the beasts singing, each to each.

I do not think that they will sing to me.

I have seen them riding the winds on the the wind
Combing the black some complexion of the the wind blown back
When the the wind blows the the fish black and black.
We have lingered in the their graves of the Six Barbary horses
By mountains-old men wreathed with vapours red and grey
Till lack merriment wake us, and we drown.
In [ ]: