RAN: Recurrent Attention Network
📢 This project is still in the works in order to make long document modeling easier.
⬇️ Installation
stable
python -m pip install -U rannet
latest
python -m pip install git+https://github.com/4AI/RAN.git
environment
- ⭐ tensorflow>2.0,<=2.10 🤗
export TF_KERAS=1 - tensorflow>=1.14,<2.0 🤗 Keras==2.3.1
🏛️ Pretrained Models
| Lang | Google Drive | Baidu NetDrive |
|---|---|---|
| EN | base | base[code: djkj] |
| CN | base | small | base[code: e47w] | small[code: mdmg] |
🚀 Quick Tour
🈶 w/ pretrained models
For the classification task
from rannet import RanNet, RanNetWordPieceTokenizer
vocab_path = 'pretrained/vocab.txt'
ckpt_path = 'pretrained/model.ckpt'
config_path = 'pretrained/config.json'
tokenizer = RanNetWordPieceTokenizer(vocab_path, lowercase=True)
rannet, rannet_model = RanNet.load_rannet(
config_path=config_path, checkpoint_path=ckpt_path, return_sequences=False)
output = rannet_model.output # (B, D)
output = L.Dropout(0.1)(output)
output = L.Dense(2, activation='softmax')(output)
model = keras.models.Model(rannet_model.input, output)
model.summary()
For the sequence task
from rannet import RanNet, RanNetWordPieceTokenizer
vocab_path = 'pretrained/vocab.txt'
ckpt_path = 'pretrained/model.ckpt'
config_path = 'pretrained/config.json'
tokenizer = RanNetWordPieceTokenizer(vocab_path, lowercase=True)
rannet, rannet_model = RanNet.load_rannet(
config_path=config_path, checkpoint_path=ckpt_path, return_cell=False)
output = rannet_model.output # (B, L, D)
rannet_model.summary()
🈚 w/o pretrained models
Embed the RAN (a Keras layer) into your network.
from rannet import RAN
ran = RAN(head_num=8,
head_size=256,
window_size=256,
min_window_size=16,
activation='swish',
kernel_initializer='glorot_normal',
apply_lm_mask=False,
apply_seq2seq_mask=False,
apply_memory_review=True,
dropout_rate=0.0,
cell_initializer_type='zero')
output, cell = ran(X)
📚 Citation
If you use our code in your research, please cite our work:
@inproceedings{li-etal-2023-ran,
title = "Recurrent Attention Networks for Long-text Modeling",
author = "Li, Xianming and Li, Zongxi and Luo, Xiaotian and Xie, Haoran and Lee, Xing and Zhao, Yingbin and Wang, Fu Lee and Li, Qing",
booktitle = "Findings of the Association for Computational Linguistics: ACL 2023",
year = "2023",
publisher = "Association for Computational Linguistics"
}
Contact
Please contact us at 1) for code problems, create a GitHub issue; 2) for paper problems, email xmlee97@gmail.com
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rannet-0.1.0.tar.gz
(30.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
rannet-0.1.0-py3-none-any.whl
(31.9 kB
view details)
File details
Details for the file rannet-0.1.0.tar.gz.
File metadata
- Download URL: rannet-0.1.0.tar.gz
- Upload date:
- Size: 30.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e30f30d56ccb7e8e0b2b179f704a33367b4cc6b688d7814c7a39e81a6e24ec43
|
|
| MD5 |
bf55c52de4ade8bfed9e1564f57787c0
|
|
| BLAKE2b-256 |
fed1a1f8190afe91e74e5239fcc184e8c8837f93e004a9949c349c55a335d4b4
|
File details
Details for the file rannet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rannet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c55eae7e23068cae6271917c2803b7532fad0654653bb7dee0c1cbec46e2628b
|
|
| MD5 |
8a2948259d2db2ae5d064b2877f51c0e
|
|
| BLAKE2b-256 |
fdca61cc2c68441886492bea1a652bb8eeccdfbe3c49b87dbde43bcf4c0f94e2
|