Created
July 31, 2020 05:10
-
-
Save wezleysherman/c22a7d98a27cc73566acbac8522bb166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_rap(model, artists_bars, length_of_bar=10, length_of_rap=20, min_score_threshold=-0.2, max_score_threshold=0.2, tries=5): | |
artists_avg_readability = calc_readability(artists_bars) | |
artists_avg_rhyme_idx = calc_rhyme_density(artists_bars) | |
fire_rap = [] | |
cur_tries = 0 | |
candidate_bars = [] | |
while len(fire_rap) < length_of_rap: | |
seed_phrase = markov_model.make_sentence(tries=500).split(" ") | |
seed_phrase = " ".join(seed_phrase[:3]) | |
cur_tries += 1 | |
bar = generate_bar(seed_phrase, model, rand.randrange(4, length_of_bar)) | |
bar_score = score_bar(bar, artist_lyrics, artists_avg_readability, artists_avg_rhyme_idx) | |
candidate_bars.append((bar_score, bar)) | |
if bar_score <= max_score_threshold and bar_score >= min_score_threshold: | |
fire_rap.append(bar) | |
cur_tries = 0 | |
print("Generated Bar: ", len(fire_rap)) | |
if cur_tries >= tries: | |
lowest_score = np.Infinity | |
best_bar = "" | |
for bar in candidate_bars: | |
if bar[0] < lowest_score: | |
best_bar = bar[1] | |
candidate_bars = [] | |
print("Generated Bar: ", len(fire_rap)) | |
fire_rap.append(best_bar) | |
cur_tries = 0 | |
print("Generated rap with avg rhyme density: ", calc_rhyme_density(fire_rap), "and avg readability of: ", calc_readability(fire_rap)) | |
return fire_rap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment