text_plain_output_1.png
from sklearn.decomposition import PCA

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.manifold import TSNE

import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('ggplot')

root_path = '/kaggle/input/medieval-chant-corpus'
df_path = f'{root_path}/mh-corpus.json'
df = pd.read_json(df_path)
df.drop(['rawTextMusic', 'rawText'], axis=1, inplace=True)

from sklearn.feature_extraction.text import TfidfVectorizer
maxx_features = 2 ** 12
vectorizer = TfidfVectorizer(max_features=maxx_features)
X = vectorizer.fit_transform(df['music_as_words'].values)

from sklearn.decomposition import PCA
pca = PCA(n_components=0.95, random_state=42)
X_reduced = pca.fit_transform(X.toarray())
X_reduced.shape

from sklearn.manifold import TSNE
tsne = TSNE(verbose=1, perplexity=50)
X_embedded = tsne.fit_transform(X.toarray())

from matplotlib import pyplot as plt
import seaborn as sns
sns.set(rc={'figure.figsize': (15, 15)})
palette = sns.color_palette('bright', 1)
sns.scatterplot(X_embedded[:, 0], X_embedded[:, 1], palette=palette)
plt.title('t-SNE with no Labels')
plt.savefig('t-sne_chants.png')
plt.show()