<jupyter_start><jupyter_text>Analogical Evals.<jupyter_code>wv.most_similar(positive=['i', 'x'], negative=['j'])[0]
wv.most_similar(positive=['j', 'x'], negative=['i'])[0]
wv.most_similar(positive=['ask', 'sell'], negative=['bid'])[0]<jupyter_output><empty_output><jupyter_text>Unsurprisingly, this works less well on general English analogies.<jupyter_code>wv.most_similar(positive=["acquire", "lock"], negative=["release"])
wv.most_similar(positive=['map', 'append'], negative=['text'], topn=3)
wv.most_similar(positive=['bar'])<jupyter_output><empty_output><jupyter_text>Negative Example(s)❗<jupyter_code>wv.most_similar(positive=["open", "lock"], negative=["close"])[:5]<jupyter_output><empty_output><jupyter_text>Huh. That had `unlock` in fourth place, but didn't contain `release`. What's near `release`?<jupyter_code>wv.most_similar(['release'])<jupyter_output><empty_output><jupyter_text>Lock is near-_ish_.  PCA<jupyter_code>from sklearn import decomposition
pca = decomposition.PCA(n_components=2)
PCA_X = pca.fit_transform(model.wv.vectors)
p = figure(title = "PCA of Embeddings", tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave")
pca_source = embedded_bokeh_src(PCA_X[:, 0], PCA_X[:, 1])
p.circle(x='x', y='y', color='color', source=pca_source, alpha='alpha', size='size')
pca_hover = p.select({'type': HoverTool})
pca_hover.tooltips = {"content": "@subtoken"}
show(p)<jupyter_output><empty_output><jupyter_text>PCA Over Analogy Sandbox<jupyter_code>def group_pca(words):
    word_idxs = [model.wv.vocab[w].index for w in words]
    vec_cpy = model.wv.vectors.copy()
    fit_x = np.vstack([vec_cpy[i] for i in word_idxs])
    pca = decomposition.PCA(n_components=2)
    pca.fit(fit_x)
    transformed = pca.transform(vec_cpy)
    return pca, transformed

def group_figure(words):
    gpca = group_pca(words)
    p = figure(title = ','.join(words), tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave")
    pca_source = embedded_bokeh_src(gpca[:, 0], gpca[:, 1])
    p.circle(x='x', y='y', color='color', source=pca_source, alpha='alpha', size='size')
    p.select({'type': HoverTool}).tooltips = {"content": "@subtoken"}
    show(p)

def analogy_figure(pos, neg, tgt):
    all_words = pos + neg + [tgt]
    pca_model, gpca = group_pca(pos + neg)
    
    title = ' : '.join(pos) + " :: " + ' : '.join(neg)
    p = figure(title=title, tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave")
    pca_source = embedded_bokeh_src(gpca[:, 0], gpca[:, 1])
    p.circle(x='x', y='y', color='color', source=pca_source, alpha='alpha', size='size')
    p.select({'type': HoverTool}).tooltips = {"content": "@subtoken"}

    # print(model.wv.most_similar(positive=pos, negative=neg))
    manual_vec = (model.wv.word_vec(pos[0], use_norm=True) \
        + model.wv.word_vec(pos[1], use_norm=True) \
        - model.wv.word_vec(neg[0], use_norm=True)).reshape(1, -1)
    # print([(w, s) for w, s in model.wv.most_similar([(manual_vec, 1.0)]) if w not in pos + neg])
    
    pca_manual_vec = pca_model.transform(manual_vec)
    p.circle(x=pca_manual_vec[:, 0], y=pca_manual_vec[:, 1], color='black')
    
    show(p)


#group_figure(colorgroups['purple'])
analogy_figure(['i', 'x'], ['j'], 'y')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1901669758812616, 'fraction_numerical': 0.006802721088435374, 'mean_word_length': 6.385844748858448, 'pattern_counts': {'":': 3, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '213662', 'license': 'MIT', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1262, 'n_words': 195, 'path': 'notebooks/IDEmbeddingAnalysis.ipynb', 'repo_name': 'samkaufman/code-names', 'size': '3234'}