{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import json \n", "from pprint import pprint\n", "from gensim.test.utils import common_texts, get_tmpfile\n", "from gensim.models import Word2Vec\n", "\n", "from json_buffered_reader import JSON_buffered_reader as JSON_br\n", "\n", "import settings" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* reading in all ingredients with json stream:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "buffered_reader = JSON_br(settings.yummly_train)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ingredient_sets = []" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "for recipe in buffered_reader:\n", " ingredient_sets.append(recipe['ingredients'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* training a word2vec approach on the ingredient set" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "model = Word2Vec(ingredient_sets, size=100, window=5, min_count=1, workers=4)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.46477914" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "model.wv.similarity('eggs', 'pepper')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }