{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install sentence-transformers==2.0.0" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "https://www.kaggle.com/datasets/dataranch/upwork-1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Load dataset with pandas" ] }, { "cell_type": "code", "execution_count": 135, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv('freelancers.csv')\n", "df = df[['shortName', 'title', 'description', 'location', 'hourlyRate', 'avgFeedbackScore', 'skills']]\n", "df = df.dropna(subset='skills')\n", "df = df.dropna(subset='title')\n", "df['location'] = df['location'].apply(lambda x : eval(x)['state'])\n", "df['skills'] = df['skills'].apply(lambda x : [x['skill']['name'] for x in eval(x)])\n", "df['hourlyRate'] = df['hourlyRate'].apply(lambda x : eval(x)['amount'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def keyword_extractor(total_keywords, str1):\n", " word_list = list()\n", " for keyword in total_keywords:\n", " for word in str1.split(' '):\n", " if word == keyword:\n", " word_list.append(word)\n", " return word_list\n", "total_keywords = df.explode('skills')['skills'].unique().tolist()\n", "\n", "skill_keywords = keyword_extractor(total_keywords, 'I want to hire a wordpress')\n", "df[df['skills'].apply(lambda x: all(val in x for val in skill_keywords))]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. Encode 100 samples into vectors (1 column with product text, 1 column with vectors)" ] }, { "cell_type": "code", "execution_count": 136, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "100%|██████████| 5815/5815 [12:10<00:00, 7.96it/s]\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
shortNametitledescriptionlocationhourlyRateavgFeedbackScoreskillstext_vector_
0Jason V.Expert WordPress DeveloperHello! Welcome to my profile!\\n\\nMy name is Ja...IL60.004.925208[wordpress, seo, wp-ecommerce, woocommerce, bo...[0.078628771007061, 0.024731114506721497, -0.0...
1Miranda S.Social Media ManagerI am a Social Media Manager who specializes in...NY20.004.675676[social-media-content-creation, video-editing,...[0.07423530519008636, -0.022386642172932625, -...
2Gagan S J.Solution ArchitectMore than 25 years in IT with 20 years in US h...NJ65.000.000000[oracle-java-ee, spring-framework, hibernate, ...[0.04637446999549866, 0.03554175794124603, -0....
3Roxana L.Procurement, Logistics and Supply Chain profes...I work FAST - I am COST EFFICIENT - I deliver ...NC70.004.916684[procurement-function, pharmaceutical-industry...[0.026502298191189766, -0.02052873745560646, -...
4John M.3d generalist, post production artist and Vide...I am a 3D artist, animator, and designer with ...OK50.005.000000[animation, motion-graphics, video-editing, vi...[0.05356863886117935, 0.032190944999456406, -0...
...........................
5818Megan D.Web Research/Content Curation/Data Entry/Socia...Extremely driven, yet easy-going gal who refus...CA22.374.574029[data-entry, internet-research, virtual-assist...[0.07812528312206268, -0.018792806193232536, -...
5819Austin V.Product ManagerExperienced in building and growing digital pl...AZ100.000.000000[atlassian-jira, atlassian-confluence, project...[0.056266412138938904, -0.007661229465156794, ...
5820Eric M.Web Developer/Designer And Graphic Designer4 YEARS experience in Wordpress / Shopify / D...OH25.004.451507[html, css, wordpress, shopify, joomla, drupal...[0.048749279230833054, -0.013894445262849331, ...
5821Kristina A.Voice Over Talent, video editing, video produc...A musician from birth. I studied music educati...VA60.005.000000[articulate][0.03207482025027275, -0.027680398896336555, -...
5822Ashley C.Print and Digital Layout DesignerHello, I'm Ashley, a professional designer and...OR25.004.951186[print-layout-design, brochure-design, flyer-d...[0.04141489043831825, -0.04500063508749008, -0...
\n", "

5815 rows × 8 columns

\n", "
" ], "text/plain": [ " shortName title \\\n", "0 Jason V. Expert WordPress Developer \n", "1 Miranda S. Social Media Manager \n", "2 Gagan S J. Solution Architect \n", "3 Roxana L. Procurement, Logistics and Supply Chain profes... \n", "4 John M. 3d generalist, post production artist and Vide... \n", "... ... ... \n", "5818 Megan D. Web Research/Content Curation/Data Entry/Socia... \n", "5819 Austin V. Product Manager \n", "5820 Eric M. Web Developer/Designer And Graphic Designer \n", "5821 Kristina A. Voice Over Talent, video editing, video produc... \n", "5822 Ashley C. Print and Digital Layout Designer \n", "\n", " description location hourlyRate \\\n", "0 Hello! Welcome to my profile!\\n\\nMy name is Ja... IL 60.00 \n", "1 I am a Social Media Manager who specializes in... NY 20.00 \n", "2 More than 25 years in IT with 20 years in US h... NJ 65.00 \n", "3 I work FAST - I am COST EFFICIENT - I deliver ... NC 70.00 \n", "4 I am a 3D artist, animator, and designer with ... OK 50.00 \n", "... ... ... ... \n", "5818 Extremely driven, yet easy-going gal who refus... CA 22.37 \n", "5819 Experienced in building and growing digital pl... AZ 100.00 \n", "5820 4 YEARS experience in Wordpress / Shopify / D... OH 25.00 \n", "5821 A musician from birth. I studied music educati... VA 60.00 \n", "5822 Hello, I'm Ashley, a professional designer and... OR 25.00 \n", "\n", " avgFeedbackScore skills \\\n", "0 4.925208 [wordpress, seo, wp-ecommerce, woocommerce, bo... \n", "1 4.675676 [social-media-content-creation, video-editing,... \n", "2 0.000000 [oracle-java-ee, spring-framework, hibernate, ... \n", "3 4.916684 [procurement-function, pharmaceutical-industry... \n", "4 5.000000 [animation, motion-graphics, video-editing, vi... \n", "... ... ... \n", "5818 4.574029 [data-entry, internet-research, virtual-assist... \n", "5819 0.000000 [atlassian-jira, atlassian-confluence, project... \n", "5820 4.451507 [html, css, wordpress, shopify, joomla, drupal... \n", "5821 5.000000 [articulate] \n", "5822 4.951186 [print-layout-design, brochure-design, flyer-d... \n", "\n", " text_vector_ \n", "0 [0.078628771007061, 0.024731114506721497, -0.0... \n", "1 [0.07423530519008636, -0.022386642172932625, -... \n", "2 [0.04637446999549866, 0.03554175794124603, -0.... \n", "3 [0.026502298191189766, -0.02052873745560646, -... \n", "4 [0.05356863886117935, 0.032190944999456406, -0... \n", "... ... \n", "5818 [0.07812528312206268, -0.018792806193232536, -... \n", "5819 [0.056266412138938904, -0.007661229465156794, ... \n", "5820 [0.048749279230833054, -0.013894445262849331, ... \n", "5821 [0.03207482025027275, -0.027680398896336555, -... \n", "5822 [0.04141489043831825, -0.04500063508749008, -0... \n", "\n", "[5815 rows x 8 columns]" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import pandas as pd\n", "from tqdm import tqdm\n", "from sentence_transformers import SentenceTransformer\n", "tqdm.pandas()\n", "\n", "model = SentenceTransformer('all-mpnet-base-v2') #all-MiniLM-L6-v2 #all-mpnet-base-v2\n", "\n", "#encode df version: for small dataset only\n", "df['text_vector_'] = df['title'].progress_apply(lambda x : model.encode(x).tolist())\n", "df" ] }, { "cell_type": "code", "execution_count": 133, "metadata": {}, "outputs": [], "source": [ "import random\n", "\n", "df = df.drop_duplicates(subset=['shortName', 'location', 'title', 'hourlyRate', 'avgFeedbackScore', 'description'])\n", "df = df.reset_index(drop=True)\n", "df['location'] = df['location'].apply(lambda x : random.choice(['New York', 'Chicago', 'Washington']))\n", "df.to_parquet('df_encoded.parquet', index=None)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.0 64-bit", "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.9.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "fdf377d643bc1cb065454f0ad2ceac75d834452ecf289e7ba92c6b3f59a7cee1" } } }, "nbformat": 4, "nbformat_minor": 2 }