https://github.com/stitchfix/context2vec
Using Word2Vec on lists and sets
https://github.com/stitchfix/context2vec
Last synced: about 1 year ago
JSON representation
Using Word2Vec on lists and sets
- Host: GitHub
- URL: https://github.com/stitchfix/context2vec
- Owner: stitchfix
- License: mit
- Created: 2015-05-16T00:51:23.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-10-28T22:34:36.000Z (over 10 years ago)
- Last Synced: 2025-03-30T13:03:46.605Z (over 1 year ago)
- Language: Python
- Size: 137 KB
- Stars: 34
- Watchers: 165
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## Using Context2Vec
Use Word2Vec on lists and sets
Use like:
from sphere.models.context2vec import ContextCorpus
from gensim.models import Word2Vec
# If user 1 bought items 0, 1, 2, 3 and user 2
# bought 3, 4, 5 and user bought item 10
contexts = {1:{0, 1, 2, 3}, 2:{2, 3, 4, 5}, 3:{10}}
cc = ContextCorpus(contexts)
# Run the w2v model
model = Word2Vec(cc, size=30, iter=100, min_count=1, alpha=0.025, sg=0)
# Find the most similar user to user 1
results = model.most_similar('C1', topn=100)
related_users = filter(lambda x: x[0].startswith('C'), results)
# Find all user vectors
users = filter(lambda x: x.startswith('C'), model.index2word)
user_vectors = [model.syn0[w2v.vocab[w].index] for w in users]
## Running tests
Simply run
nosetests
Or to debug:
nosetests --pdb