Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code for generating embeddings #141

Closed
1 task
jorgedch opened this issue Jul 30, 2022 · 1 comment · Fixed by #139
Closed
1 task

Example code for generating embeddings #141

jorgedch opened this issue Jul 30, 2022 · 1 comment · Fixed by #139

Comments

@jorgedch
Copy link

Software paper

openjournals/joss-reviews#4517

  • Functionality:
  1. A few imports and code changes were needed to run the example code in Generating embeddings offline for the experiment included in [examples/zappos](https://github.com/stsievert/salmon/tree/master/examples/zappos). Here is the updated code for the example:
# Imports:
import pandas as pd
from sklearn.model_selection import train_test_split
from salmon.triplets.offline import OfflineEmbedding

# Load and pre-process data:
df = pd.read_csv("responses.csv")  # from dashboard
X = df[["head", "winner", "loser"]].to_numpy()
X_train, X_test = train_test_split(X, random_state=42, test_size=0.2)

em = pd.read_csv("embeddings.csv")  # from dashboard
em = em[["0","1"]].to_numpy()  # select embedding data from 2D space

# Create and fit model:
n = int(X.max() + 1)  # number of targets
d = 2  # embed into 2 dimensions
max_epochs = 500_000

model = OfflineEmbedding(n=n, d=d, max_epochs=max_epochs)
model.initialize(X_train, embedding=em)
model.fit(X_train, X_test)

# Inspect model:
model.embedding_  # embedding
model.history_  # to view information on how well train/test performed
@stsievert
Copy link
Owner

Updated in 06f6bdd; closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants