# AREnets
![](https://img.shields.io/badge/Python-3.6.9-brightgreen.svg)
![](https://img.shields.io/badge/Tensorflow-1.14-orange.svg)
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nicolay-r/AREnets/blob/master/arenets_colab_tutorial.ipynb)
<p align="center">
<img src="logo.png"/>
</p>
**AREnets** -- is an [OpenNRE](https://github.com/thunlp/OpenNRE) like project, but the kernel based on [tensorflow](https://www.tensorflow.org/)
library, with implementation of neural networks on top of it, designed for **A**ttitude and **R**elation **E**xtraction tasks.
AREnets is a result of advances in [Sentiment Attitude Extraction task](http://nlpprogress.com/russian/sentiment-analysis.html)
but introduced in generalized form and applicable for other relation-extraction related classification tasks.
It provides ready to use [neural networks](#models-list) and API for `subject`→`object` pairs classification in a given samples.
This project is powered by
[AREkit](https://github.com/nicolay-r/AREkit)
core API, squeezed into a tiny
[kernel](https://github.com/nicolay-r/AREnets/tree/dev/arenets/arekit).
## Contents
* [Installation](#installation)
* [Quick Start](#quick-start)
* [Models List](#models-list)
* [FAQ](#faq)
* [Test Details](#test-details)
* [How to cite](#how-to-cite)
## Installation
```bash
pip install git+https://github.com/nicolay-r/AREnets@master
```
## Quick Start
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nicolay-r/AREnets/blob/master/arenets_colab_tutorial.ipynb)
Simply just open and follow the [google-colab](https://colab.research.google.com/github/nicolay-r/AREnets/blob/master/arenets_colab_tutorial.ipynb)
version like IDE to modify the train and inference code of provided tutorial:
<p align="center">
<img src="docs/colab-as-ide-logo.png"/>
</p>
The complete examples are in [tutorials](tutorials) folder.
First of all, prepare your `_data` folder with data required for training model and performing inference.
* **Input samples**: check out [input data formatting guide](docs/input_data.md).
* **Embeddings** could be obtained from [NLPL repository](http://vectors.nlpl.eu/repository/),
with `model.txt` file placed at `_data` folder;
* See [downloading script](tutorials/_data/download_embedding.sh);
More on input features could be [found here](docs/input_features.md).
### Train
```python
from arenets.quickstart.train import train
from arenets.enum_name_types import ModelNames
train(input_data_dir="_data", labels_count=3, model_name=ModelNames.CNN, epochs_count=10)
```
Runs `cnn` model with `10` epochs for `3-class` classification problem;
all the model-related details will be stored at `_data` model by default.
### Predict
```python
from arenets.quickstart.predict import predict
from arenets.arekit.common.data_type import DataType
from arenets.enum_name_types import ModelNames
predict(input_data_dir="_data", output_dir="_out", labels_count=3, model_name=ModelNames.CNN, data_type=DataType.Test)
```
Predict `test` results for pre-trained `cnn` model and saves them into `_out` folder
## Models List
* **Aspect-based Attentive encoders**:
- Multilayer Perceptron (MLP)
[[code]](arenets/attention/architectures/mlp.py) /
[[github:nicolay-r]](https://github.com/nicolay-r/mlp-attention);
* **Self-based Attentive encoders**:
- P. Zhou et. al.
[[code]](arenets/attention/architectures/self_p_zhou.py) /
[[github:SeoSangwoo]](https://github.com/SeoSangwoo/Attention-Based-BiLSTM-relation-extraction);
- Z. Yang et. al.
[[code]](arenets/attention/architectures/self_z_yang.py) /
[[github:ilivans]](https://github.com/ilivans/tf-rnn-attention);
* **Single Sentence Based Architectures**:
- CNN
[[code]](arenets/context/architectures/cnn.py) /
[[github:roomylee]](https://github.com/roomylee/cnn-relation-extraction);
- CNN + Aspect-based MLP Attention
[[code]](arenets/context/architectures/base/att_cnn_base.py);
- PCNN
[[code]](arenets/context/architectures/pcnn.py) /
[[github:nicolay-r]](https://github.com/nicolay-r/sentiment-pcnn);
- PCNN + Aspect-based MLP Attention
[[code]](arenets/context/architectures/base/att_pcnn_base.py);
- RNN (LSTM/GRU/RNN)
[[code]](arenets/context/architectures/rnn.py) /
[[github:roomylee]](https://github.com/roomylee/rnn-text-classification-tf);
- IAN (frames based)
[[code]](arenets/context/architectures/ian_frames.py) /
[[github:lpq29743]](https://github.com/lpq29743/IAN);
- RCNN (BiLSTM + CNN)
[[code]](arenets/context/architectures/rcnn.py) /
[[github:roomylee]](https://github.com/roomylee/rcnn-text-classification);
- RCNN + Self Attention
[[code]](arenets/context/architectures/rcnn_self.py);
- BiLSTM
[[code]](arenets/context/architectures/bilstm.py) /
[[github:roomylee]](https://github.com/roomylee/rnn-text-classification-tf);
- Bi-LSTM + Aspect-based MLP Attention
[[code]](arenets/context/architectures/base/att_bilstm_base.py)
- Bi-LSTM + Self Attention
[[code]](arenets/context/architectures/self_att_bilstm.py) /
[[github:roomylee]](https://github.com/roomylee/self-attentive-emb-tf);
- RCNN + Self Attention
[[code]](arenets/context/architectures/att_self_rcnn.py);
* **Multi Sentence Based Encoders Architectures**:
- Self Attentive
[[code]](arenets/multi/architectures/att_self.py);
- Max Pooling
[[code]](arenets/multi/architectures/max_pooling.py) /
[[paper]](https://pdfs.semanticscholar.org/8731/369a707046f3f8dd463d1fd107de31d40a24.pdf);
- Single MLP
[[code]](arenets/multi/architectures/base/base_single_mlp.py);
## FAQ
#### [How to prepare input data?](docs/input_data.md)
#### [How to setup `jsonl` or `csv` data reader?](docs/input_readers.md)
#### [How to implement a custom model with attention?](docs/tutorial_attention.md)
#### [How to customize the prediction output?](docs/tutorial_predict_output.md)
## Test Details
This project has been tested under the following setup:
* NVidia GTX-1060/1080 TI
* CUDA compilation tools, release 10.0, V10.0.130
* Python 3.6.9
* Pandas 0.25.3 (Optional, only for `CSV` reading)
* [Pip freeze package list](docs/pip-freeze-list.txt)
## How to cite
Our one and my personal interest is to help you better explore and analyze attitude and relation extraction related tasks with AREnets.
A great research is also accompanied with the faithful reference.
if you use or extend our work, please cite as follows:
```
@misc{arenets2023,
author={Nicolay Rusnachenko},
title={{AREnets}: Tensorflow-based framework of attentive neural-network
models for text classfication and relation extraction tasks},
year={2023},
url={https://github.com/nicolay-r/AREnets},
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/nicolay-r/AREnets",
"name": "arenets",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6, <3.7",
"maintainer_email": "",
"keywords": "natural language processing,relation extraction,sentiment analysis",
"author": "Nicolay Rusnachenko",
"author_email": "rusnicolay@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/97/11/e68da648cfd95dfcfd7fb357e252f33d6b4d754cf0cb10201d03734fa9e0/arenets-0.23.1.tar.gz",
"platform": null,
"description": "# AREnets\n\n![](https://img.shields.io/badge/Python-3.6.9-brightgreen.svg)\n![](https://img.shields.io/badge/Tensorflow-1.14-orange.svg)\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nicolay-r/AREnets/blob/master/arenets_colab_tutorial.ipynb)\n\n<p align=\"center\">\n <img src=\"logo.png\"/>\n</p>\n\n\n**AREnets** -- is an [OpenNRE](https://github.com/thunlp/OpenNRE) like project, but the kernel based on [tensorflow](https://www.tensorflow.org/)\nlibrary, with implementation of neural networks on top of it, designed for **A**ttitude and **R**elation **E**xtraction tasks.\nAREnets is a result of advances in [Sentiment Attitude Extraction task](http://nlpprogress.com/russian/sentiment-analysis.html)\nbut introduced in generalized form and applicable for other relation-extraction related classification tasks. \nIt provides ready to use [neural networks](#models-list) and API for `subject`\u2192`object` pairs classification in a given samples. \nThis project is powered by \n[AREkit](https://github.com/nicolay-r/AREkit) \ncore API, squeezed into a tiny \n[kernel](https://github.com/nicolay-r/AREnets/tree/dev/arenets/arekit).\n\n## Contents\n* [Installation](#installation)\n* [Quick Start](#quick-start)\n* [Models List](#models-list)\n* [FAQ](#faq)\n* [Test Details](#test-details)\n* [How to cite](#how-to-cite)\n\n## Installation\n\n```bash\npip install git+https://github.com/nicolay-r/AREnets@master\n```\n\n## Quick Start\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/nicolay-r/AREnets/blob/master/arenets_colab_tutorial.ipynb)\n\nSimply just open and follow the [google-colab](https://colab.research.google.com/github/nicolay-r/AREnets/blob/master/arenets_colab_tutorial.ipynb) \nversion like IDE to modify the train and inference code of provided tutorial:\n<p align=\"center\">\n <img src=\"docs/colab-as-ide-logo.png\"/>\n</p>\n\nThe complete examples are in [tutorials](tutorials) folder.\n\nFirst of all, prepare your `_data` folder with data required for training model and performing inference.\n* **Input samples**: check out [input data formatting guide](docs/input_data.md).\n* **Embeddings** could be obtained from [NLPL repository](http://vectors.nlpl.eu/repository/), \n with `model.txt` file placed at `_data` folder; \n * See [downloading script](tutorials/_data/download_embedding.sh);\n\nMore on input features could be [found here](docs/input_features.md).\n\n### Train\n```python\nfrom arenets.quickstart.train import train\nfrom arenets.enum_name_types import ModelNames\n\ntrain(input_data_dir=\"_data\", labels_count=3, model_name=ModelNames.CNN, epochs_count=10)\n```\nRuns `cnn` model with `10` epochs for `3-class` classification problem; \nall the model-related details will be stored at `_data` model by default.\n\n### Predict \n```python\nfrom arenets.quickstart.predict import predict\nfrom arenets.arekit.common.data_type import DataType\nfrom arenets.enum_name_types import ModelNames\n\npredict(input_data_dir=\"_data\", output_dir=\"_out\", labels_count=3, model_name=ModelNames.CNN, data_type=DataType.Test)\n```\nPredict `test` results for pre-trained `cnn` model and saves them into `_out` folder\n\n## Models List\n\n* **Aspect-based Attentive encoders**:\n - Multilayer Perceptron (MLP)\n [[code]](arenets/attention/architectures/mlp.py) /\n [[github:nicolay-r]](https://github.com/nicolay-r/mlp-attention);\n* **Self-based Attentive encoders**:\n - P. Zhou et. al.\n [[code]](arenets/attention/architectures/self_p_zhou.py) /\n [[github:SeoSangwoo]](https://github.com/SeoSangwoo/Attention-Based-BiLSTM-relation-extraction);\n - Z. Yang et. al.\n [[code]](arenets/attention/architectures/self_z_yang.py) /\n [[github:ilivans]](https://github.com/ilivans/tf-rnn-attention);\n* **Single Sentence Based Architectures**:\n - CNN\n [[code]](arenets/context/architectures/cnn.py) /\n [[github:roomylee]](https://github.com/roomylee/cnn-relation-extraction);\n - CNN + Aspect-based MLP Attention\n [[code]](arenets/context/architectures/base/att_cnn_base.py);\n - PCNN\n [[code]](arenets/context/architectures/pcnn.py) /\n [[github:nicolay-r]](https://github.com/nicolay-r/sentiment-pcnn);\n - PCNN + Aspect-based MLP Attention\n [[code]](arenets/context/architectures/base/att_pcnn_base.py);\n - RNN (LSTM/GRU/RNN)\n [[code]](arenets/context/architectures/rnn.py) /\n [[github:roomylee]](https://github.com/roomylee/rnn-text-classification-tf);\n - IAN (frames based)\n [[code]](arenets/context/architectures/ian_frames.py) /\n [[github:lpq29743]](https://github.com/lpq29743/IAN);\n - RCNN (BiLSTM + CNN)\n [[code]](arenets/context/architectures/rcnn.py) /\n [[github:roomylee]](https://github.com/roomylee/rcnn-text-classification);\n - RCNN + Self Attention\n [[code]](arenets/context/architectures/rcnn_self.py);\n - BiLSTM\n [[code]](arenets/context/architectures/bilstm.py) /\n [[github:roomylee]](https://github.com/roomylee/rnn-text-classification-tf);\n - Bi-LSTM + Aspect-based MLP Attention \n [[code]](arenets/context/architectures/base/att_bilstm_base.py)\n - Bi-LSTM + Self Attention\n [[code]](arenets/context/architectures/self_att_bilstm.py) /\n [[github:roomylee]](https://github.com/roomylee/self-attentive-emb-tf);\n - RCNN + Self Attention\n [[code]](arenets/context/architectures/att_self_rcnn.py);\n* **Multi Sentence Based Encoders Architectures**:\n - Self Attentive \n [[code]](arenets/multi/architectures/att_self.py);\n - Max Pooling\n [[code]](arenets/multi/architectures/max_pooling.py) /\n [[paper]](https://pdfs.semanticscholar.org/8731/369a707046f3f8dd463d1fd107de31d40a24.pdf);\n - Single MLP\n [[code]](arenets/multi/architectures/base/base_single_mlp.py);\n\n## FAQ\n\n#### [How to prepare input data?](docs/input_data.md)\n#### [How to setup `jsonl` or `csv` data reader?](docs/input_readers.md)\n#### [How to implement a custom model with attention?](docs/tutorial_attention.md)\n#### [How to customize the prediction output?](docs/tutorial_predict_output.md)\n\n## Test Details\n\nThis project has been tested under the following setup:\n* NVidia GTX-1060/1080 TI\n* CUDA compilation tools, release 10.0, V10.0.130\n* Python 3.6.9\n* Pandas 0.25.3 (Optional, only for `CSV` reading)\n* [Pip freeze package list](docs/pip-freeze-list.txt)\n\n## How to cite\n\nOur one and my personal interest is to help you better explore and analyze attitude and relation extraction related tasks with AREnets.\nA great research is also accompanied with the faithful reference.\nif you use or extend our work, please cite as follows:\n```\n@misc{arenets2023,\n author={Nicolay Rusnachenko},\n title={{AREnets}: Tensorflow-based framework of attentive neural-network \n models for text classfication and relation extraction tasks},\n year={2023},\n url={https://github.com/nicolay-r/AREnets},\n}\n```\n\n\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Tensorflow-based framework which lists implementation of conventional neural network models (CNN, RNN-based) for Relation Extraction classification tasks as well as API for custom model implementation",
"version": "0.23.1",
"project_urls": {
"Homepage": "https://github.com/nicolay-r/AREnets"
},
"split_keywords": [
"natural language processing",
"relation extraction",
"sentiment analysis"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "005b7c2a5bc30cf4f987542f57035ebb70cc4f40ae145dd718f755c44c77ea80",
"md5": "d5cbb092edd5e993878627ce023e75c0",
"sha256": "7d93d0a8653a5f2bc5ee4d66b32e7b2c59ac5fd95f8e803dc07084abfe84445f"
},
"downloads": -1,
"filename": "arenets-0.23.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d5cbb092edd5e993878627ce023e75c0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6, <3.7",
"size": 224529,
"upload_time": "2023-11-08T13:31:16",
"upload_time_iso_8601": "2023-11-08T13:31:16.141501Z",
"url": "https://files.pythonhosted.org/packages/00/5b/7c2a5bc30cf4f987542f57035ebb70cc4f40ae145dd718f755c44c77ea80/arenets-0.23.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9711e68da648cfd95dfcfd7fb357e252f33d6b4d754cf0cb10201d03734fa9e0",
"md5": "5f1ee9611c1a07d33bd8826f7722e81b",
"sha256": "a0c08d43e4aab1eaa764ee489514436240306de648f7ef9e10d600dc6716acbe"
},
"downloads": -1,
"filename": "arenets-0.23.1.tar.gz",
"has_sig": false,
"md5_digest": "5f1ee9611c1a07d33bd8826f7722e81b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6, <3.7",
"size": 155870,
"upload_time": "2023-11-08T13:31:18",
"upload_time_iso_8601": "2023-11-08T13:31:18.146800Z",
"url": "https://files.pythonhosted.org/packages/97/11/e68da648cfd95dfcfd7fb357e252f33d6b4d754cf0cb10201d03734fa9e0/arenets-0.23.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-08 13:31:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nicolay-r",
"github_project": "AREnets",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "arenets"
}