Tumgik
#nltk
Text
python iterative monte carlo search for text generation using nltk
You are playing a game and you want to win. But you don't know what move to make next, because you don't know what the other player will do. So, you decide to try different moves randomly and see what happens. You repeat this process again and again, each time learning from the result of the move you made. This is called iterative Monte Carlo search. It's like making random moves in a game and learning from the outcome each time until you find the best move to win.
Iterative Monte Carlo search is a technique used in AI to explore a large space of possible solutions to find the best ones. It can be applied to semantic synonym finding by randomly selecting synonyms, generating sentences, and analyzing their context to refine the selection.
# an iterative monte carlo search example using nltk # https://pythonprogrammingsnippets.tumblr.com import random from nltk.corpus import wordnet # Define a function to get the synonyms of a word using wordnet def get_synonyms(word): synonyms = [] for syn in wordnet.synsets(word): for l in syn.lemmas(): if '_' not in l.name(): synonyms.append(l.name()) return list(set(synonyms)) # Define a function to get a random variant of a word def get_random_variant(word): synonyms = get_synonyms(word) if len(synonyms) == 0: return word else: return random.choice(synonyms) # Define a function to get the score of a candidate sentence def get_score(candidate): return len(candidate) # Define a function to perform one iteration of the monte carlo search def monte_carlo_search(candidate): variants = [get_random_variant(word) for word in candidate.split()] max_candidate = ' '.join(variants) max_score = get_score(max_candidate) for i in range(100): variants = [get_random_variant(word) for word in candidate.split()] candidate = ' '.join(variants) score = get_score(candidate) if score > max_score: max_score = score max_candidate = candidate return max_candidate initial_candidate = "This is an example sentence." # Perform 10 iterations of the monte carlo search for i in range(10): initial_candidate = monte_carlo_search(initial_candidate) print(initial_candidate)
output:
This manufacture Associate_in_Nursing theoretical_account sentence. This fabricate Associate_in_Nursing theoretical_account sentence. This construct Associate_in_Nursing theoretical_account sentence. This cathode-ray_oscilloscope Associate_in_Nursing counteract sentence. This collapse Associate_in_Nursing computed_axial_tomography sentence. This waste_one's_time Associate_in_Nursing gossip sentence. This magnetic_inclination Associate_in_Nursing temptingness sentence. This magnetic_inclination Associate_in_Nursing conjure sentence. This magnetic_inclination Associate_in_Nursing controversy sentence. This inclination Associate_in_Nursing magnetic_inclination sentence.
2 notes · View notes
robotpoetry · 1 year
Text
POURING
"Pouring"
Pity In The Southern Clime Slow
Do Their Nest Merrily Morneault
Father Sold Me How They Buis
Where The Beetle Goes His Work Says
---
Eat Hoarse With Joy In Die
Moon Arise In The Lily White Di
And The Heat Till She Imo
Upon A Thorn And Wroe
4 notes · View notes
theharrymanback · 1 year
Text
El arte de escribir bien (y algunas estadísticas al respecto)
El arte de escribir bien (y algunas estadísticas al respecto)
Desde hace un tiempo, muy a menudo me sorprendo a mí mismo maravillado frente a un texto. Pero no porque la historia que cuenta sea impresionante o me esté dando información súper interesante. A medida que mi lista de lecturas ha ido creciendo, también lo ha hecho mi gozo al encontrar pasajes particularmente bien escritos. Además, durante los últimos años he invertido muchas horas intentando…
Tumblr media
View On WordPress
2 notes · View notes
mintlimeginger · 2 years
Photo
Tumblr media
Playing around with the corpus of all transcripts from all episodes of CR. After removing the most common English words, these are the top 4-word groupings. Mentally constructing my prototypical CR episode now.
6 notes · View notes
soumenatta · 1 year
Text
In this tutorial, we will explore how to perform sentiment analysis using Python with three popular libraries — NLTK, TextBlob, and VADER.
1 note · View note
differentfacetree · 2 years
Text
Tumblr media
0 notes
robotpoetry · 2 years
Text
SHEEP
"Sheep"
Think Not And Smell The Wurth
Benighted And The Rushes Kerth
Weeping In His Baits Sank
Thee Then The Wolvish Howl Schank
---
Ever See The Night Maskell
Wise Guardians Of Love Because Burble
Heard Her Head Er The Rebirth
To Peace Peace For Werth
8 notes · View notes
robotpoetry · 2 years
Text
LITTLE
"Little"
Lamb So Do Not Thou Prause
I Was Wet With Soft Baus
Sweet Is Not Alone Nor Rejoice
These Flowers While Thou Complainest Now Intervoice
---
Thee The Tiger Tiger Thuma
Moon Lovely Lyca Sleep Fama
Little Bird That In Her Haws
On Earth To Drive Their Son Naus
4 notes · View notes
robotpoetry · 1 year
Text
POEM
"POEM"
Pity The Lilly Of My Friend
The Mire Was Wet With The
Skies Earth S Descend
Lyca D In A Little A
---
Dacre And Mutual Fear
And They Know I Vanish Innocent
Hands Full Of The Voices Appear
Gifts Coined Gold Struggling Millisent
4 notes · View notes
robotpoetry · 1 year
Text
WE
"WE"
Are Called By And Sweet Round
Unseen They Why Should Thel Astonish
S Smile Was Never Shine Around
Soon Forgot Her Lap And Cherish
---
The Watery Shore Naked In My
Tears Where Can Valleys Wild
But My Palace Deep By
Arise And Weak The Beguiled
2 notes · View notes
robotpoetry · 1 year
Text
PORTER
"Porter"
Lifted The Sun Does Ache Mazda
Little Girl Lost Children Of Matola
Hovering And Glittering On Every Heart Vanhove
Still But My Wrath Shove
---
Cherish Thee Youth And Graft
My Children Under A Craft
Thou His Light Fled You Costanza
When Thy Bed He Crops Mckenna
2 notes · View notes
robotpoetry · 1 year
Text
POEM
"POEM"
D It Be Lost Its Hungry Gorge
Think Not Sit And Priests
In The Tent The Birds In Forge
Sigh Runs In Every Man Beasts
---
Through Nature To Hear His Heat Melts
Thee And The Wren With Jealousy
Does Freeze My Youth Rise From Belts
Eyes Shall Shine Like A Song Airy
2 notes · View notes
robotpoetry · 1 year
Text
AM
"Am"
A Tear And Says Lifland
Thus She Ceasd Of Neyland
Led By Blake Labov
Yet My Sorrow Breathed From The Gov
---
They Should Be At The Lafauci
Garments He Kissed Me Spreads His Brunelli
All Were Afar Fed With Chickened
Sees Cock Does Laugh Iceland
2 notes · View notes
robotpoetry · 2 years
Text
LL
"LL"
Shade And The Ground Near
My House And Gentle Sleep
If The Earth A River Appear
Why It With Cruelty Didst Mould Asleep
---
Eyes O Life Betray Besides
Their Duty If Thou Know What
A Shade Him For I Asides
Bed And I Lay Sleeping But
4 notes · View notes
robotpoetry · 1 year
Text
CAME
"CAME"
Merrily The Earth Infixes Deep
Surprise While He Can Bear
Saying She Ceasd Coined Asleep
White As Birds Are His Air
---
Secret Love With Our Father S
Despite Then We Arise Link
S Parents Wept In The Sunny Bless
But For Joy My Drink
2 notes · View notes
robotpoetry · 1 year
Text
BURNING
"BURNING"
Bright In The Summer Morn Blushed Rosy
Red The Days They Pour Sleep
Grave The Future Began Airy
Welcome In The Vales Of Asleep
---
Who Present Swift As We Rose
In Silence And Their Nest Where
The Livelong Day And Breath And Arose
Thee And Sport In The Air
2 notes · View notes