diff --git a/Basic-Scripts/Lyrics-Generator/all-of-me.txt b/Basic-Scripts/Lyrics-Generator/all-of-me.txt new file mode 100644 index 00000000..1e98afc6 --- /dev/null +++ b/Basic-Scripts/Lyrics-Generator/all-of-me.txt @@ -0,0 +1,52 @@ +What would I do without your smart mouth +Drawing me in, and you kicking me out +Got my head spinning, no kidding, I can't pin you down +What's going on in that beautiful mind +I'm on your magical mystery ride +And I'm so dizzy, don't know what hit me, but I'll be alright +My head's under water +But I'm breathing fine +You're crazy and I'm out of my mind +'Cause all of me +Loves all of you +Love your curves and all your edges +All your perfect imperfections +Give your all to me +I'll give my all to you +You're my end and my beginning +Even when I lose I'm winning +'Cause I give you all, all of me +And you give me all, all of you +How many times do I have to tell you +Even when you're crying you're beautiful too +The world is beating you down, I'm around through every move +You're my downfall, you're my muse +My worst distraction, my rhythm and blues +I can't stop singing, it's ringing, I my head for you +My head's under water +But I'm breathing fine +You're crazy and I'm out of my mind +'Cause all of me +Loves all of you +Love your curves and all your edges +All your perfect imperfections +Give your all to me +I'll give my all to you +You're my end and my beginning +Even when I lose I'm winning +'Cause I give you all of me +And you give me all, all of you +Cards on the table, we're both showing hearts +Risking it all, though it's hard +'Cause all of me +Loves all of you +Love your curves and all your edges +All your perfect imperfections +Give your all to me +I'll give my all to you +You're my end and my beginning +Even when I lose I'm winning +'Cause I give you all of me +And you give me all of you +I give you all, all of me +And you give me all, all of you \ No newline at end of file diff --git a/Basic-Scripts/Lyrics-Generator/lyrics_gen.py b/Basic-Scripts/Lyrics-Generator/lyrics_gen.py new file mode 100644 index 00000000..1410485e --- /dev/null +++ b/Basic-Scripts/Lyrics-Generator/lyrics_gen.py @@ -0,0 +1,66 @@ +import numpy as np +def generatetable(text,k=4): + T={} + for i in range(len(text)-k): + X=text[i:i+k] + Y=text[i+k] + #print(X,Y) + if T.get(X) is None: + T[X]={} + T[X][Y]=1 + else: + if T[X].get(Y) is None: + T[X][Y]=1 + else: + T[X][Y] +=1 + return T + +def convertFreqIntoProb(T): + for kx in T.keys(): + s = float(sum(T[kx].values())) + for k in T[kx].keys(): + T[kx][k] = T[kx][k]/s + + return T + + +def load_text(filename): + with open(filename,encoding='utf8') as f: + return f.read().lower() + + +def train(text,k=4): + T = generatetable(text,k) + T = convertFreqIntoProb(T) + + return T + + +def sample_next(ctx,T,k): + ctx = ctx[-k:] + if T.get(ctx) is None: + return " " + possible_Chars = list(T[ctx].keys()) + possible_values = list(T[ctx].values()) + + return np.random.choice(possible_Chars,p=possible_values) + + +def generateText(starting_sent,k=4,maxLen=1000): + + sentence = starting_sent + ctx = starting_sent[-k:] + + for ix in range(maxLen): + next_prediction = sample_next(ctx,model,k) + sentence += next_prediction + ctx = sentence[-k:] + return sentence + + +files="all-of-me.txt" +data= load_text(files) +model=train(data) +x = input("Enter the beginning word: ") +text = generateText(x,k=4,maxLen=2000) +print(text)