# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [Root]
#     language: python
#     name: Python [Root]
# ---

import myutils as my
import pandas as pd
import seaborn as sns
import numpy as np
from sklearn.manifold import TSNE
# %matplotlib inline
# %load_ext rpy2.ipython

df = pd.read_table("./data/glove.6B.100d.txt", delimiter=" ", header=None, index_col=0, quoting=3)

df = pd.DataFrame(pd.read_csv("./data/minimal.50d.4f.csv")).set_index("0")

lens = (df**2).sum(axis=1).sort_values()
dfn = df.div(np.sqrt(lens), axis='index')

my.similar(dfn, dfn.loc["war"], 10)

my.least_similar(dfn, dfn.loc["sunday"]-dfn.loc["saturday"])

my.similar(dfn, dfn.loc["jealous"]-dfn.loc["envious"])

my.similar(dfn, -dfn.loc["famous"]+dfn.loc["popular"])

from numpy.linalg import norm


def dot_norm(a, b):
    return a.dot(b)/(norm(a)*norm(b))


dot_norm(df.loc["he"] - df.loc["she"], df.loc["man"] - df.loc["woman"])


def superfunkcja (a, b, c, d) :
    return dot_norm(df.loc[a] - df.loc[b], df.loc[c] - df.loc[d])


superfunkcja("he", "she", "chair", "table")

superfunkcja("he", "she", "good", "bad")

superfunkcja("envious", "jealous", "good", "bad")

superfunkcja("terrorist", "fighter", "good", "bad")

superfunkcja("terrorist", "soldier", "good", "bad")

superfunkcja("giant", "dwarf", "big", "small")

superfunkcja("up", "down", "good", "bad")

superfunkcja("warm", "cold", "close", "far")

df.loc["chair"].dot(df.loc["love"])/(norm(df.loc["chair"])*norm(df.loc["love"]))

df.loc["leaf"].dot(df.loc["belief"])/(norm(df.loc["leaf"])*norm(df.loc["belief"]))

df.loc["habit"].dot(df.loc["ventilation"])/(norm(df.loc["habit"])*norm(df.loc["ventilation"]))

df.loc["air"].dot(df.loc["triangle"])/(norm(df.loc["air"])*norm(df.loc["triangle"]))

df.loc["chair"].dot(df.loc["table"])/(norm(df.loc["chair"])*norm(df.loc["table"]))


def simil(a, b):
    return df.loc[a].dot(df.loc[b])/(norm(df.loc[a])*norm(df.loc[b]))


simil("pen", "pencil")

simil("car", "bus")

simil("violin", "piano")

simil("hot", "attractive")

simil("theory", "building")

simil("close", "warm")

simil("past", "back")

simil("war", "argument")

simil("discussion", "battle")

simil("discussion", "cooperation")

simil("argument", "cooperation")



StarcoderdataJupyterScriptsDedupFiltered