{"id":13690087,"url":"https://github.com/AlexYangLi/ABSA_Keras","last_synced_at":"2025-05-02T06:31:49.115Z","repository":{"id":54980496,"uuid":"165494957","full_name":"AlexYangLi/ABSA_Keras","owner":"AlexYangLi","description":"Keras Implementation of Aspect based Sentiment Analysis","archived":false,"fork":false,"pushed_at":"2020-03-15T11:18:24.000Z","size":880,"stargazers_count":151,"open_issues_count":4,"forks_count":45,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-12T15:43:19.402Z","etag":null,"topics":["absa","atae","attention","attention-mechanism","cabasc","elmo","ian","memnet","ram","sentiment-analysis","sentiment-classification","td-lstm"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexYangLi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-13T11:02:12.000Z","updated_at":"2024-05-11T14:31:26.000Z","dependencies_parsed_at":"2022-08-14T08:01:04.129Z","dependency_job_id":null,"html_url":"https://github.com/AlexYangLi/ABSA_Keras","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/AlexYangLi%2FABSA_Keras","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexYangLi%2FABSA_Keras/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexYangLi%2FABSA_Keras/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexYangLi%2FABSA_Keras/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexYangLi","download_url":"https://codeload.github.com/AlexYangLi/ABSA_Keras/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251998610,"owners_count":21678005,"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":["absa","atae","attention","attention-mechanism","cabasc","elmo","ian","memnet","ram","sentiment-analysis","sentiment-classification","td-lstm"],"created_at":"2024-08-02T16:00:43.377Z","updated_at":"2025-05-02T06:31:48.716Z","avatar_url":"https://github.com/AlexYangLi.png","language":"Python","funding_links":[],"categories":["Repositories/Resources","Python"],"sub_categories":["Normal Sentiment Analysis Dataset (Coarse-grained)"],"readme":"## Aspect-based Sentiment Analysis\r\n\r\nKeras implementation (tensorflow backend) of aspect based sentiment analysis\r\n\r\n### Models\r\n\r\n- [Cabasc, WWW 2018](https://dl.acm.org/citation.cfm?id=3186001)  \r\nLiu et al. \"Content Attention Model for Aspect Based Sentiment Analysis\"\r\n\r\n- [RAM, EMNLP 2017](https://www.aclweb.org/anthology/D17-1047)  \r\nChen et al. \"Recurrent Attention Network on Memory for Aspect Sentiment Analysis\"\r\n\r\n- [IAN, IJCAI 2017](https://arxiv.org/pdf/1709.00893.pdf)  \r\nMa ei al. \"Interactive Attention Networks for Aspect-Level Sentiment Classification\"\r\n\r\n- [MemNet, EMNLP 2016](https://arxiv.org/pdf/1605.08900.pdf)  \r\nTang et al. \"Aspect Level Sentiment Classification with Deep Memory Network\"\r\n\r\n- [ATAE-LSTM(AE-LSTM, AT-LSTM), EMNLP 2016](http://aclweb.org/anthology/D16-1058)  \r\nWang et al. \"Attention-based LSTM for Aspect-level Sentiment Classification\"\r\n\r\n- [TD-LSTM(TC-LSTM), COLING 2016](https://arxiv.org/pdf/1512.01100)  \r\nTang et al. \"Effective LSTMs for Target-Dependent Sentiment Classification\"\r\n\r\n### Pre-processing\r\n\r\n1. download glove embedding `glove.42B.300d.zip`, unzip and put it in `raw_data`  \r\n```\r\nwget https://nlp.stanford.edu/data/wordvecs/glove.42B.300d.zip\r\nunzip glove.42B.300d.zip\r\nmv glove.42B.300d.txt ./raw_data\r\n```\r\n\r\n2. pre-processing\r\n```\r\npython3 process_raw.py\r\npython3 preprocess.py\r\n```\r\n\r\n### Training\r\n```\r\npython3 train.py\r\n```\r\n\r\n### Environment\r\n- python==3.6.4\r\n- keras==2.2.4\r\n- nltk==3.2.5\r\n- tensorflow=1.6.0\r\n\r\n### Data Analysis\r\n\r\nsee [data_analysis.md](./data_analysis.md)\r\n\r\n### Performance\r\nNote: results in the `()` are the performances of models with word embeddings fixed but aspect embeddings fine tuned; results in the `[]`\r\nare the performances of models with both word embeddings  and aspect embeddings fixed\r\n\r\n- Accuracy\r\n\r\n| model   | laptop(paper) |  laptop                   | restaurant(paper) | restaurant               | twitter(paper) | twitter                  |\r\n|---------|---------------|---------------------------|-------------------|--------------------------|----------------|--------------------------|\r\n|td_lstm  |               |  0.69905(0.7194)          |                   |  0.7732(0.8008)          |    0.708       |  0.69219(0.7109)         |\r\n|tc_lstm  |               |  0.69122(0.6912)[0.7178]  |                   |  0.7642(0.7696)[0.79375] |    0.715       |  0.71387(0.7124)[0.72543]|\r\n|ae_lstm  |    0.689      |  0.69122(0.6974)[0.69749] |      0.766        |  0.7651(0.7625)[0.78125] |                |  0.68497(0.68641)[0.6820]|\r\n|at_lstm  |               |  0.69122(0.6880)[0.70689] |                   |  0.7678(0.7812)[0.78571] |                |  0.67196(0.7052)[0.70086]|\r\n|atae_lstm|    0.687      |  0.69749(0.6927)[0.70376] |      0.772        |  0.7732(0.7732)[0.78482] |                |  0.66907(0.6965)[0.6921] |\r\n|memnet   |    0.7237     |  0.52821(0.5266)[0.53448] |      0.8095       |  0.6580(0.65)[0.65803]   |                |  0.57369(0.5751)[0.5780] |\r\n|ram      |    0.7449     |  0.70376(0.7225)[0.72727] |      0.8023       |  0.7937(0.8071)[0.81607] |    0.6936      |  0.69653(0.71387)[0.6979]|\r\n|ian      |    0.721      |  0.6865(0.7100)           |      0.786        |  0.7732(0.7821)          |                |  0.68208(0.71965)        |\r\n|cabasc   |    0.7507     |  0.6974(0.6990)[0.67554]  |      0.8089       |  0.7919(0.8080)[0.80357] |    0.7153      |  0.69219(0.69508)[0.6690]|\r\n\r\n- Macro-F1\r\n\r\n| model   | laptop(paper) |  laptop                   | restaurant(paper) | restaurant               | twitter(paper) | twitter                  |\r\n|---------|---------------|---------------------------|-------------------|--------------------------|----------------|--------------------------|\r\n|td_lstm  |               |  0.64172(0.6636)          |                   |  0.6653(0.6986)          |    0.690       |  0.6746(0.6898)          |\r\n|tc_lstm  |               |  0.62847(0.6335)[0.6666]  |                   |  0.6651(0.6492)[0.70170] |    0.695       |  0.6983(0.6848)[0.7122]  |\r\n|ae_lstm  |               |  0.62486(0.6435)[0.6355]  |                   |  0.6419(0.6370)[0.68319] |                |  0.66644(0.6670)[0.65437]|\r\n|at_lstm  |               |  0.61267(0.6259)[0.65907] |                   |  0.6630(0.6689)[0.6676]  |                |  0.6553(0.68194)[0.6823] |\r\n|atae_lstm|               |  0.6246(0.63185)[0.6539]  |                   |  0.6505(0.6657)[0.68006] |                |  0.6651(0.67400)[0.67085]|\r\n|memnet   |               |  0.38574(0.4118)[0.2322]  |                   |  0.3547(0.4040)[0.3395]  |                |  0.48982(0.49209)[0.4989]|\r\n|ram      |   0.7135      |  0.6474(0.6747)[0.66476]  | 0.7080            |  0.6887(0.7035)[0.72720] |    0.6730      |  0.66536(0.69679)[0.6685]|\r\n|ian      |               |  0.62007(0.6604)          |                   |  0.6550(0.6768)          |                |  0.65071(0.69550)        |\r\n|cabasc   |               |  0.64601(0.6356)[0.5886]  |                   |  0.6815(0.7201)[0.69357] |                |  0.66790(0.67948)[0.6610]|\r\n\r\n- Combining with ELMo Embedding\r\n\r\nThere are 2 ways to use ELMo in this project. Before training model, change the configuration as belows:  \r\n1. In config.py, set `self.use_elmo` to **True** and `self.elmo_hub_url` to **None** or https://tfhub.dev/google/elmo/2. By running train.py the tensorflow hub will download the elmo module and cached in the local temporay directory. But the module will be deleted after a machine reboot.\r\n2. So, I recommend you load the elmo module locally. First, download the elmo using url: https://tfhub.dev/google/elmo/2?tf-hub-format=compressed. Then change its name to **tfhub_elmo_2** (whatever you want), untar the file, and put it in the `raw_data` directory. It will be like:  \r\n   ![elmo_dir](asset/elmo_dir.png)  \r\nAnd don't forget to set `self.use_elmo` in config.py to **True** and `self.elmo_hub_url` to **raw_data/tfhub_elmo_2** (the name you just renamed).  \r\n\r\nHere's the results of combining ELMo Embedding:  \r\n![glove_vs_elmo](asset/glove_vs_elmo.png)\r\n\r\n- Personal conclusion\r\n\r\n1. Surprisingly, I failed to achieved similar performance as stated in the parper of `Memnet`. Or maybe there are bugs in the code?\r\n2. `TD-LSTM` performs unexpectedly well.\r\n3. Models with fixed embeddings are generally better than those with fine-tuned embeddings, which is consistent with the paper of `RAM`.\r\n4. L2 regularization didn't help.\r\n5. I tried elmo embedding, but it didn't bring a performance gain.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexYangLi%2FABSA_Keras","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAlexYangLi%2FABSA_Keras","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlexYangLi%2FABSA_Keras/lists"}