{"id":19817220,"url":"https://github.com/rmodi6/relation-extraction","last_synced_at":"2025-05-01T11:30:35.385Z","repository":{"id":39722384,"uuid":"222144186","full_name":"rmodi6/relation-extraction","owner":"rmodi6","description":"RNN and CNN based Relation Extraction models in tensorflow 2.0","archived":false,"fork":false,"pushed_at":"2024-08-27T17:03:38.000Z","size":20133,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-27T18:49:20.544Z","etag":null,"topics":["cnn","functional-api","gru","information-extraction","keras","natural-language-processing","relation-extraction","rnn","tensorflow2"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rmodi6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-16T18:46:06.000Z","updated_at":"2024-08-27T17:03:40.000Z","dependencies_parsed_at":"2024-08-27T18:45:07.635Z","dependency_job_id":null,"html_url":"https://github.com/rmodi6/relation-extraction","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmodi6%2Frelation-extraction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmodi6%2Frelation-extraction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmodi6%2Frelation-extraction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rmodi6%2Frelation-extraction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rmodi6","download_url":"https://codeload.github.com/rmodi6/relation-extraction/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224253407,"owners_count":17280934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnn","functional-api","gru","information-extraction","keras","natural-language-processing","relation-extraction","rnn","tensorflow2"],"created_at":"2024-11-12T10:12:03.389Z","updated_at":"2024-11-12T10:12:03.947Z","avatar_url":"https://github.com/rmodi6.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This file is best viewed in Markdown reader (eg. https://jbt.github.io/markdown-editor/)\n\n# Overview\n\nYou will implement a bi-directional GRU as well as an original model for Relation Extraction:\n\nThe GRU is loosely based on the approach done in the work of Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification (Zhou et. al, 2016).\n\nYou will need to implement:\n\n1. Bidirectional GRU\n2. Attention layer\n3. L2 Regularization\n\n\nAdditionally, you will design your own network architecture to solve this task. You can think of it yourself or base it on a known solution from a paper.\nMore details are given in the assignment pdf.\n\n\n# Installation\n\nThe environment is same as past ones minus extra requirements in `requirements.txt`. But we would *strongly* encourage you to make a new environment for assignment 4.\n\nThis assignment is implemented in python 3.6 and tensorflow 2.0. Follow these steps to setup your environment:\n\n1. [Download and install Conda](http://https://conda.io/projects/conda/en/latest/user-guide/install/index.html \"Download and install Conda\")\n2. Create a Conda environment with Python 3.6\n\n```\nconda create -n nlp-hw4 python=3.6\n```\n\n3. Activate the Conda environment. You will need to activate the Conda environment in each terminal in which you want to use this code.\n```\nconda activate nlp-hw4\n```\n4. Install the requirements:\n```\npip install -r requirements.txt\n```\n\n5. Download spacy model\n```\npython -m spacy download en_core_web_sm\n```\n\n6. Download glove wordvectors:\n```\n./download_glove.sh\n```\n\n**NOTE:** We will be using this environment to check your code, so please don't work in your default or any other python environment.\n\n\n# Data\n\nYou are given training and validation data in the form of text files. Training can be found in `data/train.txt` and validation is in `data/val.txt`. We are using data from a previous SemEval shared task which in total had 8,000 training examples. Your train/validation examples are a 90/10 split from this original 8,000. More details of the data can be found in the overview paper SemEval-2010 task 8: multi-way classification of semantic relations between pairs of nominals (Hendrickx et. al, 2009) as well as extra PDFs explaining the details of each relation in the dataset directory.\n\n\n# Code Overview\n\n\nThis repository largely follows the same interface as assignment 2 and assignment 3. Currently, the only thing missing is tensorboard support.\n\n## Train and Predict\n\nYou have 4 main scripts in the repository `train_basic.py`, `train_advanced.py`, `predict.py` and `evaluate.pl`.\n\n- Train scripts do as described and saves your model to be used later for prediction. Basic training script trains the basic `MyBasicAttentiveBiGRU` model which you are supposed implement (Bi-RNN+attention). You should not need to change this script. Advanced training script on other hand, is a template/starter code which you can adapt based on your `MyAdvancedModel` architecture design.\n\n- Predict generates predictions on the test set `test.txt` and saves your output to a file. You will submit your predictions to be scored against the hidden (labels) test set. Both files are set with reasonable defaults in their arguments but example commands are shown below.\n\n- Evaluation script is the pearl script unlike others. You can use it see detailed report of your predictions file against the gold labels.\n\n\n#### Train a model\n```\npython train.py --embed-file embeddings/glove.6B.100D.txt --embed-dim 100 --batch-size 10 --num_epochs 5\n\n# stores the model by default at : serialization_dirs/basic/\n```\n\n#### Predict with model\n```\npython predict.py --prediction-file my_predictions.txt --batch-size 10\n```\n\n**NOTE:** These scripts will not work until you fill-up the placeholders (TODOs) left out as part of the assignment.\n\n\n## Extra Scripts\n\nAs usual you are given `download_glove.sh`, however this is a slightly edited version that does not remove the larger dimension embeddings. For this assignment I personally used the 100D embeddings. I encourage everyone to do the same for their GRU to confirm your results are around the expected range.\n\n\n# General results\n\nTo help everyone confirm if their model is on the right track I will say that my bi-GRU w/ attention model scored high .5x macro-avg F1 on the validation set after 10 epochs and the default configuration.\n\n\n# Expectations\n\n## What to write in code:\n\nLike assignments 2 \u0026 3 you have `TODO(Students) Start` and `TODO(Students) End` annotations. You are expected to write your code between those comment/annotations.\n\n1. Implement a bi-directional GRU with attention (`MyBasicAttentiveBiGRU`) in `model.py`.\n2. Include L2 regularization on training on all trainable varaibles.\n3. Implement a new model (`MyAdvancedModel`) that out-performs the GRU in `model.py`. Adapt the `train_advanced.py` as required.\n\nAmong these, `MyBasicAttentiveBiGRU` and L2 regularization are well-defined tasks whereas `MyAdvancedModel` is an open-ended part of the assignment where you can design your own model as you deem fit.\n\n\n## What experiments to try with models\n\nThis assignment is much more open ended than the others. What we're looking for is that you've learned enough from the course to tackle a problem on your own. However, we do suggest a couple of experiments with the GRU:\n\n1. Run with only Word Embeddings (remove `pos_inputs` and dependency structure. Removing dep structure can be done by setting `shortest_path = []` in `data.py`)\n2. Run with only Word + Pos embeddings\n3. Run with only Word + Dep structure\n\n\n\n## What to turn in?\n\nA single zip file containing the following files:\n\n1. model.py\n2. train_advanced.py\n3. train_lib.py\n4. basic_test_prediction.txt\n5. advanced_test_prediction_1.txt\n6. advanced_test_prediction_2txt\n7. advanced_test_prediction_3.txt\n\n`gdrive_link.txt` should have a link to the `serialization_dirs.zip` of your trained models.\n\nWe will release the exact zip format on piazza in a couple of days but it should largely be the same as assignment 3.\n\n### Good Luck!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmodi6%2Frelation-extraction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmodi6%2Frelation-extraction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmodi6%2Frelation-extraction/lists"}