<jupyter_start><jupyter_text>Encoded output<jupyter_code>inputs = ["<NAME>te, dass ich mich kurz vorstelle. ich heiße <NAME>.||fr",
          "<NAME>te, dass ich mich kurz vorstelle. ich heiße <NAME>.||de",
          "les socialistes et les républicains sont venus apporter leurs voix à la majorité pour ce texte.||fr",
          "les socialistes et les républicains sont venus apporter leurs voix à la majorité pour ce texte.||de"]
embeddings = encode(model, inputs[:-2])
tsne = [(t, c, TSNE(n_components=2).fit_transform(e)) for (t, c, e) in embeddings]
fig = plt.figure(figsize=(19, 25))
for i, (t, c, e) in enumerate(tsne):
    ax = plt.subplot(4, 3, i + 1)   
    for j in range(len(t)):
        plt.scatter(e[j, 0], e[j, 1], c='k', marker=r"$ {} $".format(t[j].replace(" ", "/")), alpha=0.7, s=50)
        #ax.set_title(f'pool_layer={i + 1}')
plt.tight_layout()
plt.subplots_adjust(bottom=0.1, right=0.95, top=0.9)
#cax = plt.axes([0.96, 0.6, 0.02, 0.3])
#cbar = plt.colorbar(cax=cax, ticks=range(len(texts)))

#cbar.ax.get_yaxis().set_ticks([])
#for j, lab in enumerate(texts.keys()):
#    cbar.ax.text(4.25, (2 * j + 1) / 2.25, lab, ha='center', va='center', fontsize=15)

plt.show()<jupyter_output><empty_output><jupyter_text>Language embedding<jupyter_code>def show_similarity(similarity, languages):
    fig = plt.figure(figsize=(6, 6))
    ax = fig.add_subplot(111)
    diagonal = similarity[1:,:-1].copy()
    lower_indices = np.tril_indices(diagonal.shape[0])
    lower = diagonal[lower_indices]
    lower_min = np.min(lower)
    lower_max = np.max(lower)
    diagonal = (diagonal - lower_min) / (lower_max - lower_min)
    cax = ax.matshow(np.tril(diagonal), interpolation='nearest')
    fig.colorbar(cax)
    ax.set_xticklabels([languages[0]]+languages[:-1], rotation='vertical')
    ax.set_yticklabels(languages)
    plt.show()
embeddings = model._encoder._embedding.weight.detach().numpy()
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
similarity = cosine_similarity(embeddings)
show_similarity(similarity, hp.languages)
layer_number = 2
layer_weights = model._encoder._layers[layer_number]._convolution._bottleneck.weight.detach().numpy()
bottleneck_embeddings = embeddings @ layer_weights.T
bottleneck_similarity = cosine_similarity(bottleneck_embeddings)
show_similarity(bottleneck_similarity, hp.languages)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15800502933780386, 'fraction_numerical': 0.022632020117351215, 'mean_word_length': 4.9675, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '651178', 'license': 'MIT', 'n_tokens_mistral': 951, 'n_tokens_neox': 895, 'n_words': 179, 'path': 'notebooks/encoder_analyze.ipynb', 'repo_name': 'williamxi1/Multilingual_Text_to_Speech', 'size': '2420'}