{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"raw","source":"NLP Model","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:37.819911Z","iopub.execute_input":"2023-08-13T17:10:37.820361Z","iopub.status.idle":"2023-08-13T17:10:37.825844Z","shell.execute_reply.started":"2023-08-13T17:10:37.820321Z","shell.execute_reply":"2023-08-13T17:10:37.824811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/articles.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:37.831360Z","iopub.execute_input":"2023-08-13T17:10:37.832657Z","iopub.status.idle":"2023-08-13T17:10:38.988696Z","shell.execute_reply.started":"2023-08-13T17:10:37.832629Z","shell.execute_reply":"2023-08-13T17:10:38.987361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"article.describe()","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:38.990829Z","iopub.execute_input":"2023-08-13T17:10:38.991264Z","iopub.status.idle":"2023-08-13T17:10:39.076219Z","shell.execute_reply.started":"2023-08-13T17:10:38.991219Z","shell.execute_reply":"2023-08-13T17:10:39.074935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/customers.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:39.078170Z","iopub.execute_input":"2023-08-13T17:10:39.078609Z","iopub.status.idle":"2023-08-13T17:10:44.704447Z","shell.execute_reply.started":"2023-08-13T17:10:39.078560Z","shell.execute_reply":"2023-08-13T17:10:44.703235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"customer.describe()","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:44.707518Z","iopub.execute_input":"2023-08-13T17:10:44.707933Z","iopub.status.idle":"2023-08-13T17:10:44.964611Z","shell.execute_reply.started":"2023-08-13T17:10:44.707902Z","shell.execute_reply":"2023-08-13T17:10:44.963235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:44.966184Z","iopub.execute_input":"2023-08-13T17:10:44.967458Z","iopub.status.idle":"2023-08-13T17:10:49.896882Z","shell.execute_reply.started":"2023-08-13T17:10:44.967414Z","shell.execute_reply":"2023-08-13T17:10:49.895705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:49.899591Z","iopub.execute_input":"2023-08-13T17:10:49.900002Z","iopub.status.idle":"2023-08-13T17:10:49.916222Z","shell.execute_reply.started":"2023-08-13T17:10:49.899963Z","shell.execute_reply":"2023-08-13T17:10:49.914762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_train = pd.read_csv('/kaggle/input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:10:49.918630Z","iopub.execute_input":"2023-08-13T17:10:49.919950Z","iopub.status.idle":"2023-08-13T17:12:10.256731Z","shell.execute_reply.started":"2023-08-13T17:10:49.919906Z","shell.execute_reply":"2023-08-13T17:12:10.255200Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"transaction_train","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:12:10.266573Z","iopub.execute_input":"2023-08-13T17:12:10.266977Z","iopub.status.idle":"2023-08-13T17:12:10.320689Z","shell.execute_reply.started":"2023-08-13T17:12:10.266936Z","shell.execute_reply":"2023-08-13T17:12:10.317657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import spacy","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:12:10.327628Z","iopub.execute_input":"2023-08-13T17:12:10.328483Z","iopub.status.idle":"2023-08-13T17:12:10.335899Z","shell.execute_reply.started":"2023-08-13T17:12:10.328365Z","shell.execute_reply":"2023-08-13T17:12:10.334619Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# nlp = spacy.load(\"en_core_web_sm\")","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:12:10.341299Z","iopub.execute_input":"2023-08-13T17:12:10.341829Z","iopub.status.idle":"2023-08-13T17:12:10.348196Z","shell.execute_reply.started":"2023-08-13T17:12:10.341682Z","shell.execute_reply":"2023-08-13T17:12:10.347022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# text = \"I need a red dress for a party this weekend.\"\n# doc = nlp(text)\n# entities = [(ent.text, ent.label_) for ent in doc.ents]\n# print(entities)","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:12:10.349938Z","iopub.execute_input":"2023-08-13T17:12:10.351241Z","iopub.status.idle":"2023-08-13T17:12:10.359170Z","shell.execute_reply.started":"2023-08-13T17:12:10.351201Z","shell.execute_reply":"2023-08-13T17:12:10.357858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\n\ncommand = (\n    \"python /kaggle/input/nlp-fashion/src/lstm_fashion.py\"\n    \" --data_folder '/kaggle/input/nlp-fashion/data/lstm_input'\"\n    \" --embedding 'no_char'\"\n    \" --output_folder '/kaggle/working/'\"\n)\n\nos.system(command)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:12:10.360938Z","iopub.execute_input":"2023-08-13T17:12:10.361325Z","iopub.status.idle":"2023-08-13T17:13:14.972080Z","shell.execute_reply.started":"2023-08-13T17:12:10.361286Z","shell.execute_reply":"2023-08-13T17:13:14.971092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from flair.models import SequenceTagger\n\n# Define the path to the trained NER model\nmodel_path = '/kaggle/working/final-model.pt'\n\n# Load the trained NER model\ntagger = SequenceTagger.load(model_path)\n\n# Define a sample text for NER\ntext = \"Nike is a popular sportswear brand headquartered in Oregon, USA.\"\n\n# Run NER on the sample text\nsentence = Sentence(text)\ntagger.predict(sentence)\n\n# Get the NER results\nner_results = sentence.to_dict(tag_type='ner')\n\n# Print the NER results\nprint(ner_results)\n","metadata":{"execution":{"iopub.status.busy":"2023-08-13T17:16:09.253002Z","iopub.execute_input":"2023-08-13T17:16:09.253438Z","iopub.status.idle":"2023-08-13T17:16:09.862090Z","shell.execute_reply.started":"2023-08-13T17:16:09.253403Z","shell.execute_reply":"2023-08-13T17:16:09.860609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}