Created
July 31, 2020 05:13
-
-
Save wezleysherman/e1bc8eda2f4b68128a134c484d3fee7d 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 compare_bars(input_bar, artists_bars): | |
''' | |
input_bars are the fire bars our AI generates | |
artists_bars are the original bars for the artist | |
The lower the score the better! We want unique bars | |
''' | |
# Converts sentences to matrix of token counts | |
avg_dist = 0 | |
total_counted = 0 | |
for bar in artists_bars: | |
v = CountVectorizer() | |
# Vectorize the sentences | |
word_vector = v.fit_transform([input_bar, bar]) | |
# Compute the cosine distance between the sentence vectors | |
cos_dist = 1-pdist(word_vector.toarray(), 'cosine')[0] | |
if not math.isnan(cos_dist): | |
avg_dist += 1-pdist(word_vector.toarray(), 'cosine')[0] | |
total_counted += 1 | |
return avg_dist/total_counted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment