https://github.com/mfa/allennlp-reverse-seq2seq
Sequence-to-Sequence example with AllenNLP and attention visualization
https://github.com/mfa/allennlp-reverse-seq2seq
Last synced: about 1 year ago
JSON representation
Sequence-to-Sequence example with AllenNLP and attention visualization
- Host: GitHub
- URL: https://github.com/mfa/allennlp-reverse-seq2seq
- Owner: mfa
- Created: 2019-08-20T17:53:04.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-06-26T15:51:05.000Z (almost 6 years ago)
- Last Synced: 2025-02-07T14:22:37.273Z (over 1 year ago)
- Language: Python
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.org
Awesome Lists containing this project
README
#+STARTUP: showeverything
#+OPTIONS: toc:nil
#+OPTIONS: ^:nil
** reverse
*** about
Train a seq2seq encoder-decoder model to reverse the input string.
rebuild of the tutorial of joeynmt:
https://joeynmt.readthedocs.io/en/latest/tutorial.html
in AllenNLP
Blog posts describing the code in this repository:
- https://madflex.de/posts/allennlp--reverse-sequence-example/
- https://madflex.de/posts/allennlp--sequence-to-sequence-attention-plots/
*** first
download generator script from joeynmt
#+BEGIN_SRC bash
mkdir -p tools; cd tools
wget https://raw.githubusercontent.com/joeynmt/joeynmt/master/scripts/generate_reverse_task.py
cd ..
#+END_SRC
generate some data
#+BEGIN_SRC bash
mkdir data; cd data
python ../tools/generate_reverse_task.py
cd ..
#+END_SRC
convert data to tsv for seq2seq datareader
#+BEGIN_SRC bash
cd data
paste dev.src dev.trg > dev.csv
paste test.src test.trg > test.csv
paste train.src train.trg > train.csv
cd ..
#+END_SRC
*** training
#+begin_src bash
allennlp train configurations/reverse_starting_point.json -s output -f --include-package library
#+end_src
*** predict / evaluation
#+begin_src bash
echo '{"source": "15 28 32 4", "target": "4 32 28 15"}' > reverse_example.json
allennlp predict output/model.tar.gz reverse_example.json --predictor seq2seq
#+end_src
*** predict with attention plots
#+begin_src bash
allennlp predict output/model.tar.gz --use-dataset-reader examples.csv --predictor my_seq2seq --output-file output/examples.output --include-package library
python tools/plot_attention.py
#+end_src