Created
January 31, 2020 13:38
-
-
Save jobergum/72b247e09bf2da8294e694895426b8a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Feed unique products to Vespa" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 332, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"feed_status = []\n", | |
"for uid,df in all.groupby('product_uid'):\n", | |
" title = df['product_title'].iloc[0]\n", | |
" description = df['product_description'].iloc[0]\n", | |
" queries = []\n", | |
" df['search_term'].apply(lambda x: queries.append(x))\n", | |
" attributes = []\n", | |
" p = product_attributes[product_attributes.product_uid==uid]\n", | |
" p['value'].apply(lambda x: attributes.append(x))\n", | |
" brand = p[p.name == 'MFG Brand Name']\n", | |
" brand = None if brand.empty else brand['value'].iloc[0]\n", | |
" title_embedding,description_embedding = session.run(\n", | |
" sentence_embeddings, feed_dict={sentence: [title,description]})\n", | |
" success,vespa_json = feed_product_to_vespa(title, description, \n", | |
" brand, attributes, uid, queries, title_embedding, description_embedding) \n", | |
" feed_status.append((success,vespa_json))" | |
] | |
} | |
], | |
"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.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment