├── .github └── workflows │ ├── dockerhub.yml │ └── unittest.yml ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── VERSION ├── addons ├── README.md ├── __init__.py ├── paired.py ├── pretrained_transformer_tagger.py ├── reader_conllcased.py ├── reader_pandas.py ├── reader_parallel_classify.py ├── reporting_xpctl.py └── vec_text.py ├── baseline ├── README.md ├── __init__.py ├── bleu.py ├── confusion.py ├── conlleval.py ├── data.py ├── embeddings.py ├── mime_type.py ├── model.py ├── onnx │ ├── __init__.py │ ├── apis │ │ ├── __init__.py │ │ ├── grpc_service_pb2.py │ │ ├── grpc_service_pb2_grpc.py │ │ ├── model_config_pb2.py │ │ └── model_config_pb2_grpc.py │ └── remote.py ├── progress.py ├── pytorch │ ├── __init__.py │ ├── classify │ │ ├── __init__.py │ │ ├── model.py │ │ └── train.py │ ├── deps │ │ ├── __init__.py │ │ ├── model.py │ │ └── train.py │ ├── embeddings.py │ ├── lm │ │ ├── __init__.py │ │ ├── model.py │ │ └── train.py │ ├── optz.py │ ├── remote.py │ ├── seq2seq │ │ ├── __init__.py │ │ ├── decoders.py │ │ ├── encoders.py │ │ ├── model.py │ │ └── train.py │ ├── tagger │ │ ├── __init__.py │ │ ├── model.py │ │ └── train.py │ └── torchy.py ├── reader.py ├── remote.py ├── reporting.py ├── services.py ├── tensorflow_serving │ ├── __init__.py │ └── apis │ │ ├── __init__.py │ │ ├── classification_pb2.py │ │ ├── classification_pb2_grpc.py │ │ ├── get_model_metadata_pb2.py │ │ ├── get_model_metadata_pb2_grpc.py │ │ ├── inference_pb2.py │ │ ├── inference_pb2_grpc.py │ │ ├── input_pb2.py │ │ ├── input_pb2_grpc.py │ │ ├── model_management_pb2.py │ │ ├── model_management_pb2_grpc.py │ │ ├── model_pb2.py │ │ ├── model_pb2_grpc.py │ │ ├── model_service_pb2.py │ │ ├── model_service_pb2_grpc.py │ │ ├── predict_pb2.py │ │ ├── predict_pb2_grpc.py │ │ ├── prediction_service_pb2.py │ │ ├── prediction_service_pb2_grpc.py │ │ ├── regression_pb2.py │ │ └── regression_pb2_grpc.py ├── tf │ ├── __init__.py │ ├── classify │ │ ├── __init__.py │ │ ├── model.py │ │ ├── train.py │ │ └── training │ │ │ ├── __init__.py │ │ │ ├── distributed.py │ │ │ ├── eager.py │ │ │ └── utils.py │ ├── deps │ │ ├── __init__.py │ │ ├── model.py │ │ └── train.py │ ├── embeddings.py │ ├── lm │ │ ├── __init__.py │ │ ├── model.py │ │ ├── train.py │ │ └── training │ │ │ ├── __init__.py │ │ │ ├── distributed.py │ │ │ ├── eager.py │ │ │ └── utils.py │ ├── optz.py │ ├── remote.py │ ├── seq2seq │ │ ├── __init__.py │ │ ├── decoders.py │ │ ├── encoders.py │ │ ├── model.py │ │ ├── train.py │ │ └── training │ │ │ ├── __init__.py │ │ │ ├── distributed.py │ │ │ ├── eager.py │ │ │ └── utils.py │ ├── tagger │ │ ├── __init__.py │ │ ├── model.py │ │ └── train.py │ └── tfy.py ├── train.py ├── utils.py ├── vectorizers.py ├── version.py └── w2v.py ├── docker ├── Dockerfile.pytorch-cuda10 ├── Dockerfile.pytorch-cuda11 ├── Dockerfile.pytorch-cuda111 ├── Dockerfile.pytorch-cuda111x ├── Dockerfile.pytorch-cuda11x ├── Dockerfile.tf2-cuda10 └── Dockerfile.tf2-cuda11 ├── docs ├── addons.md ├── baseline.md ├── classify.md ├── dataset-embedding.md ├── docker.md ├── export.md ├── fine-tuning.md ├── fw.md ├── hpctl.md ├── lm.md ├── logging.md ├── main.md ├── mead.md ├── reporting.md ├── seq2seq.md ├── tagging.md ├── v1.md ├── v2.md └── xpctl.md ├── eval ├── conlleval.pl └── multi-bleu.pl ├── layers ├── README.md ├── eight_mile │ ├── __init__.py │ ├── bleu.py │ ├── calibration │ │ ├── __init__.py │ │ ├── calibration.py │ │ ├── metrics │ │ │ ├── __init__.py │ │ │ └── calibration_error.py │ │ └── plot │ │ │ ├── __init__.py │ │ │ ├── confidence_histogram.py │ │ │ └── reliability_diagram.py │ ├── confusion.py │ ├── conlleval.py │ ├── downloads.py │ ├── embeddings.py │ ├── metrics.py │ ├── optz.py │ ├── progress.py │ ├── pytorch │ │ ├── __init__.py │ │ ├── embeddings.py │ │ ├── layers.py │ │ ├── optz.py │ │ └── serialize.py │ ├── tf │ │ ├── __init__.py │ │ ├── embeddings.py │ │ ├── layers.py │ │ ├── optz.py │ │ └── serialize.py │ ├── utils.py │ └── version.py ├── pyproject.toml ├── setup.cfg └── setup.py ├── mead ├── README.md ├── __init__.py ├── api_examples │ ├── __init__.py │ ├── analyze_calibration.py │ ├── bio_to_iobes.py │ ├── classify_paired_text.py │ ├── classify_tag_text.py │ ├── classify_text.py │ ├── convert_hf2npz.py │ ├── deps_text.py │ ├── eager_lm_pytorch.py │ ├── eager_lm_tf.py │ ├── ed_text.py │ ├── finetuned_transformer_to_npz.py │ ├── generate_lm.py │ ├── generate_mlm.py │ ├── iob_to_bio.py │ ├── iob_to_iobes.py │ ├── iobes_result_to_bio.py │ ├── lm_text.py │ ├── preproc_paired.py │ ├── preproc_tag.py │ ├── preproc_tlm.py │ ├── preproc_utils.py │ ├── pretrain_discrim_pytorch.py │ ├── pretrain_discrim_tf.py │ ├── pretrain_paired_pytorch.py │ ├── pretrain_paired_tf.py │ ├── pretrain_tag_tf.py │ ├── pretrain_tlm_grad_accum_tf.py │ ├── pretrain_tlm_pytorch.py │ ├── pretrain_tlm_tf.py │ ├── pretrain_transformer_seq2seq_pytorch.py │ ├── pretrain_transformer_seq2seq_tf.py │ ├── response_selection.py │ ├── run_senteval.py │ ├── score_text.py │ ├── seq2seq_generate_response.py │ ├── tag_text.py │ ├── text2embeddings.py │ └── transformer_utils.py ├── clean.py ├── config │ ├── ag-news-lstm.json │ ├── ag-news-single-lstm.json │ ├── ag-news.json │ ├── atis-bert-joint-tf.yml │ ├── atis-bert-joint.yml │ ├── atis-bert.yml │ ├── atis-sf.yml │ ├── conll-bert-hf.yml │ ├── conll-bert.yml │ ├── conll-cnn.yml │ ├── conll-elmo.yml │ ├── conll-no-crf.json │ ├── conll-single-tf.json │ ├── conll-single.json │ ├── conll-stacked.json │ ├── conll-transformer.json │ ├── conll.json │ ├── datasets.json │ ├── dbpedia.json │ ├── deps-pyt.yml │ ├── embeddings.json │ ├── gn-embed.json │ ├── iwslt15-en-vi-transformer.json │ ├── iwslt15-en-vi.json │ ├── iwslt15-luong.json │ ├── logging.json │ ├── mead-settings.json │ ├── mnli-m-bert-base-uncased.yml │ ├── mp-settings.json │ ├── mrda-hier.json │ ├── mrda.json │ ├── mrpc-bert-base-uncased.yml │ ├── ontonotes-bert.yml │ ├── ontonotes.json │ ├── ptb-350-deps-pyt.yml │ ├── ptb-kim-adam.yml │ ├── ptb-med.json │ ├── ptb-small-tf.json │ ├── ptb-transformer.json │ ├── qnli-bert-base-uncased.yml │ ├── qqp-bert-base-uncased.yml │ ├── remote-settings.json │ ├── reverse-transformer.json │ ├── reverse.json │ ├── rte-bert-base-uncased.yml │ ├── snips-intent.json │ ├── snips.json │ ├── snli-bert-base-cased.yml │ ├── snli-bert-base-uncased.yml │ ├── snli-sbert-base-uncased.yml │ ├── sst2-bert-base-uncased.yml │ ├── sst2-bert-hf-base-uncased.json │ ├── sst2-bert-official-base-uncased.json │ ├── sst2-demolib.yml │ ├── sst2-distributed.json │ ├── sst2-elmo-eh.json │ ├── sst2-elmo-hub.json │ ├── sst2-elmo-large.json │ ├── sst2-gpt2-small.yml │ ├── sst2-lstm-840b.json │ ├── sst2-lstm-char.json │ ├── sst2-lstm-pyt.yml │ ├── sst2-lstm.json │ ├── sst2-nogpu-pyt.yml │ ├── sst2-pyt.yml │ ├── sst2-resconv.yml │ ├── sst2-rnf-pyt.yml │ ├── sst2-wandb.json │ ├── sst2.json │ ├── trec-bert-base-uncased.json │ ├── trec-bert-finetune-pytorch-eh.json │ ├── trec-bert-finetune-tf-eh.json │ ├── trec-cnn.yml │ ├── trec-demolib.yml │ ├── trec-gpt2-small.yml │ ├── trec-lstm.yml │ ├── trec-roberta-base.json │ ├── twpos-blstm-lan.json │ ├── twpos-nogpu-pyt.json │ ├── twpos-stacked.json │ ├── twpos.json │ ├── vecs.json │ ├── wmt-de-en-luong.json │ ├── wnli-bert-base-uncased.yml │ ├── wnut-bert-hf.yml │ ├── wnut-bert.yml │ ├── wnut-elmo.json │ ├── wnut-no-crf.json │ ├── wnut-single-no-crf.json │ ├── wnut-single.json │ └── wnut.json ├── eval.py ├── export.py ├── exporters.py ├── hash_config.py ├── preprocessors.py ├── pytorch │ ├── __init__.py │ └── exporters.py ├── tasks.py ├── tf │ ├── __init__.py │ ├── exporters.py │ ├── preproc_exporters.py │ └── preprocessors.py ├── trainer.py └── utils.py ├── pyproject.toml ├── scripts ├── README.md ├── compare_calibrations.py ├── download_all.py ├── images │ ├── CosineLR.png │ ├── ExampleLR.png │ ├── LR_Finder.png │ └── tagger_find.png ├── lr_compare.py ├── lr_find.py ├── lr_visualize.py ├── speed_configs │ ├── conll-bio.json │ ├── iwslt15-en-vi.json │ ├── ptb-convchar.json │ ├── ptb-med.json │ ├── sst2-lstm.yml │ └── sst2.json ├── speed_test │ ├── __init__.py │ ├── report.py │ └── run.py └── speed_tests.py ├── setup.cfg ├── setup.py └── tests ├── README.md ├── export-config-classify-grpc.yml ├── export-config-classify-rest.yml ├── export-config-tagger-grpc.yml ├── export-config-tagger-rest.yml ├── export-elmo-conll-rest.yml ├── export-elmo-sst2-rest.yml ├── test_attention_pytorch.py ├── test_beam_pytorch.py ├── test_beam_tensorflow.py ├── test_bleu.py ├── test_calc_feats.py ├── test_cm.py ├── test_conll.py ├── test_crf_pytorch.py ├── test_data ├── bert-base-uncased-vocab.txt ├── codes.30k ├── config │ ├── datasets.json │ ├── embeddings.json │ └── test_tagger.json ├── crf_vocab ├── eng.testb.small.conll ├── eng.testb.small.txt ├── glove_test.txt ├── multi_col.txt ├── multi_parallel.1 ├── multi_parallel.2 ├── single_col.txt ├── tagger_model │ ├── tagger-model-tf-21855-char.vocab │ ├── tagger-model-tf-21855-word.vocab │ ├── tagger-model-tf-21855.data-00000-of-00001 │ ├── tagger-model-tf-21855.graph │ ├── tagger-model-tf-21855.index │ ├── tagger-model-tf-21855.labels │ ├── tagger-model-tf-21855.meta │ ├── tagger-model-tf-21855.saver │ └── tagger-model-tf-21855.state ├── test.conll ├── test_json.json ├── test_yaml.yml ├── tsv_parallel.tsv ├── tsv_unstruct_file.tsv ├── vocab.30k └── w2v_test.bin ├── test_decay.py ├── test_decoders_pytorch.py ├── test_decoders_tensorflow.py ├── test_embeddings.py ├── test_exporters.sh ├── test_hash_utils.py ├── test_iobes.py ├── test_label_first_data_utils.py ├── test_layers_pytorch.py ├── test_layers_tf2.py ├── test_lr_sched_tf2.py ├── test_mead_tasks.py ├── test_mead_utils.py ├── test_model.py ├── test_parse_extra_args.py ├── test_pytorch_masks.py ├── test_pytorch_transformer.py ├── test_pytorch_variational_dropout.py ├── test_pytorch_weight_sharing.py ├── test_read_files.py ├── test_readers.py ├── test_rel_bias_pytorch.py ├── test_rel_bias_tf.py ├── test_reporting_hooks.py ├── test_sample.py ├── test_tag_text.sh ├── test_tf_transformer.py ├── test_tlm_serialization.py ├── test_torchy.py ├── test_transition_masks.py ├── test_utils.py ├── test_vectorizers.py ├── test_windowed_ra_pytorch.py └── test_windowed_ra_tf.py /.github/workflows/dockerhub.yml: -------------------------------------------------------------------------------- 1 | name: Publish to DockerHub 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | - name: Set up Docker Buildx 15 | uses: docker/setup-buildx-action@v1 16 | - name: Login to DockerHub 17 | uses: docker/login-action@v1 18 | with: 19 | username: ${{ secrets.DOCKER_USERNAME }} 20 | password: ${{ secrets.DOCKER_PASSWORD }} 21 | - name: Build & Push PyTorch CUDA 10 image 22 | uses: docker/build-push-action@v2 23 | with: 24 | file: docker/Dockerfile.pytorch-cuda10 25 | push: true 26 | tags: meadml/mead2-pytorch-gpu:latest 27 | - name: Build & Push PyTorch CUDA 11 image 28 | uses: docker/build-push-action@v2 29 | with: 30 | file: docker/Dockerfile.pytorch-cuda11 31 | push: true 32 | tags: meadml/mead2-pytorch-cuda11:latest 33 | - name: Build & Push PyTorch CUDA 11.1 image 34 | uses: docker/build-push-action@v2 35 | with: 36 | file: docker/Dockerfile.pytorch-cuda111 37 | push: true 38 | tags: meadml/mead2-pytorch-cuda111:latest 39 | - name: Build & Push PyTorch CUDA 11 ext image 40 | uses: docker/build-push-action@v2 41 | with: 42 | file: docker/Dockerfile.pytorch-cuda11x 43 | push: true 44 | tags: meadml/mead2-pytorch-cuda11x:latest 45 | - name: Build & Push PyTorch CUDA 11.1 ext image 46 | uses: docker/build-push-action@v2 47 | with: 48 | file: docker/Dockerfile.pytorch-cuda111x 49 | push: true 50 | tags: meadml/mead2-pytorch-cuda111x:latest 51 | - name: Build & Push TF2 CUDA 10 image 52 | uses: docker/build-push-action@v2 53 | with: 54 | file: docker/Dockerfile.tf2-cuda10 55 | push: true 56 | tags: meadml/mead2-tf2-gpu:latest 57 | - name: Build & Push TF2 CUDA 11 image 58 | uses: docker/build-push-action@v2 59 | with: 60 | file: docker/Dockerfile.tf2-cuda11 61 | push: true 62 | tags: meadml/mead2-tf2-cuda11:latest 63 | 64 | -------------------------------------------------------------------------------- /.github/workflows/unittest.yml: -------------------------------------------------------------------------------- 1 | name: Unit Test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | 13 | test-tf-2-1: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | max-parallel: 4 17 | matrix: 18 | tf-version: 19 | - 2.1.0 20 | container: tensorflow/tensorflow:${{matrix.tf-version}}-py3 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Install Baseline 24 | run: | 25 | cd layers 26 | pip install -e . 27 | cd .. 28 | pip install tensorflow_addons==0.9.1 29 | pip install -e .[test,yaml] 30 | - name: Unit Test Tf ${{matrix.tf-version}} 31 | run: | 32 | pytest --forked 33 | 34 | test-tf-2-3: 35 | runs-on: ubuntu-latest 36 | strategy: 37 | max-parallel: 4 38 | matrix: 39 | tf-version: 40 | - 2.3.0 41 | container: tensorflow/tensorflow:${{matrix.tf-version}} 42 | steps: 43 | - uses: actions/checkout@v2 44 | - name: Install Baseline 45 | run: | 46 | cd layers 47 | pip install -e . 48 | cd .. 49 | pip install tensorflow_addons 50 | pip install -e .[test,yaml] 51 | - name: Unit Test Tf ${{matrix.tf-version}} 52 | run: | 53 | pytest --forked 54 | 55 | test-pyt: 56 | runs-on: ubuntu-latest 57 | strategy: 58 | max-parallel: 4 59 | matrix: 60 | pyt-version: 61 | - 1.7.1-cuda11.0-cudnn8-runtime 62 | container: pytorch/pytorch:${{matrix.pyt-version}} 63 | steps: 64 | - uses: actions/checkout@v2 65 | - name: Install Baseline 66 | run: | 67 | cd layers 68 | pip install --no-use-pep517 -e . 69 | cd .. 70 | pip install --no-use-pep517 -e .[test,yaml] 71 | - name: Unit Test PyTorch ${{matrix.pyt-version}} 72 | run: | 73 | pytest --forked 74 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | **/pip-wheel-metadata/ 29 | pip-wheel-metadata/ 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | db.sqlite3 61 | 62 | # Flask stuff: 63 | instance/ 64 | .webassets-cache 65 | 66 | # Scrapy stuff: 67 | .scrapy 68 | 69 | # Sphinx documentation 70 | docs/_build/ 71 | 72 | # PyBuilder 73 | target/ 74 | 75 | # Jupyter Notebook 76 | .ipynb_checkpoints 77 | 78 | # pyenv 79 | .python-version 80 | 81 | # celery beat schedule file 82 | celerybeat-schedule 83 | 84 | # SageMath parsed files 85 | *.sage.py 86 | 87 | # Environments 88 | .env 89 | .venv 90 | env/ 91 | venv/ 92 | ENV/ 93 | env.bak/ 94 | venv.bak/ 95 | 96 | # Spyder project settings 97 | .spyderproject 98 | .spyproject 99 | 100 | # Rope project settings 101 | .ropeproject 102 | 103 | # mkdocs documentation 104 | /site 105 | 106 | # mypy 107 | .mypy_cache/ 108 | 109 | python/README.md 110 | python/MANIFEST.in 111 | 112 | scripts/.lrs 113 | baseline.iml 114 | .idea/* 115 | tags 116 | *.zip 117 | 118 | *.pkl 119 | *.conll 120 | *.onnx 121 | *.script 122 | *.pth 123 | 124 | api-examples/pytorch_cpp/json.hpp 125 | api-examples/pytorch_cpp/libtorch* 126 | api-examples/pytorch_cpp/tag-text 127 | api-examples/pytorch_cpp/classify-text 128 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Portions of this software were developed at Interactions, LLC 2 | (https://www.interactions.com/) 3 | 4 | All contributions by Daniel Pressel 5 | Copyright (c) 2016-2020, Daniel Pressel 6 | All rights reserved. 7 | 8 | All contributions by Interactions, LLC 9 | Copyright (c) 2016-2020, Interactions, LLC. 10 | All rights reserved. 11 | 12 | All other contributions: 13 | Copyright (c) 2016-2020, the respective contributors. 14 | All rights reserved. 15 | 16 | Each contributor holds copyright over their respective contributions. 17 | The project versioning (Git) records all such contribution source information. 18 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 2.5.0 2 | -------------------------------------------------------------------------------- /addons/README.md: -------------------------------------------------------------------------------- 1 | baseline addons 2 | =============== 3 | 4 | These are `addon` models that can be run in `baseline` using `mead`. To run these models, make sure this directory is in your `$PYTHONPATH` 5 | 6 | # Overview 7 | 8 | These models are coded in a backend that is supported by baseline (currently either TensorFlow or PyTorch) 9 | 10 | 11 | -------------------------------------------------------------------------------- /addons/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/addons/__init__.py -------------------------------------------------------------------------------- /addons/vec_text.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from baseline.utils import listify 3 | from baseline.vectorizers import Token1DVectorizer, register_vectorizer, _token_iterator 4 | 5 | 6 | @register_vectorizer(name='text') 7 | class Text1DVectorizer(Token1DVectorizer): 8 | def _next_element(self, tokens, vocab): 9 | for atom in self.iterable(tokens): 10 | yield atom 11 | 12 | def run(self, tokens, vocab): 13 | if self.mxlen < 0: 14 | self.mxlen = self.max_seen 15 | vec1d = np.full(self.mxlen, '', dtype=np.object) 16 | for i, atom in enumerate(self._next_element(tokens, vocab)): 17 | if i == self.mxlen: 18 | i -= 1 19 | break 20 | vec1d[i] = atom 21 | valid_length = i + 1 22 | 23 | if self.time_reverse: 24 | vec1d = vec1d[::-1] 25 | return vec1d, None 26 | return vec1d, valid_length 27 | 28 | 29 | @register_vectorizer(name='dict_text') 30 | class DictText1DVectorizer(Text1DVectorizer): 31 | def __init__(self, **kwargs): 32 | super().__init__(**kwargs) 33 | self.fields = listify(kwargs.get('fields', 'text')) 34 | self.delim = kwargs.get('token_delim', '@@') 35 | 36 | def iterable(self, tokens): 37 | return _token_iterator(self, tokens) 38 | -------------------------------------------------------------------------------- /baseline/README.md: -------------------------------------------------------------------------------- 1 | See the [docs](../../docs/baseline.md) 2 | -------------------------------------------------------------------------------- /baseline/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.version import __version__ 2 | from baseline.utils import * 3 | from baseline.vectorizers import * 4 | from baseline.confusion import * 5 | from baseline.data import * 6 | from baseline.reader import * 7 | from eight_mile.progress import * 8 | from baseline.reporting import * 9 | from baseline.model import * 10 | from baseline.embeddings import * 11 | from baseline.services import * 12 | from baseline.train import * 13 | logger = get_console_logger('baseline', env_key='BASELINE_LOG_LEVEL') 14 | report_logger = get_console_logger('baseline.reporting', env_key='BASELINE_LOG_LEVEL') 15 | -------------------------------------------------------------------------------- /baseline/bleu.py: -------------------------------------------------------------------------------- 1 | import eight_mile.bleu 2 | from eight_mile.bleu import * 3 | from eight_mile.bleu import main 4 | 5 | __all__ = [] 6 | __all__.extend(eight_mile.bleu.__all__) 7 | -------------------------------------------------------------------------------- /baseline/confusion.py: -------------------------------------------------------------------------------- 1 | import eight_mile.confusion 2 | from eight_mile.confusion import * 3 | 4 | __all__ = [] 5 | __all__.extend(eight_mile.confusion.__all__) 6 | -------------------------------------------------------------------------------- /baseline/mime_type.py: -------------------------------------------------------------------------------- 1 | import eight_mile.mime_type 2 | from eight_mile.mime_type import * 3 | 4 | __all__ = [] 5 | __all__.extend(eight_mile.mime_type.__all__) 6 | -------------------------------------------------------------------------------- /baseline/onnx/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /baseline/onnx/apis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/baseline/onnx/apis/__init__.py -------------------------------------------------------------------------------- /baseline/onnx/apis/model_config_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | """Client and server classes corresponding to protobuf-defined services.""" 3 | import grpc 4 | 5 | -------------------------------------------------------------------------------- /baseline/progress.py: -------------------------------------------------------------------------------- 1 | import eight_mile.progress 2 | from eight_mile.progress import * 3 | from eight_mile.utils import exporter, optional_params, register 4 | 5 | __all__ = [] 6 | __all__.extend(eight_mile.progress.__all__) 7 | 8 | -------------------------------------------------------------------------------- /baseline/pytorch/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.pytorch.torchy import * 2 | -------------------------------------------------------------------------------- /baseline/pytorch/classify/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.pytorch.classify.model import * 2 | from baseline.pytorch.classify.train import * 3 | -------------------------------------------------------------------------------- /baseline/pytorch/deps/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.pytorch.deps.model import * 2 | from baseline.pytorch.deps.train import * 3 | -------------------------------------------------------------------------------- /baseline/pytorch/lm/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.pytorch.lm.model import * 2 | from baseline.pytorch.lm.train import * -------------------------------------------------------------------------------- /baseline/pytorch/optz.py: -------------------------------------------------------------------------------- 1 | import eight_mile.optz 2 | from eight_mile.optz import * 3 | 4 | __all__ = [] 5 | __all__.extend(eight_mile.optz.__all__) 6 | -------------------------------------------------------------------------------- /baseline/pytorch/seq2seq/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.pytorch.seq2seq.model import * 2 | from baseline.pytorch.seq2seq.train import * 3 | from baseline.pytorch.seq2seq.encoders import * 4 | from baseline.pytorch.seq2seq.decoders import * 5 | -------------------------------------------------------------------------------- /baseline/pytorch/tagger/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.pytorch.tagger.model import * 2 | from baseline.pytorch.tagger.train import * 3 | -------------------------------------------------------------------------------- /baseline/pytorch/torchy.py: -------------------------------------------------------------------------------- 1 | import math 2 | import copy 3 | import os 4 | import logging 5 | import numpy as np 6 | import torch 7 | import torch.autograd 8 | import torch.nn as nn 9 | import torch.nn.functional as F 10 | from torch.utils.data import IterableDataset, Dataset 11 | from baseline.utils import lookup_sentence, get_version, Offsets 12 | from eight_mile.pytorch.layers import * 13 | 14 | PYT_MAJOR_VERSION = get_version(torch) 15 | 16 | BaseLayer = nn.Module 17 | TensorDef = torch.Tensor 18 | 19 | 20 | class IterableDatasetAdapter(IterableDataset): 21 | def __init__(self, example_list, shuffle=False): 22 | super().__init__() 23 | self.examples = example_list 24 | self.shuffle = shuffle 25 | 26 | def __len__(self): 27 | return len(self.examples) 28 | 29 | def __iter__(self): 30 | while True: 31 | if self.shuffle: 32 | np.random.shuffle(self.examples) 33 | for example in self.examples: 34 | yield example 35 | 36 | 37 | class DatasetAdapter(Dataset): 38 | """Wrapper for example_list, only needed if you care about typing 39 | 40 | PyTorch DatasetSampler declares that it acts on a dataset, so if you care 41 | about typing, use this, otherwise a standard list should fulfill the interface 42 | requirements 43 | """ 44 | def __init__(self, example_list): 45 | super().__init__() 46 | self.examples = example_list 47 | 48 | def __len__(self): 49 | return len(self.examples) 50 | 51 | def __getitem__(self, index): 52 | return self.examples[index] 53 | 54 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/baseline/tensorflow_serving/__init__.py -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/baseline/tensorflow_serving/apis/__init__.py -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/classification_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/get_model_metadata_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/inference_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/input_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/model_management_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/model_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/predict_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tensorflow_serving/apis/regression_pb2_grpc.py: -------------------------------------------------------------------------------- 1 | # Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! 2 | import grpc 3 | 4 | -------------------------------------------------------------------------------- /baseline/tf/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.tfy import * 2 | -------------------------------------------------------------------------------- /baseline/tf/classify/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.classify.train import * 2 | from baseline.tf.classify.model import * 3 | -------------------------------------------------------------------------------- /baseline/tf/classify/train.py: -------------------------------------------------------------------------------- 1 | """Train a classifier with TensorFlow 2 | 3 | This module supports several different ways of training a model 4 | 5 | 1. eager mode (`default` for eager) 6 | 2. distributed eager mode (`distributed`) 7 | """ 8 | from baseline.tf.classify.training import * 9 | -------------------------------------------------------------------------------- /baseline/tf/classify/training/__init__.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from baseline.tf.classify.training.eager import * 3 | from baseline.tf.classify.training.distributed import * 4 | -------------------------------------------------------------------------------- /baseline/tf/classify/training/utils.py: -------------------------------------------------------------------------------- 1 | import six 2 | import os 3 | import time 4 | import logging 5 | import tensorflow as tf 6 | import numpy as np 7 | 8 | # Number of batches to prefetch if using tf.datasets 9 | NUM_PREFETCH = 2 10 | # The shuffle buffer 11 | SHUF_BUF_SZ = 5000 12 | 13 | log = logging.getLogger('baseline.timing') 14 | 15 | 16 | def to_tensors(ts, lengths_key): 17 | """Convert a data feed into a tuple of `features` (`dict`) and `y` values 18 | 19 | This method is required to produce `tf.dataset`s from the input data feed 20 | 21 | :param ts: The data feed to convert 22 | :return: A `tuple` of `features` and `y` (labels) 23 | """ 24 | keys = ts[0].keys() 25 | features = dict((k, []) for k in keys) 26 | for sample in ts: 27 | for k in features.keys(): 28 | # add each sample 29 | for s in sample[k]: 30 | features[k].append(s) 31 | 32 | features = dict((k, np.stack(v)) for k, v in features.items()) 33 | if lengths_key and lengths_key in features: 34 | features['lengths'] = features[lengths_key] 35 | del features[lengths_key] 36 | y = features.pop('y') 37 | return features, y 38 | 39 | 40 | def _report(step, metrics, start, phase, tt, reporting_fns, steps=1): 41 | """Make a report (both metric and timing). 42 | 43 | :param step: `int` The step number of this report (epoch or nstep number). 44 | :param metrics: `dict` The metrics to report. 45 | :param start: `int` The starting time of this segment. 46 | :param phase: `str` The phase type. {'Train', 'Valid', 'Test'} 47 | :param tt: `str` The tick type. {'STEP', 'EPOCH'} 48 | :param reporting_fns: `List[Callable]` The list of reporting functions to call. 49 | :param steps: `int` The number of steps in this segment, used to normalize the time. 50 | """ 51 | elapsed = time.perf_counter() - start 52 | for reporting in reporting_fns: 53 | reporting(metrics, step, phase, tt) 54 | log.debug({ 55 | 'tick_type': tt, 'tick': step, 'phase': phase, 56 | 'time': elapsed / float(steps), 57 | 'step/sec': steps / float(elapsed) 58 | }) 59 | 60 | -------------------------------------------------------------------------------- /baseline/tf/deps/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.deps.train import * 2 | from baseline.tf.deps.model import * 3 | -------------------------------------------------------------------------------- /baseline/tf/lm/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.lm.train import * 2 | from baseline.tf.lm.model import * -------------------------------------------------------------------------------- /baseline/tf/lm/train.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.lm.training import * -------------------------------------------------------------------------------- /baseline/tf/lm/training/__init__.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from baseline.tf.lm.training.eager import * 3 | from baseline.tf.lm.training.distributed import * 4 | -------------------------------------------------------------------------------- /baseline/tf/lm/training/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | import numpy as np 4 | import tensorflow as tf 5 | from baseline.tf.tfy import TRAIN_FLAG, SET_TRAIN_FLAG 6 | from baseline.train import Trainer, register_trainer 7 | from baseline.model import create_model_for 8 | from collections import OrderedDict 9 | 10 | 11 | # Number of batches to prefetch if using tf.datasets 12 | NUM_PREFETCH = 2 13 | # The shuffle buffer 14 | SHUF_BUF_SZ = 5000 15 | 16 | 17 | def to_tensors(ts): 18 | """Convert a data feed into a tuple of `features` (`dict`) and `y` values 19 | 20 | This method is required to produce `tf.dataset`s from the input data feed. 21 | Any fields ending with `_lengths` are ignored, unless they match the 22 | `src_lengths_key` or `tgt_lengths_key`, in which case, they are converted to `src_len` and `tgt_len` 23 | 24 | :param ts: The data feed to convert 25 | :param lengths_key: This is a field passed from the model params specifying source of truth of the temporal lengths 26 | :return: A `tuple` of `features` and `y` (labels) 27 | """ 28 | keys = ts[0].keys() 29 | # This is kind of a hack 30 | keys = [k for k in keys if k != 'ids'] 31 | 32 | features = dict((k, []) for k in keys) 33 | 34 | for sample in ts: 35 | for k in features.keys(): 36 | for s in sample[k]: 37 | features[k].append(s) 38 | 39 | features = dict((k, np.stack(v).astype(np.int32)) for k, v in features.items()) 40 | tgt = features.pop('y') 41 | return features, tgt 42 | 43 | -------------------------------------------------------------------------------- /baseline/tf/optz.py: -------------------------------------------------------------------------------- 1 | import eight_mile.optz 2 | from eight_mile.optz import * 3 | 4 | __all__ = [] 5 | __all__.extend(eight_mile.optz.__all__) 6 | -------------------------------------------------------------------------------- /baseline/tf/seq2seq/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.seq2seq.model import * 2 | from baseline.tf.seq2seq.train import * 3 | from baseline.tf.seq2seq.encoders import * 4 | from baseline.tf.seq2seq.decoders import * 5 | -------------------------------------------------------------------------------- /baseline/tf/seq2seq/train.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.seq2seq.training import * 2 | -------------------------------------------------------------------------------- /baseline/tf/seq2seq/training/__init__.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from baseline.tf.seq2seq.training.eager import * 3 | from baseline.tf.seq2seq.training.distributed import * 4 | -------------------------------------------------------------------------------- /baseline/tf/seq2seq/training/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | import numpy as np 4 | import tensorflow as tf 5 | from eight_mile.progress import create_progress_bar 6 | from eight_mile.bleu import bleu 7 | 8 | from baseline.utils import ( 9 | convert_seq2seq_golds, 10 | convert_seq2seq_preds, 11 | ) 12 | 13 | from baseline.train import Trainer, register_trainer 14 | from baseline.tf.tfy import TRAIN_FLAG, SET_TRAIN_FLAG 15 | 16 | from baseline.model import create_model_for 17 | 18 | # Number of batches to prefetch if using tf.datasets 19 | NUM_PREFETCH = 2 20 | # The shuffle buffer 21 | SHUF_BUF_SZ = 5000 22 | 23 | 24 | def to_tensors(ts, src_lengths_key, dst=False): 25 | """Convert a data feed into a tuple of `features` (`dict`) and `y` values 26 | 27 | This method is required to produce `tf.dataset`s from the input data feed. 28 | Any fields ending with `_lengths` are ignored, unless they match the 29 | `src_lengths_key` or `tgt_lengths_key`, in which case, they are converted to `src_len` and `tgt_len` 30 | 31 | :param ts: The data feed to convert 32 | :param lengths_key: This is a field passed from the model params specifying source of truth of the temporal lengths 33 | :param dst: `bool` that says if we should prepare a `dst` tensor. This is needed in distributed mode 34 | :return: A `tuple` of `features` and `y` (labels) 35 | """ 36 | keys = ts[0].keys() 37 | # This is kind of a hack 38 | keys = [k for k in keys if '_lengths' not in k and k != 'ids'] + [src_lengths_key, "tgt_lengths"] 39 | 40 | features = dict((k, []) for k in keys) 41 | for sample in ts: 42 | for k in keys: 43 | for s in sample[k]: 44 | features[k].append(s) 45 | features['src_len'] = features[src_lengths_key] 46 | del features[src_lengths_key] 47 | features['tgt_len'] = features['tgt_lengths'] 48 | del features['tgt_lengths'] 49 | features = dict((k, np.stack(v).astype(np.int32)) for k, v in features.items()) 50 | if dst: 51 | features['dst'] = features['tgt'][:, :-1] 52 | tgt = features.pop('tgt') 53 | 54 | return features, tgt 55 | 56 | -------------------------------------------------------------------------------- /baseline/tf/tagger/__init__.py: -------------------------------------------------------------------------------- 1 | from baseline.tf.tagger.model import * 2 | from baseline.tf.tagger.train import * 3 | -------------------------------------------------------------------------------- /baseline/version.py: -------------------------------------------------------------------------------- 1 | __version__ = "2.5.0" 2 | -------------------------------------------------------------------------------- /baseline/w2v.py: -------------------------------------------------------------------------------- 1 | import eight_mile.w2v 2 | from eight_mile.w2v import * 3 | 4 | __all__ = [] 5 | __all__.extend(eight_mile.w2v.__all__) 6 | -------------------------------------------------------------------------------- /docker/Dockerfile.pytorch-cuda10: -------------------------------------------------------------------------------- 1 | FROM meadml/cuda10.1-cudnn7-devel-ubuntu18.04-python3.6 2 | 3 | COPY . /usr/mead/mead-baseline 4 | 5 | WORKDIR /usr/mead 6 | 7 | RUN cd mead-baseline/layers && pip install . 8 | RUN cd mead-baseline && pip install .[test,yaml] 9 | 10 | # Set env variables 11 | # Set baseline logging vars 12 | ENV TIMING_LOG_LEVEL=DEBUG 13 | # Set terminal encodings 14 | ENV LC_ALL=C.UTF-8 15 | ENV LANG=C.UTF-8 16 | # Set ENV to tensorflow can find cuda 17 | ENV PATH=/usr/local/cuda/bin:$PATH 18 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 19 | 20 | # Install pytorch 21 | RUN python3.6 -m pip install torch==1.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html && \ 22 | python3.6 -m pip install torchelastic && \ 23 | python3.6 -m pip install Cython && \ 24 | python3.6 -m pip install fastBPE && \ 25 | python3.6 -m pip install regex && \ 26 | python3.6 -m pip install tfrecord && \ 27 | python3.6 -m pip install tensorboard && \ 28 | python3.6 -m pip install mead-xpctl-client 29 | 30 | ENTRYPOINT ["mead-train", "--config", "config/conll.json"] 31 | 32 | -------------------------------------------------------------------------------- /docker/Dockerfile.pytorch-cuda11: -------------------------------------------------------------------------------- 1 | FROM meadml/cuda11.0-cudnn8-devel-ubuntu18.04-python3.8 2 | 3 | COPY . /usr/mead/mead-baseline 4 | WORKDIR /usr/mead 5 | 6 | RUN cd mead-baseline/layers && pip install --no-use-pep517 . 7 | RUN cd mead-baseline && pip install --no-use-pep517 .[test,yaml] 8 | 9 | # Set env variables 10 | # Set baseline logging vars 11 | ENV TIMING_LOG_LEVEL=DEBUG 12 | # Set terminal encodings 13 | ENV LC_ALL=C.UTF-8 14 | ENV LANG=C.UTF-8 15 | # Set ENV to tensorflow can find cuda 16 | ENV PATH=/usr/local/cuda/bin:$PATH 17 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 18 | 19 | COPY . /usr/mead 20 | 21 | # Install pytorch 22 | 23 | 24 | RUN python3.8 -m pip --no-cache-dir install torch==1.7.1+cu110 -f https://download.pytorch.org/whl/torch_stable.html && \ 25 | python3.8 -m pip install torchelastic && \ 26 | python3.8 -m pip install Cython && \ 27 | python3.8 -m pip install fastBPE && \ 28 | python3.8 -m pip install regex && \ 29 | python3.8 -m pip install tfrecord && \ 30 | python3.8 -m pip install tensorboard && \ 31 | python3.8 -m pip install mead-xpctl-client 32 | 33 | ENTRYPOINT ["mead-train", "--config", "config/conll.json"] 34 | 35 | -------------------------------------------------------------------------------- /docker/Dockerfile.pytorch-cuda111: -------------------------------------------------------------------------------- 1 | FROM meadml/cuda11.1-cudnn8-devel-ubuntu18.04-python3.8 2 | 3 | COPY . /usr/mead/mead-baseline 4 | WORKDIR /usr/mead 5 | 6 | RUN cd mead-baseline/layers && pip install --no-use-pep517 . 7 | RUN cd mead-baseline && pip install --no-use-pep517 .[test,yaml] 8 | 9 | # Set env variables 10 | # Set baseline logging vars 11 | ENV TIMING_LOG_LEVEL=DEBUG 12 | # Set terminal encodings 13 | ENV LC_ALL=C.UTF-8 14 | ENV LANG=C.UTF-8 15 | ENV PATH=/usr/local/cuda/bin:$PATH 16 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 17 | 18 | COPY . /usr/mead 19 | 20 | # Install pytorch 21 | 22 | 23 | RUN python3.8 -m pip --no-cache-dir install torch==1.8.2+cu111 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html && \ 24 | python3.8 -m pip install Cython && \ 25 | python3.8 -m pip install fastBPE && \ 26 | python3.8 -m pip install regex && \ 27 | python3.8 -m pip install tfrecord && \ 28 | python3.8 -m pip install tensorboard && \ 29 | python3.8 -m pip install mead-xpctl-client 30 | 31 | ENTRYPOINT ["mead-train", "--config", "config/conll.json"] 32 | 33 | -------------------------------------------------------------------------------- /docker/Dockerfile.pytorch-cuda111x: -------------------------------------------------------------------------------- 1 | FROM meadml/cuda11.1-cudnn8-devel-ubuntu18.04-python3.8 2 | 3 | COPY . /usr/mead/mead-baseline 4 | WORKDIR /usr/mead 5 | 6 | RUN cd mead-baseline/layers && pip install --no-use-pep517 . 7 | RUN cd mead-baseline && pip install --no-use-pep517 .[test,yaml] 8 | 9 | # Set env variables 10 | # Set baseline logging vars 11 | ENV TIMING_LOG_LEVEL=DEBUG 12 | # Set terminal encodings 13 | ENV LC_ALL=C.UTF-8 14 | ENV LANG=C.UTF-8 15 | ENV PATH=/usr/local/cuda/bin:$PATH 16 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 17 | 18 | COPY . /usr/mead 19 | 20 | # Install pytorch 21 | 22 | 23 | RUN python3.8 -m pip --no-cache-dir install torch==1.8.2+cu111 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html && \ 24 | python3.8 -m pip install Cython && \ 25 | python3.8 -m pip install fastBPE && \ 26 | python3.8 -m pip install regex && \ 27 | python3.8 -m pip install tfrecord && \ 28 | python3.8 -m pip install tensorboard && \ 29 | python3.8 -m pip install mead-xpctl-client && \ 30 | python3.8 -m pip install transformers && \ 31 | python3.8 -m pip install pandas && \ 32 | python3.8 -m pip install sentencepiece 33 | 34 | 35 | ENTRYPOINT ["mead-train", "--config", "config/conll.json"] 36 | 37 | -------------------------------------------------------------------------------- /docker/Dockerfile.pytorch-cuda11x: -------------------------------------------------------------------------------- 1 | FROM meadml/cuda11.0-cudnn8-devel-ubuntu18.04-python3.8 2 | 3 | COPY . /usr/mead/mead-baseline 4 | WORKDIR /usr/mead 5 | 6 | RUN cd mead-baseline/layers && pip install --no-use-pep517 . 7 | RUN cd mead-baseline && pip install --no-use-pep517 .[test,yaml] 8 | 9 | # Set env variables 10 | # Set baseline logging vars 11 | ENV TIMING_LOG_LEVEL=DEBUG 12 | # Set terminal encodings 13 | ENV LC_ALL=C.UTF-8 14 | ENV LANG=C.UTF-8 15 | # Set ENV to tensorflow can find cuda 16 | ENV PATH=/usr/local/cuda/bin:$PATH 17 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 18 | 19 | COPY . /usr/mead 20 | 21 | # Install pytorch 22 | 23 | 24 | RUN python3.8 -m pip --no-cache-dir install torch==1.7.1+cu110 -f https://download.pytorch.org/whl/torch_stable.html && \ 25 | python3.8 -m pip install torchelastic && \ 26 | python3.8 -m pip install Cython && \ 27 | python3.8 -m pip install fastBPE && \ 28 | python3.8 -m pip install regex && \ 29 | python3.8 -m pip install tfrecord && \ 30 | python3.8 -m pip install tensorboard && \ 31 | python3.8 -m pip install mead-xpctl-client && \ 32 | python3.8 -m pip install transformers && \ 33 | python3.8 -m pip install pandas && \ 34 | python3.8 -m pip install sentencepiece 35 | 36 | ENTRYPOINT ["mead-train", "--config", "config/conll.json"] 37 | 38 | -------------------------------------------------------------------------------- /docker/Dockerfile.tf2-cuda10: -------------------------------------------------------------------------------- 1 | # This is built on CUDA 10.1 2 | # everything after 2.2 is Python3 3 | FROM tensorflow/tensorflow:2.2.0-gpu 4 | 5 | COPY . /usr/mead/mead-baseline 6 | 7 | WORKDIR /usr/mead 8 | 9 | RUN cd mead-baseline/layers && pip install . 10 | RUN cd mead-baseline && pip install .[tf2,test,yaml] 11 | 12 | # Set env variables 13 | # Set baseline logging vars 14 | ENV TIMING_LOG_LEVEL=DEBUG 15 | # Set terminal encodings 16 | ENV LC_ALL=C.UTF-8 17 | ENV LANG=C.UTF-8 18 | # Set ENV to tensorflow can find cuda 19 | ENV PATH=/usr/local/cuda/bin:$PATH 20 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 21 | 22 | # Install tensorflow 23 | RUN python -m pip install tensorflow_addons && \ 24 | python -m pip install tensorflow-hub && \ 25 | python -m pip install Cython && \ 26 | python -m pip install fastBPE && \ 27 | python -m pip install mead-xpctl-client 28 | 29 | ENTRYPOINT ["mead-train", "--config", "config/sst2.json"] 30 | 31 | -------------------------------------------------------------------------------- /docker/Dockerfile.tf2-cuda11: -------------------------------------------------------------------------------- 1 | # This is built on CUDA 11 2 | FROM tensorflow/tensorflow:2.4.1-gpu 3 | 4 | COPY . /usr/mead/mead-baseline 5 | 6 | WORKDIR /usr/mead 7 | 8 | RUN cd mead-baseline/layers && pip install . 9 | RUN cd mead-baseline && pip install .[tf2,test,yaml] 10 | 11 | # Set env variables 12 | # Set baseline logging vars 13 | ENV TIMING_LOG_LEVEL=DEBUG 14 | # Set terminal encodings 15 | ENV LC_ALL=C.UTF-8 16 | ENV LANG=C.UTF-8 17 | # Set ENV to tensorflow can find cuda 18 | ENV PATH=/usr/local/cuda/bin:$PATH 19 | ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 20 | 21 | # Install tensorflow 22 | RUN python -m pip install tensorflow_addons && \ 23 | python -m pip install tensorflow-hub && \ 24 | python -m pip install Cython && \ 25 | python -m pip install fastBPE && \ 26 | python -m pip install mead-xpctl-client 27 | 28 | ENTRYPOINT ["mead-train", "--config", "config/sst2.json"] 29 | 30 | -------------------------------------------------------------------------------- /docs/docker.md: -------------------------------------------------------------------------------- 1 | We provide dockerhub builds of mead-baseline for 2 | 3 | - [TensorFlow](https://hub.docker.com/repository/docker/meadml/mead2-tf2-gpu) 4 | - [PyTorch](https://hub.docker.com/repository/docker/meadml/mead2-pytorch-gpu) 5 | 6 | -------------------------------------------------------------------------------- /docs/fw.md: -------------------------------------------------------------------------------- 1 | # Framework Specific Implementation Details 2 | 3 | ## TensorFlow 4 | 5 | ### Dropout and the TRAIN_FLAG() 6 | 7 | 8 | In the TensorFlow backend, we use a global method function `TRAIN_FLAG()` to determine if things like dropout should be applied. If the user is running `mead` to train (which is the typical case), this flag is automatically defined as a boolean that will default `False` (meaning no dropout will be applied). 9 | 10 | We provide a method which allows the user to override the value of the `TRAIN_FLAG()` on demand. 11 | -------------------------------------------------------------------------------- /docs/hpctl.md: -------------------------------------------------------------------------------- 1 | # HPCTL 2 | 3 | A library for training models and doing hyper parameter search. 4 | 5 | More details [here](https://github.com/mead-ml/hpctl) 6 | -------------------------------------------------------------------------------- /docs/logging.md: -------------------------------------------------------------------------------- 1 | # Baseline and Logging 2 | 3 | Baseline, MEAD, and hpctl all use logging extensively. hpctl uses it to collect scores from spawned jobs while baseline and mead use it to give the user information as well as to (more importantly) report scores. 4 | 5 | Default configuration can be found in [logging.json](../python/mead/config/logging.json). 6 | 7 | ## Loggers in Baseline and MEAD 8 | 9 | * `baseline.reporting` 10 | * This is what saves results of a given run. 11 | * This logs to a special `reporting-{pid}.log` 12 | * This logger should always log to the reporting file. It should not be disabled. 13 | * This logs at the `INFO` level 14 | * This outputs JSON messages 15 | * This also includes a console logger to log to stdout. This can be controlled separately from the file logging with the `REPORTING_LOG_LEVEL` environment variable. 16 | * `baseline.timing` This saves how long various parts of the system took. 17 | * This logs to a special `timing-{pid}.log` 18 | * This logs at the `DEBUG` level 19 | * This outputs JSON messages 20 | * This does not log to stdout 21 | * `baseline` This gives user information from baseline 22 | * This has a default config that logs json to console at `INFO` for use of baseline as an API. 23 | * This is overridden when used with a mead driver. 24 | * Mead driver default to having this write to `console`, `info.log` and `error.log` 25 | * Level can be controlled with `BASELINE_LOG_LEVEL` or `LOG_LEVEL` 26 | * These have a default config that is overridden by the mead logging 27 | * `mead` This gives user information from mead 28 | * This has a default config that logs json to console at `INFO` for use of baseline as an API. 29 | * This is overridden when used with a mead driver. 30 | * Mead driver default to having this write to `console`, `info.log` and `error.log` 31 | * Level can be controlled with `MEAD_LOG_LEVEL` or `LOG_LEVEL` 32 | 33 | 34 | ## Common options 35 | 36 | * Suppress logging from MEAD but not baseline `MEAD_LOG_LEVEL=WARNING` 37 | * Suppress logging of information from baseline but not mead `BASELINE_LOG_LEVEL=WARNING` 38 | * Suppress logging from MEAD and baseline but keep the reporting printouts. `MEAD_LOG_LEVEL=WARNING BASELINE_LOG_LEVEL=WARNING` 39 | * Suppress reporting from printing on screen but keep information from MEAD and baseline. `REPORTING_LOG_LEVEL=WARNING` 40 | * Suppress all logging `LOG_LEVEL=WARNING` 41 | -------------------------------------------------------------------------------- /docs/seq2seq.md: -------------------------------------------------------------------------------- 1 | # Seq2Seq 2 | 3 | Encoder-decoder frameworks have been used for Statistical Machine Translation, Image Captioning, ASR, Conversation Modeling, Formula Generation and many other applications. Seq2seq is a type of encoder-decoder implementation, where the encoder is some sort of RNN, and the memories (sometimes known as the "thought vector") are transferred over to the decoder, also an RNN, essentially making this a conditional language model. The code as it is written here is with text in mind, and supports multiple types of RNNs, including GRUs and LSTMs, as well as stacked layer. Global attention is optional. 4 | 5 | ## seq2seq: Phrase in, phrase-out, 2 lookup table implementation, input is a temporal vector, and so is output 6 | 7 | This code implements seq2seq with mini-batching (as in other examples) using adagrad, adadelta, sgd or adam. It supports two vocabularies, and supports word2vec pre-trained models as input, filling in words that are attested in the dataset but not found in the pre-trained models. It uses dropout for regularization. 8 | 9 | For any reasonable size data, this really needs to run on the GPU. 10 | 11 | #### Losses and Reporting 12 | 13 | The loss that is optimized is the total loss divided by the total number of non-masked tokens in the mini-batch (token level loss). 14 | 15 | When reporting the loss every nsteps it is the total loss divided by the total number of non-masked tokens in the last nstep number of mini-batches. The perplexity is e to this loss. 16 | 17 | The epoch loss is the total loss averaged over the total number of non-masked tokens in the whole epoch. The perplexity is e to this loss. 18 | -------------------------------------------------------------------------------- /docs/v2.md: -------------------------------------------------------------------------------- 1 | ## MEAD 2.0 Release 2 | 3 | ### Goals for Version 2 4 | 5 | - Support TF eager completely 6 | - Better support for native Datasets 7 | - For TensorFlow, tf.dataset and still support multi-GPU 8 | - For PyTorch, use DataLoader 9 | - Better a la carte support (providing layers that work outside of mead) 10 | - Underlying layers API that is nearly identical between PyTorch and TF 11 | - Some cases pytorch requires explicit dims and TF no longer does which makes things more clunky than they need to be 12 | - Get rid of python 2, make typing more explicit 13 | - Improved documentation over previous offering 14 | - Simplify by removing `dynet` support and non TF `keras` support 15 | - Simplify services and provide a more straightforward `predict` like functionality with an array 16 | - Updated API examples for accessing layers directly, including large-scale Transformer pre-training code with fine-tuning addons 17 | - Native support for BERT and BPE-based Transformer models in TF and PyTorch with no library dependencies 18 | - Support for [mead-hub](https://github.com/mead-ml/hub), a centralized repository for sharing models, tasks, vectorizers and embeddings 19 | - [ELMo example](https://github.com/mead-ml/hub/blob/master/v1/addons/embed_elmo_tf.py) - by specifying this addon in your [mead config](https://github.com/dpressel/mead-baseline/blob/feature/v2/mead/config/sst2-elmo-eh.json) 20 | 21 | *Note on TensorFlow Eager Mode* 22 | 23 | By default, eager mode is turned off! To turn it on, pass `--prefer-eager true` into `mead-train`. This only works in TF 2.x and recent versions of TF 1.x. In cases where it is not supported, it should degrade gracefully 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /docs/xpctl.md: -------------------------------------------------------------------------------- 1 | ## xpctl 2 | 3 | In [mead](mead.md) we have separate **tasks** such as classify or tagger. Each task can have multiple **experiments**, each corresponding to a separate model or different hyperparameters of the same model. An experiment is uniquely identified by the id. The configuration for an experiment is uniquely identified by hash(_sha1_) of the config file. 4 | 5 | `xpctl` is now part of [mead-ml](https://github.com/mead-ml/xpctl) and can be installed separately from that repository 6 | 7 | -------------------------------------------------------------------------------- /layers/README.md: -------------------------------------------------------------------------------- 1 | # Eight Mile 2 | 3 | [![PyPi Version](https://img.shields.io/pypi/v/mead-layers)](https://pypi.org/project/mead-layers/) [![Actions Status](https://github.com/mead-ml/mead-layers/workflows/Unit%20Test/badge.svg)](https://github.com/mead-ml/mead-layers/actions) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) 4 | 5 | Layers built on PyTorch/TensorFlow for reuse in MEAD framework (or a la carte) 6 | -------------------------------------------------------------------------------- /layers/eight_mile/__init__.py: -------------------------------------------------------------------------------- 1 | from eight_mile.version import __version__ 2 | -------------------------------------------------------------------------------- /layers/eight_mile/calibration/__init__.py: -------------------------------------------------------------------------------- 1 | from eight_mile.calibration.calibration import * 2 | from eight_mile.calibration.metrics import * 3 | try: 4 | from eight_mile.calibration.plot import * 5 | except ImportError: 6 | pass 7 | -------------------------------------------------------------------------------- /layers/eight_mile/calibration/metrics/__init__.py: -------------------------------------------------------------------------------- 1 | from eight_mile.calibration.metrics.calibration_error import expected_calibration_error, maximum_calibration_error 2 | -------------------------------------------------------------------------------- /layers/eight_mile/calibration/metrics/calibration_error.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | __all__ = ["expected_calibration_error", "maximum_calibration_error"] 5 | 6 | 7 | def expected_calibration_error( 8 | bin_mean_acc: np.ndarray, 9 | bin_mean_conf: np.ndarray, 10 | bin_counts: np.ndarray, 11 | ) -> float: 12 | """The difference in expectation between the confidence and the accuracy. 13 | 14 | This is an approximation of eq (2) as described in eq (5) 15 | from https://arxiv.org/abs/1706.04599 16 | 17 | This is the absolute difference between the confidence and accuracy of each 18 | bin weighted by the number of samples in each bin. 19 | 20 | :param bin_mean_acc: `[B]` an array with the accuracy of each bin as elements 21 | :param bin_meanc_conf: `[B]` an array with the mean confidence of each bin as elements 22 | :param bin_counts: `[B]` an array with the number of samples in each bin 23 | 24 | :returns: The ECE between the accuracy and confidence distributions via binning. 25 | """ 26 | abs_differences = np.abs(bin_mean_acc - bin_mean_conf) 27 | coeff = bin_counts / np.sum(bin_counts) 28 | return np.sum(coeff * abs_differences) 29 | 30 | 31 | def maximum_calibration_error( 32 | bin_mean_acc: np.ndarray, 33 | bin_mean_conf: np.ndarray, 34 | bin_counts: np.ndarray, 35 | ) -> float: 36 | """The worst case deviation between confidence and accuracy. 37 | 38 | This is an approximation of eq (4) as described in eq (5) 39 | from https://arxiv.org/abs/1706.04599 40 | 41 | This is the maximum absolute difference between the confidence and accuracy 42 | of each bin. The bin_counts are used to filter out bins that have no samples 43 | in them. This seems like it is very dependent on the number of bins you have 44 | and should therefore be kept constant when comparing models. 45 | 46 | :param bin_mean_acc: 47 | :param bin_mean_conf: 48 | :param bin_counts: 49 | 50 | :returns: The MCE between the accuracy and confidence distributions via binning. 51 | """ 52 | abs_differences = np.abs(bin_mean_acc - bin_mean_conf) 53 | filtered = abs_differences[bin_counts != 0] 54 | return np.max(filtered) 55 | -------------------------------------------------------------------------------- /layers/eight_mile/calibration/plot/__init__.py: -------------------------------------------------------------------------------- 1 | from eight_mile.calibration.plot.confidence_histogram import confidence_histogram 2 | from eight_mile.calibration.plot.reliability_diagram import reliability_diagram, reliability_curve 3 | -------------------------------------------------------------------------------- /layers/eight_mile/pytorch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/layers/eight_mile/pytorch/__init__.py -------------------------------------------------------------------------------- /layers/eight_mile/tf/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/layers/eight_mile/tf/__init__.py -------------------------------------------------------------------------------- /layers/eight_mile/version.py: -------------------------------------------------------------------------------- 1 | __version__ = "2.5.0" 2 | -------------------------------------------------------------------------------- /layers/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ['setuptools', 'wheel'] 3 | 4 | [tool.black] 5 | line-length = 120 6 | target-version = ['py36'] 7 | skip-string-normalization = 'true' 8 | -------------------------------------------------------------------------------- /layers/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | NAME = mead-layers 3 | version = 2.5.0 4 | description = Reusable Deep-Learning layers for NLP 5 | author = dpressel 6 | author_email = dpressel@gmail.com 7 | url = https://www.github.com/dpressel/mead-baseline/layers 8 | 9 | license = Apache 2.0 10 | keywords= 11 | deep-learning 12 | nlp 13 | pytorch 14 | tensorflow 15 | long_description_content_type = text/markdown 16 | long_description = file: README.md 17 | license_files = 18 | ../LICENSE 19 | ../NOTICE 20 | classifiers = 21 | Development Status :: 3 - Alpha 22 | Environment :: Console 23 | Intended Audience :: Developers 24 | Intended Audience :: Science/Research 25 | License :: OSI Approved :: Apache Software License 26 | Natural Language :: English 27 | Operating System :: OS Independent 28 | Programming Language :: Python :: 3.5 29 | Programming Language :: Python :: 3.6 30 | Programming Language :: Python :: 3.7 31 | Programming Language :: Python :: 3.8 32 | Topic :: Scientific/Engineering :: Artificial Intelligence 33 | 34 | [options] 35 | packages = find: 36 | 37 | install_requires = 38 | numpy 39 | six 40 | 41 | [options.entry_points] 42 | console_scripts = 43 | bleu = eight_mile.bleu:main 44 | conlleval = eight_mile.conlleval:main 45 | 46 | [options.extras_require] 47 | test: 48 | pytest 49 | mock 50 | contextdecorator 51 | pytest-forked 52 | yaml: 53 | pyyaml 54 | tf2: 55 | tensorflow_addons 56 | plot: 57 | matplotlib 58 | -------------------------------------------------------------------------------- /layers/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | setup() 3 | -------------------------------------------------------------------------------- /mead/README.md: -------------------------------------------------------------------------------- 1 | See the [docs](../../docs/mead.md) 2 | -------------------------------------------------------------------------------- /mead/__init__.py: -------------------------------------------------------------------------------- 1 | from mead.tasks import * 2 | from mead.utils import * 3 | from mead.exporters import * 4 | from mead.preprocessors import * 5 | 6 | from baseline.utils import get_console_logger 7 | logger = get_console_logger('mead', env_key="MEAD_LOG_LEVEL") 8 | -------------------------------------------------------------------------------- /mead/api_examples/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /mead/api_examples/bio_to_iobes.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | from eight_mile.utils import convert_bio_conll_to_iobes 4 | 5 | def main(): 6 | parser = argparse.ArgumentParser(description='Convert a CONLL file with BIO tagging to IOBES.') 7 | parser.add_argument('--io_dir', help='Input/Output dir', default='../data') 8 | parser.add_argument('--train_file', help='Training file relative name', default='eng.train.bio') 9 | parser.add_argument('--valid_file', help='Validation file relative name', default='eng.testa.bio') 10 | parser.add_argument('--test_file', help='Test file relative name', default='eng.testb.bio') 11 | parser.add_argument('--suffix', help='Suffix to append', default='.iobes') 12 | parser.add_argument("--fields", help="The fields to convert", default=[-1], type=int, nargs="+") 13 | parser.add_argument("--delim", help="delimiter for the fields") 14 | 15 | args = parser.parse_args() 16 | 17 | train_output = args.train_file[:-4] if args.train_file.endswith(".bio") else args.train_file 18 | valid_output = args.valid_file[:-4] if args.valid_file.endswith(".bio") else args.valid_file 19 | test_output = args.test_file[:-4] if args.test_file.endswith(".bio") else args.test_file 20 | 21 | convert_bio_conll_to_iobes( 22 | os.path.join(args.io_dir, args.train_file), os.path.join(args.io_dir, train_output + args.suffix), 23 | fields=args.fields, 24 | delim=args.delim 25 | ) 26 | 27 | convert_bio_conll_to_iobes( 28 | os.path.join(args.io_dir, args.valid_file), os.path.join(args.io_dir, valid_output + args.suffix), 29 | fields=args.fields, 30 | delim=args.delim 31 | ) 32 | 33 | convert_bio_conll_to_iobes( 34 | os.path.join(args.io_dir, args.test_file), os.path.join(args.io_dir, test_output + args.suffix), 35 | fields=args.fields, 36 | delim=args.delim 37 | ) 38 | 39 | 40 | if __name__ == '__main__': 41 | main() 42 | -------------------------------------------------------------------------------- /mead/api_examples/ed_text.py: -------------------------------------------------------------------------------- 1 | import baseline as bl 2 | import argparse 3 | import os 4 | from baseline.utils import str2bool 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser(description='Encoder-Decoder execution') 8 | parser.add_argument('--model', help='An encoder-decoder model', required=True, type=str) 9 | parser.add_argument('--text', help='raw value or a file', type=str) 10 | parser.add_argument('--backend', help='backend', default='pytorch') 11 | parser.add_argument('--remote', help='(optional) remote endpoint', type=str) # localhost:8500 12 | parser.add_argument('--name', help='(optional) signature name', type=str) 13 | parser.add_argument('--target', help='A file to write decoded output (or print to screen)') 14 | parser.add_argument('--tsv', help='print tab separated', type=bl.str2bool, default=False) 15 | parser.add_argument('--batchsz', help='Size of a batch to pass at once', default=32, type=int) 16 | parser.add_argument('--device', help='device') 17 | parser.add_argument('--alpha', type=float, help='If set use in the gnmt length penalty.') 18 | parser.add_argument('--beam', type=int, default=30, help='The size of beam to use.') 19 | 20 | args = parser.parse_known_args()[0] 21 | 22 | batches = [] 23 | if os.path.exists(args.text) and os.path.isfile(args.text): 24 | with open(args.text, 'r') as f: 25 | batch = [] 26 | for line in f: 27 | text = line.strip().split() 28 | if len(batch) == args.batchsz: 29 | batches.append(batch) 30 | batch = [] 31 | batch.append(text) 32 | 33 | if len(batch) > 0: 34 | batches.append(batch) 35 | 36 | else: 37 | batch = [args.text.split()] 38 | batches.append(batch) 39 | 40 | m = bl.EncoderDecoderService.load(args.model, backend=args.backend, beam=args.beam, 41 | remote=args.remote, name=args.name, device=args.device) 42 | 43 | f = open(args.target, 'w') if args.target is not None else None 44 | 45 | for texts in batches: 46 | decoded = m.predict(texts, alpha=args.alpha, beam=args.beam) 47 | for src, dst in zip(texts, decoded): 48 | src_str = ' '.join(src) 49 | dst_str = ' '.join(dst) 50 | if args.tsv: 51 | line = src_str + '\t' + dst_str 52 | else: 53 | line = dst_str 54 | 55 | print(line, file=f, flush=True) 56 | 57 | if f is not None: 58 | f.close() 59 | 60 | 61 | if __name__ == '__main__': 62 | main() 63 | -------------------------------------------------------------------------------- /mead/api_examples/iob_to_bio.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | from eight_mile.utils import convert_iob_conll_to_bio 4 | 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser(description='Convert a CONLL file tagged with IOB to BIO.') 8 | parser.add_argument('--io_dir', help='Input/Output dir', default='../data') 9 | parser.add_argument('--train_file', help='Training file relative name', default='eng.train') 10 | parser.add_argument('--valid_file', help='Validation file relative name', default='eng.testa') 11 | parser.add_argument('--test_file', help='Test file relative name', default='eng.testb') 12 | parser.add_argument('--fields', help="The fields to convert.", default=[-1], type=int, nargs="+") 13 | parser.add_argument('--suffix', help='Suffix to append', default='.bio') 14 | args = parser.parse_args() 15 | 16 | convert_iob_conll_to_bio(os.path.join(args.io_dir, args.train_file), os.path.join(args.io_dir, args.train_file + args.suffix), fields=args.fields) 17 | convert_iob_conll_to_bio(os.path.join(args.io_dir, args.valid_file), os.path.join(args.io_dir, args.valid_file + args.suffix), fields=args.fields) 18 | convert_iob_conll_to_bio(os.path.join(args.io_dir, args.test_file), os.path.join(args.io_dir, args.test_file + args.suffix), fields=args.fields) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /mead/api_examples/iob_to_iobes.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | from eight_mile.utils import convert_iob_conll_to_iobes 4 | 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser(description='Convert a CONLL file tagged with IOB to IOBES.') 8 | parser.add_argument('--io_dir', help='Input/Output dir', default='../data') 9 | parser.add_argument('--train_file', help='Training file relative name', default='eng.train') 10 | parser.add_argument('--valid_file', help='Validation file relative name', default='eng.testa') 11 | parser.add_argument('--test_file', help='Test file relative name', default='eng.testb') 12 | parser.add_argument('--suffix', help='Suffix to append', default='.iobes') 13 | parser.add_argument("--fields", help="The fields to convert", default=[-1], type=int, nargs="+") 14 | args = parser.parse_args() 15 | 16 | 17 | convert_iob_conll_to_iobes(os.path.join(args.io_dir, args.train_file), os.path.join(args.io_dir, args.train_file + args.suffix), fields=args.fields) 18 | convert_iob_conll_to_iobes(os.path.join(args.io_dir, args.valid_file), os.path.join(args.io_dir, args.valid_file + args.suffix), fields=args.fields) 19 | convert_iob_conll_to_iobes(os.path.join(args.io_dir, args.test_file), os.path.join(args.io_dir, args.test_file + args.suffix), fields=args.fields) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /mead/api_examples/iobes_result_to_bio.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from baseline.reader import _norm_ext 3 | from eight_mile.utils import convert_iobes_conll_to_bio 4 | 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser(description="Convert a CONLL file from IOBES to BIO. This defaults to changing the right two most columns and is used to convert the output of IOBES taggers so that conlleval.pl will work on them.") 8 | parser.add_argument("--file", help="The file to convert", default="conllresults.conll") 9 | parser.add_argument("--fields", help="The fields to convert", default=[-2, -1], type=int, nargs="+") 10 | parser.add_argument("--delim", "-d", help="The delimiter between items", default=" ") 11 | parser.add_argument("--suffix", help="Suffix to append", default=".bio", type=_norm_ext) 12 | args = parser.parse_args() 13 | 14 | convert_iobes_conll_to_bio(args.file, args.file + args.suffix, args.fields, args.delim) 15 | 16 | 17 | if __name__ == '__main__': 18 | main() -------------------------------------------------------------------------------- /mead/api_examples/lm_text.py: -------------------------------------------------------------------------------- 1 | import baseline as bl 2 | import argparse 3 | import os 4 | from eight_mile.utils import str2bool 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser(description='Classify text with a model') 8 | parser.add_argument('--model', help='A classifier model', required=True, type=str) 9 | parser.add_argument('--text', help='raw value', type=str) 10 | parser.add_argument('--device', help='device') 11 | parser.add_argument('--backend', help='backend', choices={'tf', 'pytorch'}, default='pytorch') 12 | 13 | 14 | args = parser.parse_known_args()[0] 15 | 16 | if os.path.exists(args.text) and os.path.isfile(args.text): 17 | texts = [] 18 | with open(args.text, 'r') as f: 19 | for line in f: 20 | text = line.strip().split() 21 | texts += [text] 22 | 23 | else: 24 | texts = args.text.split() 25 | 26 | print(texts) 27 | 28 | m = bl.LanguageModelService.load(args.model, device=args.device) 29 | print(m.predict(texts)) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() -------------------------------------------------------------------------------- /mead/api_examples/score_text.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | import baseline as bl 4 | 5 | def main(): 6 | parser = argparse.ArgumentParser(description='Score text with a language model.') 7 | parser.add_argument("--model", help='The path to either the .zip file (or dir) created by training', required=True) 8 | parser.add_argument("--text", help="The text to score as a string, or a path to a file", required=True) 9 | parser.add_argument("--backend", default="tf", help="the dl backend framework the model was trained with", choices=("tensorflow", "tf", "pytorch", "pyt")) 10 | parser.add_argument("--device", help="the device to run the model on") 11 | parser.add_argument("--prob", default="conditional", choices=("joint", "conditional"), help="Should you score the whole string (joint) or the score of the last token given the previous (conditional)") 12 | args = parser.parse_args() 13 | 14 | if os.path.exists(args.text) and os.path.isfile(args.text): 15 | with open(args.text, 'r') as f: 16 | text = [f.read.strip().split()] 17 | else: 18 | text = [args.text.split()] 19 | 20 | if len(text) > 1: 21 | raise ValueError(f"Currently only batch size 1 supported for LanguageModelServices, got {len(text)}") 22 | 23 | m = bl.LanguageModelService.load(args.model, backend=args.backend, device=args.device) 24 | 25 | if args.prob == 'joint': 26 | scores = m.joint(text) 27 | print(f"P({' '.join(text[0])}) = {scores[0]}") 28 | else: 29 | *context, targets = list(zip(*text)) 30 | context = list(zip(*context)) 31 | scores = m.conditional(context, target=targets) 32 | print(f"P({text[0][-1]} | {' '.join(text[0][:-1])}) = {scores[0]}") 33 | 34 | 35 | if __name__ == '__main__': 36 | main() 37 | -------------------------------------------------------------------------------- /mead/clean.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import shutil 4 | import glob 5 | from itertools import chain 6 | 7 | frameworks = ['tf', 'pytorch'] 8 | frameworks = '({})'.format("|".join(frameworks)) 9 | 10 | tasks = ['classify', 'tagger', 'lm', 'seq2seq'] 11 | tasks = '({})'.format("|".join(tasks)) 12 | 13 | pid = r'[0-9]{2,5}' 14 | 15 | pytorch_model = re.compile(r".*\.pyt$") 16 | log = re.compile(r".*\.log$") 17 | tf_model_dir = re.compile(r"tf-{}-{}".format(tasks, pid)) 18 | model_file = re.compile(r"{}-model-{}-{}.*".format(tasks, frameworks, pid)) 19 | checkpoint = re.compile("checkpoint") 20 | conll = re.compile("^conll(-(bio|iobes)-)?results.conll$") 21 | twpos = re.compile("^twposresults.conll$") 22 | 23 | pyc = re.compile(r".*\.pyc$") 24 | pycache = re.compile(r"^.*/__pycache__/.*$") 25 | test_file = re.compile(r"^.*/test_data/.*$") 26 | cm_file = re.compile(r"^.*-cm.csv$") 27 | 28 | res = [ 29 | log, 30 | pytorch_model, 31 | tf_model_dir, 32 | model_file, 33 | checkpoint, 34 | conll, 35 | twpos, 36 | cm_file, 37 | ] 38 | 39 | def delete(file_): 40 | try: 41 | if os.path.isdir(file_): 42 | shutil.rmtree(file_) 43 | else: 44 | os.remove(file_) 45 | except OSError: 46 | pass 47 | 48 | 49 | def main(): 50 | for path, dirs, files in os.walk('.'): 51 | for file_name in chain(files, dirs): 52 | if file_name == "Dockerfile.pyt": 53 | continue 54 | file_ = os.path.join(path, file_name) 55 | # Skip test files 56 | if test_file.match(file_): 57 | continue 58 | # Delete files that are generated by training 59 | if any(r.match(file_name) for r in res): 60 | delete(file_) 61 | # Delete .pyc files not in __pycache__ (created by python 27) 62 | if pyc.match(file_name) and not pycache.match(file_): 63 | delete(file_) 64 | 65 | 66 | if __name__ == "__main__": 67 | main() 68 | -------------------------------------------------------------------------------- /mead/config/ag-news-lstm.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "ag-news", 4 | "batchsz": 100, 5 | "preproc": { 6 | "mxlen": 100, 7 | "clean": true 8 | }, 9 | "features": [ 10 | { 11 | "name": "word", 12 | "vectorizer": { "type": "token1d" }, 13 | "embeddings": { "label": "glove-840B" } 14 | }, 15 | { 16 | "name": "word2", 17 | "vectorizer": { "type": "token1d" }, 18 | "embeddings": { "label": "w2v-gn" } 19 | } 20 | ], 21 | "backend": "tensorflow", 22 | "dataset": "AG", 23 | "loader": { 24 | "reader_type": "default" 25 | }, 26 | "unif": 0.25, 27 | "model": { 28 | "model_type": "lstm", 29 | "rnnsz": 200, 30 | "dropout": 0.5, 31 | "finetune": true 32 | }, 33 | "train": { 34 | "epochs": 10, 35 | "optim": "adadelta", 36 | "eta": 1.0, 37 | "early_stopping_metric": "acc" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mead/config/ag-news-single-lstm.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "ag-news", 4 | "batchsz": 100, 5 | "preproc": { 6 | "mxlen": 100, 7 | "clean": true 8 | }, 9 | "features": [ 10 | { 11 | "name": "word", 12 | "vectorizer": { "type": "token1d" }, 13 | "embeddings": { "label": "glove-840B" } 14 | } 15 | ], 16 | "backend": "tensorflow", 17 | "dataset": "AG", 18 | "loader": { 19 | "reader_type": "default" 20 | }, 21 | "unif": 0.25, 22 | "model": { 23 | "model_type": "lstm", 24 | "rnnsz": 200, 25 | "dropout": 0.5, 26 | "finetune": true 27 | }, 28 | "train": { 29 | "epochs": 10, 30 | "optim": "adadelta", 31 | "eta": 1.0, 32 | "early_stopping_metric": "acc" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mead/config/ag-news.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "ag-news", 4 | "batchsz": 100, 5 | "preproc": { 6 | "mxlen": 100, 7 | "clean": true 8 | }, 9 | "features": [ 10 | { 11 | "name": "word", 12 | "vectorizer": { 13 | "type": "token1d", 14 | "transform": "baseline.lowercase" 15 | }, 16 | "embeddings": { 17 | "label": "w2v-gn" 18 | } 19 | } 20 | ], 21 | "backend": "tensorflow", 22 | "dataset": "AG", 23 | "loader": { 24 | "reader_type": "default" 25 | }, 26 | "unif": 0.25, 27 | "model": { 28 | "model_type": "default", 29 | "filtsz": [3,4,5], 30 | "cmotsz": 200, 31 | "dropout": 0.5, 32 | "finetune": true 33 | }, 34 | "train": { 35 | "epochs": 10, 36 | "optim": "adadelta", 37 | "eta": 1.0, 38 | "early_stopping_metric": "acc" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mead/config/atis-bert-joint-tf.yml: -------------------------------------------------------------------------------- 1 | task: tagger 2 | backend: tensorflow 3 | conll_output: atis-bert.conll 4 | unif: 0.1 5 | dataset: atis-joint-intent 6 | basedir: atis-bert 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | 11 | features: 12 | - name: word 13 | vectorizer: 14 | label: bert-base-uncased-dict1d 15 | embeddings: 16 | type: tlm-words-embed 17 | word_embed_type: learned-positional-w-bias 18 | label: bert-base-uncased-npz 19 | reduction: sum-layer-norm 20 | layer_norms_after: true 21 | finetune: true 22 | mlm: true 23 | loader: 24 | reader_type: joint 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | 30 | model: 31 | model_type: pass-joint 32 | constrain_decode: 0 33 | crf: 0 34 | dropout: 0.65 35 | alpha: 0.5 36 | 37 | train: 38 | trainer_type: joint-trainer 39 | batchsz: 8 40 | epochs: 50 41 | optim: adam 42 | eta: 1.0e-5 43 | patience: 15 44 | early_stopping_metric: tagging_f1 45 | clip: 5.0 46 | span_type: iobes 47 | -------------------------------------------------------------------------------- /mead/config/atis-bert-joint.yml: -------------------------------------------------------------------------------- 1 | task: tagger 2 | backend: pytorch 3 | conll_output: atis-bert.conll 4 | unif: 0.1 5 | dataset: atis-joint-intent 6 | basedir: atis-bert 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | 11 | features: 12 | - name: word 13 | vectorizer: 14 | label: bert-base-uncased-dict1d 15 | embeddings: 16 | type: tlm-words-embed 17 | word_embed_type: learned-positional-w-bias 18 | label: bert-base-uncased-npz 19 | reduction: sum-layer-norm 20 | layer_norms_after: true 21 | finetune: true 22 | mlm: true 23 | loader: 24 | reader_type: joint 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | 30 | model: 31 | model_type: pass-joint 32 | constrain_decode: 0 33 | crf: 1 34 | dropout: 0.65 35 | alpha: 0.5 36 | 37 | train: 38 | trainer_type: joint-trainer 39 | batchsz: 32 40 | epochs: 50 41 | optim: adam 42 | eta: 1.0e-5 43 | patience: 15 44 | early_stopping_metric: tagging_f1 45 | clip: 5.0 46 | span_type: iobes 47 | -------------------------------------------------------------------------------- /mead/config/atis-bert.yml: -------------------------------------------------------------------------------- 1 | task: tagger 2 | backend: pytorch 3 | conll_output: atis-bert.conll 4 | unif: 0.1 5 | dataset: atis 6 | basedir: atis-bert 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | 11 | features: 12 | - name: word 13 | vectorizer: 14 | label: bert-base-uncased-dict1d 15 | embeddings: 16 | type: tlm-words-embed 17 | word_embed_type: learned-positional-w-bias 18 | label: bert-base-uncased-npz 19 | reduction: sum-layer-norm 20 | layer_norms_after: true 21 | finetune: true 22 | mlm: true 23 | loader: 24 | reader_type: default 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | 30 | model: 31 | model_type: pass 32 | constrain_decode: 0 33 | crf: 1 34 | dropout: 0.65 35 | 36 | train: 37 | batchsz: 32 38 | epochs: 50 39 | optim: adam 40 | eta: 1.0e-5 41 | patience: 15 42 | early_stopping_metric: f1 43 | clip: 5.0 44 | span_type: bio 45 | -------------------------------------------------------------------------------- /mead/config/atis-sf.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./atis-sf 3 | batchsz: 10 4 | #batchsz: 50 5 | conll_output: atis.conll 6 | dataset: atis-iobes 7 | features: 8 | - embeddings: 9 | label: 10 | - glove-6B-100 11 | - senna 12 | name: word 13 | vectorizer: 14 | type: dict1d 15 | transform: baseline.lowercase 16 | reader: 17 | type: default 18 | named_fields: 19 | '0': text 20 | '-1': y 21 | model: 22 | constrain_decode: true 23 | crf: 0 24 | dropin: 25 | word: 0.4 26 | dropout: 0.65 27 | hsz: 600 28 | layers: 1 29 | model_type: default 30 | rnntype: blstm 31 | task: tagger 32 | train: 33 | clip: 5.0 34 | early_stopping_metric: f1 35 | epochs: 100 36 | eta: 0.015 37 | mom: 0.9 38 | optim: sgd 39 | #weight_decay: 1e-4 40 | patience: 20 41 | span_type: iobes 42 | unif: 0.1 43 | 44 | -------------------------------------------------------------------------------- /mead/config/conll-bert-hf.yml: -------------------------------------------------------------------------------- 1 | # This configuration file uses the HuggingFace library via mead-hub 2 | # To run it, do `mead-config --config/conll-bert-hf.yml --embeddings hub:v1:embeddings 3 | # 4 | # To see an example of a BERT configuration that does not require mead-hub 5 | # or HuggingFace dependencies, see `config/conll-bert.yml` 6 | task: tagger 7 | backend: pytorch 8 | conll_output: conll-bert-iobes-hf.conll 9 | unif: 0.1 10 | dataset: conll-iobes 11 | 12 | preproc: 13 | mxlen: -1 14 | mxwlen: -1 15 | 16 | features: 17 | - name: word 18 | vectorizer: 19 | label: bert-base-cased-dict1d 20 | embeddings: 21 | label: bert-base-cased-pytorch 22 | layers: [-1] 23 | 24 | loader: 25 | reader_type: default 26 | named_fields: {"0": "text", "-1": "y"} 27 | label_vectorizer: 28 | label: y 29 | type: wordpiece-label-dict1d 30 | 31 | model: 32 | model_type: pass 33 | constrain_decode: 0 34 | crf: 0 35 | 36 | train: 37 | batchsz: 32 38 | epochs: 50 39 | optim: adam 40 | eta: 1.0e-5 41 | patience: 15 42 | early_stopping_metric: f1 43 | clip: 5.0 44 | span_type: iobes 45 | -------------------------------------------------------------------------------- /mead/config/conll-bert.yml: -------------------------------------------------------------------------------- 1 | task: tagger 2 | backend: pytorch 3 | conll_output: conll-bert-iobes.conll 4 | unif: 0.1 5 | dataset: conll-iobes 6 | 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | 11 | features: 12 | - name: word 13 | vectorizer: 14 | label: bert-base-cased-dict1d 15 | embeddings: 16 | type: tlm-words-embed 17 | word_embed_type: learned-positional-w-bias 18 | label: bert-base-cased-npz 19 | reduction: sum-layer-norm 20 | layer_norms_after: true 21 | finetune: true 22 | mlm: true 23 | loader: 24 | reader_type: default 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | 30 | model: 31 | model_type: pass 32 | constrain_decode: 0 33 | crf: 0 34 | 35 | train: 36 | batchsz: 32 37 | epochs: 50 38 | optim: adam 39 | eta: 1.0e-5 40 | patience: 15 41 | early_stopping_metric: f1 42 | clip: 5.0 43 | span_type: iobes 44 | -------------------------------------------------------------------------------- /mead/config/conll-cnn.yml: -------------------------------------------------------------------------------- 1 | # FIXME 2 | task: tagger 3 | batchsz: 128 4 | conll_output: conllresults.conll 5 | charsz: 50 6 | unif: 0.1 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | lower: true 11 | features: 12 | - name: word 13 | vectorizer: 14 | type: dict1d 15 | fields: text 16 | transform: baseline.lowercase 17 | embeddings: 18 | label: glove-6B-100 19 | - name: char 20 | vectorizer: 21 | type: dict2d 22 | embeddings: 23 | dsz: 30 24 | wsz: 30 25 | type: char-conv 26 | backend: tensorflow 27 | dataset: conll-iobes 28 | loader: 29 | reader_type: default 30 | named_fields: 31 | "0": text 32 | "-1": y 33 | model: 34 | model_type: default 35 | wfiltsz: [5] 36 | cfiltsz: [3] 37 | hsz: 800 38 | wsz: 50 39 | dropout: 0.5 40 | rnntype: cnn 41 | layers: 2 42 | crf: 1 43 | constrain_decode: true 44 | activation: relu 45 | train: 46 | epochs: 600 47 | optim: sgd 48 | decay: 0 49 | eta: 0.001 50 | mom: 0.9 51 | patience: 40 52 | early_stopping_metric: f1 53 | clip: 5.0 54 | span_type: iobes 55 | -------------------------------------------------------------------------------- /mead/config/conll-elmo.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | modules: ["hub:v1:addons:embed_elmo_tf"] 3 | task: tagger 4 | batchsz: 10 5 | conll_output: conll-elmo-iobes.conll 6 | unif: 0.1 7 | 8 | preproc: 9 | mxlen: -1 10 | mxwlen: -1 11 | features: 12 | - name: word 13 | vectorizer: 14 | type: dict1d 15 | fields: text 16 | transform: baseline.lowercase 17 | embeddings: 18 | label: glove-6B-100 19 | - name: char 20 | vectorizer: 21 | type: dict2d 22 | embeddings: 23 | dsz: 30 24 | wsz: 30 25 | cfiltsz: [3] 26 | type: char-conv 27 | - name: elmo 28 | vectorizer: 29 | type: dict_elmo 30 | fields: text 31 | embeddings: 32 | label: elmo-large-tf 33 | 34 | backend: tensorflow 35 | dataset: conll-iobes 36 | 37 | loader: 38 | reader_type: default 39 | named_fields: 40 | "0": text 41 | "-1": y 42 | 43 | model: 44 | model_type: default 45 | cfiltsz: [3] 46 | hsz: 256 47 | wsz: 30 48 | dropout: 0.5 49 | #dropin: 50 | # word: 0.1 51 | # elmo: 0.1 52 | rnntype: blstm 53 | layers: 2 54 | constrain_decode: true 55 | crf: 1 56 | 57 | train: 58 | epochs: 50 59 | optim: sgd 60 | eta: 0.015 61 | mom: 0.9 62 | patience: 15 63 | early_stopping_metric: f1 64 | clip: 5.0 65 | span_type: iobes 66 | -------------------------------------------------------------------------------- /mead/config/conll-no-crf.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "batchsz": 10, 4 | "conll_output": "conllresults.conll", 5 | "unif": 0.1, 6 | "features": [ 7 | { 8 | "name": "word", 9 | "vectorizer": { 10 | "type": "dict1d", 11 | "fields": "text", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "glove-6B-100" 16 | } 17 | }, 18 | { 19 | "name": "senna", 20 | "vectorizer": { 21 | "type": "dict1d", 22 | "fields": "text", 23 | "transform": "baseline.lowercase" 24 | }, 25 | "embeddings": { 26 | "label": "senna" 27 | } 28 | }, 29 | { 30 | "name": "char", 31 | "vectorizer": { 32 | "type": "dict2d" 33 | }, 34 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 35 | } 36 | ], 37 | "preproc": { 38 | }, 39 | "backend": "pytorch", 40 | "dataset": "conll-iobes", 41 | "loader": { 42 | "reader_type": "default", 43 | "named_fields": { 44 | "0": "text", 45 | "-1": "y" 46 | } 47 | }, 48 | "model": { 49 | "model_type": "default", 50 | "cfiltsz": [ 51 | 3 52 | ], 53 | "hsz": 400, 54 | "dropout": 0.5, 55 | "rnntype": "blstm", 56 | "layers": 1, 57 | "constrain_decode": true, 58 | "crf": 0 59 | }, 60 | "train": { 61 | "epochs": 100, 62 | "optim": "sgd", 63 | "eta": 0.015, 64 | "mom": 0.9, 65 | "patience": 40, 66 | "early_stopping_metric": "f1", 67 | "clip": 5.0, 68 | "span_type": "iobes" 69 | } 70 | } 71 | 72 | -------------------------------------------------------------------------------- /mead/config/conll-single-tf.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "batchsz": 10, 4 | "conll_output": "conll-iobes-results.conll", 5 | "unif": 0.1, 6 | "preproc": { 7 | }, 8 | "features": [ 9 | { 10 | "name": "word", 11 | "vectorizer": { 12 | "type": "dict1d", 13 | "fields": "text", 14 | "transform": "baseline.lowercase" 15 | }, 16 | "embeddings": { "label": "glove-6B-100" } 17 | }, 18 | { 19 | "name": "char", 20 | "vectorizer": { "type": "dict2d" }, 21 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 22 | } 23 | ], 24 | "backend": "tensorflow", 25 | "dataset": "conll-iobes", 26 | "loader": { 27 | "reader_type": "default", 28 | "named_fields": { 29 | "0": "text", 30 | "-1": "y" 31 | } 32 | }, 33 | "model": { 34 | "model_type": "default", 35 | "hsz": 400, 36 | "dropout": 0.5, 37 | "dropin": {"word": 0.1 }, 38 | "rnntype": "blstm", 39 | "layers": 1, 40 | "constrain_decode": true, 41 | "crf": 1 42 | }, 43 | "train": { 44 | "epochs": 100, 45 | "optim": "sgd", 46 | "eta": 0.015, 47 | "mom": 0.9, 48 | "patience": 40, 49 | "early_stopping_metric": "f1", 50 | "clip": 5.0, 51 | "span_type": "iobes" 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /mead/config/conll-single.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "conll_output": "conll-iobes-results.conll", 4 | "unif": 0.1, 5 | "preproc": { 6 | }, 7 | "features": [ 8 | { 9 | "name": "word", 10 | "vectorizer": { 11 | "type": "dict1d", 12 | "fields": "text", 13 | "transform": "baseline.lowercase" 14 | }, 15 | "embeddings": { "label": "glove-6B-100" } 16 | }, 17 | { 18 | "name": "char", 19 | "vectorizer": { "type": "dict2d" }, 20 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 21 | } 22 | ], 23 | "backend": "pytorch", 24 | "dataset": "conll-iobes", 25 | "loader": { 26 | "reader_type": "default", 27 | "named_fields": { 28 | "0": "text", 29 | "-1": "y" 30 | } 31 | }, 32 | "model": { 33 | "model_type": "default", 34 | "hsz": 400, 35 | "dropout": 0.5, 36 | "dropin": {"word": 0.1 }, 37 | 38 | "rnntype": "blstm", 39 | "layers": 1, 40 | "constrain_decode": true, 41 | "crf": 1 42 | }, 43 | "train": { 44 | "batchsz": 10, 45 | "epochs": 100, 46 | "optim": "sgd", 47 | "eta": 0.015, 48 | "mom": 0.9, 49 | "patience": 40, 50 | "early_stopping_metric": "f1", 51 | "clip": 5.0, 52 | "span_type": "iobes" 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /mead/config/conll-stacked.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "conll_output": "conllresults.conll", 4 | "unif": 0.1, 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "dict1d", 10 | "fields": "text", 11 | "transform": "baseline.lowercase" 12 | }, 13 | "embeddings": { 14 | "labels": ["glove-6B-100", "senna"] 15 | } 16 | }, 17 | { 18 | "name": "char", 19 | "vectorizer": { 20 | "type": "dict2d" 21 | }, 22 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 23 | } 24 | ], 25 | "backend": "pytorch", 26 | "dataset": "conll-iobes", 27 | "reader": { 28 | "type": "default", 29 | "named_fields": { 30 | "0": "text", 31 | "-1": "y" 32 | } 33 | }, 34 | "model": { 35 | "type": "default", 36 | "cfiltsz": [ 37 | 3 38 | ], 39 | "hsz": 400, 40 | "dropout": 0.5, 41 | "dropin": {"word": 0.1,"senna": 0.1}, 42 | "rnntype": "blstm", 43 | "layers": 1, 44 | "constrain_decode": true, 45 | "crf": 1 46 | }, 47 | "train": { 48 | "batchsz": 10, 49 | "epochs": 100, 50 | "optim": "sgd", 51 | "eta": 0.015, 52 | "mom": 0.9, 53 | "patience": 40, 54 | "early_stopping_metric": "f1", 55 | "clip": 5.0, 56 | "span_type": "iobes" 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /mead/config/conll-transformer.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "conll_output": "conllresults.conll", 4 | "unif": 0.1, 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "dict1d", 10 | "fields": "text", 11 | "transform": "baseline.lowercase" 12 | }, 13 | "embeddings": { 14 | "label": "glove-6B-100" 15 | } 16 | }, 17 | { 18 | "name": "senna", 19 | "vectorizer": { 20 | "type": "dict1d", 21 | "fields": "text", 22 | "transform": "baseline.lowercase" 23 | }, 24 | "embeddings": { 25 | "label": "senna" 26 | } 27 | }, 28 | { 29 | "name": "char", 30 | "vectorizer": { 31 | "type": "dict2d" 32 | }, 33 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 34 | } 35 | ], 36 | "backend": "pytorch", 37 | "dataset": "conll-iobes", 38 | "reader": { 39 | "type": "default", 40 | "named_fields": { 41 | "0": "text", 42 | "-1": "y" 43 | } 44 | }, 45 | "model": { 46 | "type": "transformer", 47 | "hsz": 1792, 48 | "num_heads": 14, 49 | "rpr_k": 100, 50 | "dropout": 0.15, 51 | "dropin": {"word": 0.1,"senna": 0.1}, 52 | "layers": 2, 53 | "constrain_decode": true, 54 | "crf": 1 55 | }, 56 | "train": { 57 | "batchsz": 16, 58 | "epochs": 120, 59 | "optim": "sgd", 60 | "eta": 0.0009, 61 | "mom": 0.9, 62 | "patience": 40, 63 | "early_stopping_metric": "f1", 64 | "clip": 5.0, 65 | "span_type": "iobes" 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /mead/config/conll.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "conll_output": "conllresults.conll", 4 | "unif": 0.1, 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "dict1d", 10 | "fields": "text", 11 | "transform": "baseline.lowercase" 12 | }, 13 | "embeddings": { 14 | "label": "glove-6B-100" 15 | } 16 | }, 17 | { 18 | "name": "senna", 19 | "vectorizer": { 20 | "type": "dict1d", 21 | "fields": "text", 22 | "transform": "baseline.lowercase" 23 | }, 24 | "embeddings": { 25 | "label": "senna" 26 | } 27 | }, 28 | { 29 | "name": "char", 30 | "vectorizer": { 31 | "type": "dict2d" 32 | }, 33 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 34 | } 35 | ], 36 | "backend": "pytorch", 37 | "dataset": "conll-iobes", 38 | "reader": { 39 | "type": "default", 40 | "named_fields": { 41 | "0": "text", 42 | "-1": "y" 43 | } 44 | }, 45 | "model": { 46 | "type": "default", 47 | "cfiltsz": [ 48 | 3 49 | ], 50 | "hsz": 400, 51 | "dropout": 0.5, 52 | "dropin": {"word": 0.1,"senna": 0.1}, 53 | "rnntype": "blstm", 54 | "layers": 1, 55 | "constrain_decode": true, 56 | "crf": 1 57 | }, 58 | "train": { 59 | "batchsz": 10, 60 | "epochs": 100, 61 | "optim": "sgd", 62 | "eta": 0.015, 63 | "mom": 0.9, 64 | "patience": 40, 65 | "early_stopping_metric": "f1", 66 | "clip": 5.0, 67 | "span_type": "iobes" 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /mead/config/dbpedia.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "basedir": "dbpedia", 4 | "task": "classify", 5 | "batchsz": 1024, 6 | "features": [{ 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "token1d", 10 | "transform": "baseline.lowercase" 11 | }, 12 | "embeddings": { 13 | "label": "w2v-gn" 14 | } 15 | }], 16 | "preproc": { 17 | "mxlen": 100, 18 | "clean": true 19 | }, 20 | "backend": "tensorflow", 21 | "dataset": "dbpedia", 22 | "loader": { 23 | "reader_type": "default" 24 | }, 25 | "unif": 0.25, 26 | "model": { 27 | "model_type": "default", 28 | "filtsz": [1,2,3,4,5,7], 29 | "cmotsz": 400, 30 | "dropout": 0.5, 31 | "finetune": true 32 | }, 33 | "train": { 34 | "epochs": 80, 35 | "optim": "sgd", 36 | "eta": 0.02, 37 | "early_stopping_metric": "acc", 38 | "verbose": true 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mead/config/deps-pyt.yml: -------------------------------------------------------------------------------- 1 | batchsz: 10 2 | basedir: deps-pyt 3 | task: deps 4 | backend: pytorch 5 | preproc: 6 | # mxlen: 100 7 | clean: true 8 | dataset: deps-sample 9 | 10 | loader: 11 | reader_type: default 12 | named_fields: 13 | "1": text 14 | "6": heads 15 | "7": labels 16 | "-1": y 17 | label_vectorizers: 18 | heads: 19 | emit_begin_tok: 0 20 | type: int-identity-dict1d 21 | fields: heads 22 | # mxlen: 100 23 | labels: 24 | emit_begin_tok: "" 25 | type: dict1d 26 | fields: labels 27 | # mxlen: 100 28 | 29 | 30 | unif: 0.25 31 | model: 32 | model_type: default 33 | dropin: 34 | word: 0.1 35 | 36 | features: 37 | - name: word 38 | vectorizer: 39 | type: dict1d 40 | fields: text 41 | transform: baseline.lowercase 42 | emit_begin_tok: "" 43 | embeddings: 44 | label: [glove-6B-100, senna] 45 | - name: char 46 | vectorizer: 47 | type: dict2d 48 | emit_begin_tok: "" 49 | embeddings: 50 | dsz: 30 51 | wsz: 30 52 | cfiltsz: [3] 53 | type: char-conv 54 | 55 | train: 56 | epochs: 250 57 | optim: adam 58 | patience: 20 59 | #mom: 0.9 60 | eta: 0.002 61 | early_stopping_metric: uas 62 | verbose: 63 | console: True 64 | file: deps-cm.csv 65 | 66 | -------------------------------------------------------------------------------- /mead/config/gn-embed.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "task": "servable_embeddings", 4 | "basedir": "./embeddings", 5 | "features":[ 6 | { 7 | "name": "gn", 8 | "vectorizer": { 9 | "type": "token1d" 10 | }, 11 | "embeddings": { 12 | "label": "w2v-gn" 13 | } 14 | } 15 | ], 16 | "backend": "tensorflow", 17 | "unif": 0.25 18 | } 19 | -------------------------------------------------------------------------------- /mead/config/iwslt15-en-vi-transformer.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 0, 4 | "batchsz": 128, 5 | "basedir": "iwslt15-en-vi-transformer", 6 | "unif": 0.25, 7 | "features": [ 8 | { 9 | "name": "src", 10 | "vectorizer": { "type": "token1d"}, 11 | "embeddings": { "dsz": 512, "type": "positional" } 12 | }, 13 | { 14 | "name": "tgt", 15 | "vectorizer": { "type": "token1d"}, 16 | "embeddings": { "dsz": 512, "type": "positional" } 17 | } 18 | ], 19 | "preproc": { 20 | "mxlen": 50 21 | }, 22 | "backend": "tensorflow", 23 | "dataset": "iwslt15-en-vi", 24 | "loader": { 25 | "reader_type": "default", 26 | "pair_suffix": ["en", "vi"] 27 | }, 28 | 29 | "model": { 30 | "model_type": "default", 31 | "encoder_type": "transformer", 32 | "decoder_type": "transformer", 33 | "hsz": 512, 34 | "dropout": 0.5, 35 | "layers": 2 36 | }, 37 | "train": { 38 | "epochs": 16, 39 | "optim": "adam", 40 | "lr_scheduler_type": "warmup_linear", 41 | "warmup_steps": 800, 42 | "eta": 0.001, 43 | "patience": 20, 44 | "do_early_stopping": false, 45 | "clip": 1.0 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /mead/config/iwslt15-en-vi.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 0, 4 | "basedir": "iwslt15-en-vi-s2s", 5 | "unif": 0.25, 6 | "features": [ 7 | { 8 | "name": "src", 9 | "vectorizer": { "type": "token1d"}, 10 | "embeddings": { "dsz": 512 } 11 | }, 12 | { 13 | "name": "tgt", 14 | "vectorizer": { "type": "token1d"}, 15 | "embeddings": { "dsz": 512 } 16 | } 17 | ], 18 | "preproc": { 19 | "mxlen": 50 20 | }, 21 | "backend": "tensorflow", 22 | "dataset": "iwslt15-en-vi", 23 | "reader": { 24 | "type": "default", 25 | "pair_suffix": ["en", "vi"] 26 | }, 27 | 28 | "model": { 29 | "type": "attn", 30 | "rnntype": "blstm", 31 | "hsz": 512, 32 | "dropout": 0.5, 33 | "layers": 2 34 | }, 35 | "train": { 36 | "batchsz": 100, 37 | "epochs": 32, 38 | "optim": "adam", 39 | "eta": 0.001, 40 | "do_early_stopping": true, 41 | "clip": 1.0 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /mead/config/iwslt15-luong.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 0, 4 | "batchsz": 128, 5 | "basedir": "iwslt15-en-vi-luong", 6 | "unif": 0.1, 7 | "features": [ 8 | { 9 | "name": "src", 10 | "vectorizer": { "type": "token1d"}, 11 | "embeddings": { "dsz": 512 } 12 | }, 13 | { 14 | "name": "tgt", 15 | "vectorizer": { "type": "token1d"}, 16 | "embeddings": { "dsz": 512 } 17 | } 18 | ], 19 | "preproc": { 20 | "mxlen": 50 21 | }, 22 | "backend": "tensorflow", 23 | "dataset": "iwslt15-en-vi", 24 | "loader": { 25 | "reader_type": "default", 26 | "pair_suffix": ["en", "vi"] 27 | }, 28 | "model": { 29 | "model_type": "default", 30 | "rnntype": "blstm", 31 | "hsz": 512, 32 | "dropout": 0.2, 33 | "layers": 2 34 | }, 35 | "train": { 36 | "epochs": 12, 37 | "optim": "sgd", 38 | "start_decay_epoch": 8, 39 | "decay_rate": 2.0, 40 | "decay_type": "zaremba", 41 | "mom": 0.9, 42 | "lr": 1.0, 43 | "do_early_stopping": false, 44 | "clip": 5.0 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /mead/config/mead-settings.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /mead/config/mnli-m-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./mnli-m-bert-base-uncased 3 | batchsz: 32 4 | dataset: mnli-matched 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | token_type_vsz: 2 9 | label: bert-base-uncased-npz 10 | type: tlm-words-embed-pooled 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | name: bert 17 | vectorizer: 18 | mxlen: 225 19 | label: bert-base-uncased-no-cls 20 | loader: 21 | reader_type: tsv-paired-shared-vec 22 | use_token_type: true 23 | col_keys: [pairID, sentence1, sentence2, gold_label] 24 | start_tokens_1: ["[CLS]"] 25 | model: 26 | model_type: fine-tune-paired 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 6 31 | patience: 2 32 | eta: 1.0e-5 33 | optim: adamw 34 | weight_decay: 1.0e-8 35 | unif: 0.1 36 | -------------------------------------------------------------------------------- /mead/config/mp-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "datacache": "~/.bl-data", 3 | "reporting_hooks":{ 4 | "xpctl": { 5 | "cred": "~/xpctlcred.json", 6 | "module": "reporting_xpctl" 7 | } 8 | }, 9 | "hpctl": { 10 | "backend": { 11 | "type": "mp", 12 | "real_gpus": [0] 13 | }, 14 | "logging": { 15 | "host": "localhost", 16 | "port": 6006 17 | }, 18 | "frontend": { 19 | "type": "console", 20 | "train": "avg_loss", 21 | "dev": "acc", 22 | "test": "acc" 23 | }, 24 | "root": "/data/hpctl" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /mead/config/mrda-hier.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "modules": ["hub:v1:addons:da"], 4 | "unif": 0.1, 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "turn-dict2d", 10 | "fields": "text" 11 | }, 12 | "embeddings": { 13 | "label": "glove-840B", 14 | "type": "char-lstm", 15 | "lstmsz": 300 16 | } 17 | } 18 | ], 19 | "backend": "pytorch", 20 | "dataset": "mrda", 21 | "reader": { 22 | "type": "da", 23 | "named_fields": { 24 | "0": "text", 25 | "-1": "y" 26 | } 27 | }, 28 | "model": { 29 | "type": "default", 30 | "hsz": 300, 31 | "dropout": 0.5, 32 | "rnntype": "blstm", 33 | "layers": 1, 34 | "crf": 1 35 | }, 36 | "train": { 37 | "batchsz": 1, 38 | "epochs": 40, 39 | "optim": "adadelta", 40 | "eta": 1.0, 41 | "grad_accum": 10, 42 | "patience": 20, 43 | "early_stopping_metric": "f1", 44 | "clip": 5.0 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /mead/config/mrda.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "modules": ["hub:v1:addons:da"], 4 | "unif": 0.1, 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "turn-dict2d", 10 | "fields": "text" 11 | }, 12 | "embeddings": { 13 | "label": "glove-840B", 14 | "type": "char-conv", 15 | "cfiltsz": [3,4,5], 16 | "wsz": 100 17 | } 18 | } 19 | ], 20 | "backend": "pytorch", 21 | "dataset": "mrda", 22 | "reader": { 23 | "type": "da", 24 | "named_fields": { 25 | "0": "text", 26 | "-1": "y" 27 | } 28 | }, 29 | "model": { 30 | "type": "default", 31 | "hsz": 300, 32 | "dropout": 0.5, 33 | "rnntype": "blstm", 34 | "layers": 1, 35 | "crf": 1 36 | }, 37 | "train": { 38 | "batchsz": 1, 39 | "epochs": 40, 40 | "optim": "adam", 41 | "eta": 0.0008, 42 | "grad_accum": 10, 43 | "patience": 20, 44 | "early_stopping_metric": "f1", 45 | "clip": 5.0 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /mead/config/mrpc-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | # 89.2 average of F1/acc @ epoch 7 on a single run 2 | backend: pytorch 3 | basedir: ./mrpc-bert-base-uncased 4 | batchsz: 16 5 | dataset: mrpc 6 | features: 7 | - embeddings: 8 | word_embed_type: learned-positional 9 | token_type_vsz: 2 10 | label: bert-base-uncased-npz 11 | type: tlm-words-embed-pooled 12 | reduction: sum-layer-norm 13 | layer_norms_after: true 14 | finetune: true 15 | dropout: 0.1 16 | mlm: true 17 | name: bert 18 | vectorizer: 19 | mxlen: 128 20 | label: bert-base-uncased-no-cls 21 | loader: 22 | reader_type: tsv-paired-shared-vec 23 | use_token_type: true 24 | col_keys: ["#1 ID", "#1 String", "#2 String", "Quality"] 25 | start_tokens_1: ["[CLS]"] 26 | model: 27 | model_type: fine-tune-paired 28 | task: classify 29 | train: 30 | early_stopping_metric: avg_f1_acc 31 | epochs: 10 32 | warmup_steps: 70 33 | eta: 5.0e-5 34 | optim: adamw 35 | weight_decay: 1.0e-8 36 | lr_scheduler_type: [warmup_linear, cosine] 37 | decay_steps: 2300 38 | unif: 0.1 39 | -------------------------------------------------------------------------------- /mead/config/ontonotes-bert.yml: -------------------------------------------------------------------------------- 1 | task: tagger 2 | backend: pytorch 3 | conll_output: ontonotes-bert-iobes.conll 4 | unif: 0.1 5 | dataset: ontonotes 6 | 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | 11 | features: 12 | - name: word 13 | vectorizer: 14 | label: bert-base-cased-dict1d 15 | embeddings: 16 | type: tlm-words-embed 17 | word_embed_type: learned-positional-w-bias 18 | label: bert-base-cased-npz 19 | reduction: sum-layer-norm 20 | layer_norms_after: true 21 | finetune: true 22 | mlm: true 23 | loader: 24 | reader_type: default 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | 30 | model: 31 | model_type: pass 32 | constrain_decode: 0 33 | crf: 0 34 | 35 | train: 36 | batchsz: 32 37 | epochs: 50 38 | optim: adam 39 | eta: 1.0e-5 40 | patience: 15 41 | early_stopping_metric: f1 42 | clip: 5.0 43 | span_type: iobes 44 | -------------------------------------------------------------------------------- /mead/config/ontonotes.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "batchsz": 9, 4 | "conll_output": "ontonotes-results.conll", 5 | "unif": 0.1, 6 | "features": [ 7 | { 8 | "name": "word", 9 | "vectorizer": { 10 | "type": "dict1d", 11 | "fields": "text", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "glove-6B-100" 16 | } 17 | }, 18 | { 19 | "name": "senna", 20 | "vectorizer": { 21 | "type": "dict1d", 22 | "fields": "text", 23 | "transform": "baseline.lowercase" 24 | }, 25 | "embeddings": { 26 | "label": "senna" 27 | } 28 | }, 29 | { 30 | "name": "char", 31 | "vectorizer": { 32 | "type": "dict2d" 33 | }, 34 | "embeddings": { "dsz": 30, "wsz": 20, "type": "char-conv" } 35 | } 36 | ], 37 | "preproc": { 38 | }, 39 | "backend": "pytorch", 40 | "dataset": "ontonotes", 41 | "loader": { 42 | "reader_type": "default", 43 | "named_fields": { 44 | "0": "text", 45 | "-1": "y" 46 | } 47 | }, 48 | "model": { 49 | "model_type": "default", 50 | "cfiltsz": [ 51 | 3 52 | ], 53 | "hsz": 400, 54 | "dropout": 0.63, 55 | "dropin": {"word": 0.1,"senna": 0.1}, 56 | "rnntype": "blstm", 57 | "layers": 2, 58 | "constrain_decode": true, 59 | "crf": 1 60 | }, 61 | "train": { 62 | "epochs": 100, 63 | "optim": "sgd", 64 | "eta": 0.008, 65 | "mom": 0.9, 66 | "patience": 40, 67 | "early_stopping_metric": "f1", 68 | "clip": 5.0, 69 | "span_type": "iobes" 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /mead/config/ptb-350-deps-pyt.yml: -------------------------------------------------------------------------------- 1 | batchsz: 200 2 | basedir: ptb-350-deps-pyt 3 | task: deps 4 | backend: pytorch 5 | preproc: {} 6 | 7 | dataset: ptb-350-deps 8 | loader: 9 | reader_type: default 10 | named_fields: 11 | "1": text 12 | "3": pos 13 | "6": heads 14 | "7": labels 15 | "-1": y 16 | label_vectorizers: 17 | heads: 18 | emit_begin_tok: 0 19 | type: int-identity-dict1d 20 | fields: heads 21 | labels: 22 | emit_begin_tok: "" 23 | type: dict1d 24 | fields: labels 25 | 26 | 27 | unif: 0.25 28 | model: 29 | model_type: default 30 | 31 | features: 32 | - name: word 33 | vectorizer: 34 | type: dict1d 35 | fields: text 36 | transform: baseline.lowercase 37 | emit_begin_tok: "" 38 | embeddings: 39 | label: [glove-6B-100] 40 | dropin: 0.1 41 | - name: word2 42 | vectorizer: 43 | type: dict1d 44 | fields: text 45 | emit_begin_tok: "" 46 | embeddings: 47 | label: [senna] 48 | dropin: 0.1 49 | - name: pos 50 | vectorizer: 51 | type: dict1d 52 | fields: pos 53 | dropin: 0.1 54 | emit_begin_tok: "" 55 | embeddings: 56 | dsz: 100 57 | - name: char 58 | vectorizer: 59 | type: dict2d 60 | emit_begin_tok: "" 61 | embeddings: 62 | dsz: 50 63 | wsz: 50 64 | type: char-conv 65 | 66 | train: 67 | epochs: 265 68 | optim: adam 69 | patience: 40 70 | beta2: 0.9 71 | decay_rate: 0.75 72 | decay_steps: 50000 73 | lr_scheduler_type: exponential 74 | eta: 0.002 75 | early_stopping_metric: uas 76 | 77 | -------------------------------------------------------------------------------- /mead/config/ptb-kim-adam.yml: -------------------------------------------------------------------------------- 1 | basedir: ptb-med 2 | task: lm 3 | backend: tensorflow 4 | dataset: ptb 5 | unif: 0.05 6 | preproc: 7 | mxwlen: 50 8 | features: 9 | - name: x 10 | vectorizer: 11 | type: token1d 12 | embeddings: 13 | dsz: 512 14 | 15 | - name: xch 16 | vectorizer: 17 | type: char2d 18 | mxwlen: 50 19 | embeddings: 20 | dsz: 16 21 | type: "char-conv" 22 | filtsz: 23 | - [1, 32] 24 | - [2, 32] 25 | - [3, 64] 26 | - [4, 128] 27 | - [5, 256] 28 | - [6, 512] 29 | - [7, 1024] 30 | gating: highway 31 | num_gates: 2 32 | cmotsz: 30 33 | 34 | reader: 35 | reader_type: default 36 | tgt_key: x 37 | src_keys: xch 38 | nbptt: 35 39 | 40 | model: 41 | model_type: default 42 | hsz: 512 43 | skip_conn: 1 44 | projsz: 512 45 | layers: 1 46 | pdrop: 0.5 47 | 48 | train: 49 | epochs: 25 50 | optim: adam 51 | eta: 0.001 52 | nsteps: 100 53 | clip: 1.0 54 | batchsz: 20 55 | 56 | -------------------------------------------------------------------------------- /mead/config/ptb-med.json: -------------------------------------------------------------------------------- 1 | { 2 | "basedir":"ptb-med", 3 | "task": "lm", 4 | "batchsz": 20, 5 | "unif": 0.05, 6 | "nbptt": 35, 7 | "preproc": { 8 | }, 9 | "features": [ 10 | { 11 | "name": "word", 12 | "vectorizer": { 13 | "type":"token1d", 14 | "fields":"text" 15 | }, 16 | "embeddings": {"dsz": 650, "dropin": 0.0} 17 | } 18 | ], 19 | "backend": "tensorflow", 20 | "dataset": "ptb", 21 | "loader": { 22 | "reader_type": "default", 23 | "tgt_key": "word" 24 | }, 25 | "model": { 26 | "model_type": "default", 27 | "hsz": 650, 28 | "layers": 2, 29 | "variational": false, 30 | "tie_weights": true, 31 | "pdrop": 0.5 32 | }, 33 | "train": { 34 | "epochs": 39, 35 | "decay_rate": 1.2, 36 | "patience": 20, 37 | "optim": "sgd", 38 | "start_decay_epoch": 15, 39 | "lr_scheduler_type": "zaremba", 40 | "eta": 35.0, 41 | "mom": 0.0, 42 | "nsteps": 500, 43 | "do_early_stopping": true, 44 | "clip": 0.25 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /mead/config/ptb-small-tf.json: -------------------------------------------------------------------------------- 1 | { 2 | "basedir": "ptb-small", 3 | "task": "lm", 4 | "batchsz": 20, 5 | "unif": 0.1, 6 | "nbptt": 20, 7 | "charsz": 16, 8 | "preproc": { 9 | "mxwlen": 40, 10 | "lower": true 11 | }, 12 | "backend": "tensorflow", 13 | "dataset": "ptb", 14 | "loader": { 15 | "reader_type": "default", 16 | "tgt_key": "word" 17 | }, 18 | "features": [{ 19 | "name": "word", 20 | "vectorizer": { 21 | "type": "token1d", 22 | "fields": "text" 23 | }, 24 | "embeddings": { "label": "w2v-gn" } 25 | }], 26 | "model": { 27 | "model_type": "default", 28 | "tie_weights": "true", 29 | "hsz": 300, 30 | "dropout": 0.5, 31 | "layers": 2 32 | }, 33 | "train": { 34 | "epochs": 13, 35 | "optim": "sgd", 36 | "eta": 20.0, 37 | "mom": 0.0, 38 | "do_early_stopping": true, 39 | "clip": 0.25 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mead/config/ptb-transformer.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "lm", 3 | "basedir": "ptb-transformer", 4 | "batchsz": 20, 5 | "unif": 0.1, 6 | "nctx": 256, 7 | "preproc": { 8 | }, 9 | "backend": "pytorch", 10 | "dataset": "ptb", 11 | "loader": { 12 | "reader_type": "default", 13 | "tgt_key": "word" 14 | }, 15 | "features": [ 16 | { 17 | "name": "word", 18 | "vectorizer": { 19 | "type": "token1d", 20 | "fields": "text" 21 | }, 22 | "embeddings": {"dsz": 512, "type": "positional", "dropin": 0.2} 23 | 24 | } 25 | 26 | ], 27 | "model": { 28 | "model_type": "transformer", 29 | "hsz": 512, 30 | "layers": 3, 31 | "pdrop": 0.5 32 | }, 33 | "train": { 34 | "epochs": 40, 35 | "optim": "adamw", 36 | "weight_decay": 1.0e-4, 37 | "eta": 4.0e-4, 38 | "do_early_stopping": true, 39 | "clip": 1.0 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /mead/config/qnli-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./qnli-bert-base-uncased 3 | batchsz: 32 4 | dataset: qnli 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | token_type_vsz: 2 9 | label: bert-base-uncased-npz 10 | type: tlm-words-embed-pooled 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | name: bert 17 | vectorizer: 18 | mxlen: 200 19 | label: bert-base-uncased-no-cls 20 | loader: 21 | reader_type: tsv-paired-shared-vec 22 | use_token_type: true 23 | col_keys: [index, question, sentence, label] 24 | start_tokens_1: ["[CLS]"] 25 | model: 26 | model_type: fine-tune-paired 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 3 31 | patience: 6 32 | eta: 1.0e-5 33 | optim: adamw 34 | weight_decay: 1.0e-8 35 | unif: 0.1 36 | -------------------------------------------------------------------------------- /mead/config/qqp-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./qqp-bert-base-uncased 3 | batchsz: 32 4 | dataset: qqp 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | token_type_vsz: 2 9 | label: bert-base-uncased-npz 10 | type: tlm-words-embed-pooled 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | name: bert 17 | vectorizer: 18 | mxlen: 150 19 | label: bert-base-uncased-no-cls 20 | loader: 21 | reader_type: tsv-paired-shared-vec 22 | use_token_type: true 23 | col_keys: [id, question1, question2, is_duplicate] 24 | start_tokens_1: ["[CLS]"] 25 | model: 26 | model_type: fine-tune-paired 27 | task: classify 28 | train: 29 | early_stopping_metric: avg_f1_acc 30 | epochs: 6 31 | patience: 2 32 | eta: 1.0e-5 33 | optim: adamw 34 | weight_decay: 1.0e-8 35 | unif: 0.1 36 | -------------------------------------------------------------------------------- /mead/config/remote-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "datacache": "~/.bl-data", 3 | "reporting_hooks":{ 4 | "visdom": { 5 | "name": "ZZZZZZZZZZZZ" 6 | }, 7 | "xpctl": { 8 | "cred": "~/xpctlcred.json.mongo" 9 | } 10 | }, 11 | "hpctl": { 12 | "backend": { 13 | "type": "remote", 14 | "host": "localhost", 15 | "port": 5000 16 | }, 17 | "logging": { 18 | "host": "localhost", 19 | "port": 6006 20 | }, 21 | "frontend": { 22 | "type": "console", 23 | "train": "avg_loss", 24 | "dev": "f1", 25 | "test": "f1" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mead/config/reverse-transformer.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 1, 4 | "batchsz": 128, 5 | "basedir": "s2s_reverse", 6 | "test_batchsz": 16, 7 | "unif": 0.25, 8 | "features": [ 9 | { 10 | "name": "src", 11 | "vectorizer": { "type": "token1d"}, 12 | "embeddings": { "dsz": 128, "type": "positional" } 13 | }, 14 | { 15 | "name": "tgt", 16 | "vectorizer": { "type": "token1d"}, 17 | "embeddings": { "dsz": 128, "type": "positional" } 18 | } 19 | ], 20 | "preproc": { 21 | "mxlen": 10 22 | }, 23 | "backend": "tensorflow", 24 | "dataset": "reverse", 25 | "loader": { 26 | "reader_type": "default", 27 | "pair_suffix": ["fwd", "bwd"] 28 | }, 29 | "model": { 30 | "encoder_type": "transformer", 31 | "decoder_type": "transformer", 32 | "hsz": 128, 33 | "dropout": 0.1, 34 | "layers": 4 35 | }, 36 | "train": { 37 | "epochs": 64, 38 | "optim": "adam", 39 | "eta": 0.001, 40 | "patience": 40, 41 | "nsteps": 200, 42 | "do_early_stopping": true, 43 | "clip": 1.0 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mead/config/reverse.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 1, 4 | "batchsz": 32, 5 | "basedir": "s2s_reverse", 6 | "test_batchsz": 16, 7 | "unif": 0.25, 8 | "features": [ 9 | { 10 | "name": "src", 11 | "vectorizer": { "type": "token1d"}, 12 | "embeddings": { "dsz": 32 } 13 | }, 14 | { 15 | "name": "tgt", 16 | "vectorizer": { "type": "token1d"}, 17 | "embeddings": { "dsz": 32 } 18 | } 19 | ], 20 | "preproc": { 21 | "mxlen": 10 22 | }, 23 | "backend": "pytorch", 24 | "dataset": "reverse", 25 | "loader": { 26 | "reader_type": "default", 27 | "pair_suffix": ["fwd", "bwd"] 28 | }, 29 | "model": { 30 | "model_type": "attn", 31 | "rnntype": "blstm", 32 | "hsz": 64, 33 | "dropout": 0.5, 34 | "attn_type": "concat", 35 | "tie_weights": false, 36 | "layers": 2 37 | }, 38 | "train": { 39 | "epochs": 30, 40 | "optim": "adam", 41 | "eta": 0.001, 42 | "mom": 0.9, 43 | "patience": 10, 44 | "nsteps": 200, 45 | "do_early_stopping": true, 46 | "early_stopping_metric": "bleu", 47 | "clip": 1.0 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mead/config/rte-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | # Single run, 67.5 dev, epoch 10 2 | backend: pytorch 3 | basedir: ./rte-bert-base-uncased 4 | batchsz: 16 5 | dataset: rte 6 | features: 7 | - embeddings: 8 | word_embed_type: learned-positional 9 | token_type_vsz: 2 # For BERT, we want to add a token_type feature, its size 2 10 | label: bert-base-uncased-npz 11 | type: tlm-words-embed-pooled 12 | reduction: sum-layer-norm 13 | layer_norms_after: true 14 | finetune: true 15 | dropout: 0.1 16 | mlm: true 17 | name: bert 18 | vectorizer: 19 | mxlen: 512 20 | label: bert-base-uncased-no-cls 21 | loader: 22 | reader_type: tsv-paired-shared-vec 23 | use_token_type: true # By default, our vectorizer wont emit this feature, turn it on for BERT 24 | col_keys: [index, sentence1, sentence2, label] 25 | start_tokens_1: ["[CLS]"] 26 | model: 27 | model_type: fine-tune-paired 28 | task: classify 29 | train: 30 | early_stopping_metric: acc 31 | epochs: 20 32 | warmup_steps: 16 33 | patience: 5 34 | eta: 5.0e-5 35 | optim: adamw 36 | weight_decay: 1.0e-8 37 | lr_scheduler_type: warmup_linear 38 | #lr_scheduler_type: [warmup_linear, cosine] 39 | #decay_steps: 156*3 40 | unif: 0.1 41 | -------------------------------------------------------------------------------- /mead/config/snips-intent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "modules": ["reader_parallel_classify"], 4 | "task": "classify", 5 | "basedir": "./snips-intent", 6 | "batchsz": 50, 7 | "features": [ 8 | { 9 | "name": "word", 10 | "vectorizer": { 11 | "type": "token1d", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "w2v-gn" 16 | } 17 | } 18 | ], 19 | "preproc": { 20 | "rev": false 21 | }, 22 | "backend": "tensorflow", 23 | "dataset": "snips", 24 | "loader": { 25 | "reader_type": "parallel" 26 | }, 27 | "unif": 0.25, 28 | "model": { 29 | "model_type": "default", 30 | "filtsz": [ 31 | 3, 32 | 4, 33 | 5 34 | ], 35 | "cmotsz": 100, 36 | "dropout": 0.5, 37 | "finetune": true 38 | }, 39 | "train": { 40 | "epochs": 2, 41 | "optim": "adadelta", 42 | "eta": 1.0, 43 | "model_zip": true, 44 | "early_stopping_metric": "acc", 45 | "verbose": { 46 | "console": true, 47 | "file": "sst2-cm.csv" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mead/config/snips.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "batchsz": 10, 4 | "conll_output": "snips.conll", 5 | "basedir": "./snips-sf", 6 | "unif": 0.1, 7 | "features": [ 8 | { 9 | "name": "word", 10 | "vectorizer": { 11 | "type": "dict1d", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "glove-6B-100" 16 | } 17 | }, 18 | { 19 | "name": "senna", 20 | "vectorizer": { 21 | "type": "dict1d", 22 | "transform": "baseline.lowercase" 23 | }, 24 | "embeddings": { 25 | "label": "senna" 26 | } 27 | }, 28 | { 29 | "name": "char", 30 | "vectorizer": { 31 | "type": "dict2d" 32 | }, 33 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 34 | } 35 | ], 36 | "preproc": { 37 | }, 38 | "dataset": "snips-conll", 39 | "reader": { 40 | "type": "default", 41 | "named_fields": { 42 | "0": "text", 43 | "-1": "y" 44 | } 45 | }, 46 | "model": { 47 | "model_type": "default", 48 | "cfiltsz": [ 49 | 3 50 | ], 51 | "hsz": 400, 52 | "dropout": 0.5, 53 | "dropin": {"word": 0.1,"senna": 0.1}, 54 | "rnntype": "blstm", 55 | "layers": 1, 56 | "constrain_decode": true, 57 | "crf": 1 58 | }, 59 | "train": { 60 | "epochs": 100, 61 | "optim": "sgd", 62 | "eta": 0.015, 63 | "mom": 0.9, 64 | "patience": 40, 65 | "early_stopping_metric": "f1", 66 | "clip": 5.0, 67 | "span_type": "iobes" 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /mead/config/snli-bert-base-cased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./snli-bert-base-cased 3 | batchsz: 8 4 | dataset: snli1 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | token_type_vsz: 2 9 | label: bert-base-cased-npz 10 | type: tlm-words-embed-pooled 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | name: bert 17 | vectorizer: 18 | mxlen: 400 19 | label: bert-base-cased-no-cls 20 | loader: 21 | reader_type: tsv-paired-shared-vec 22 | use_token_type: true 23 | col_keys: [pairID, sentence1, sentence2, gold_label] 24 | start_tokens_1: ["[CLS]"] 25 | model: 26 | model_type: fine-tune-paired 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 3 31 | patience: 6 32 | eta: 1.0e-5 33 | optim: adamw 34 | weight_decay: 1.0e-8 35 | unif: 0.1 36 | -------------------------------------------------------------------------------- /mead/config/snli-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./snli-bert-base-uncased 3 | batchsz: 8 4 | dataset: snli1 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | token_type_vsz: 2 9 | label: bert-base-uncased-npz 10 | type: tlm-words-embed-pooled 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | name: bert 17 | vectorizer: 18 | mxlen: 400 19 | label: bert-base-uncased-no-cls 20 | loader: 21 | reader_type: tsv-paired-shared-vec 22 | use_token_type: true 23 | col_keys: [pairID, sentence1, sentence2, gold_label] 24 | start_tokens_1: ["[CLS]"] 25 | model: 26 | model_type: fine-tune-paired 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 3 31 | patience: 6 32 | eta: 1.0e-5 33 | optim: adamw 34 | weight_decay: 1.0e-8 35 | unif: 0.1 36 | -------------------------------------------------------------------------------- /mead/config/snli-sbert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./snli-bert-base-uncased 3 | batchsz: 8 4 | dataset: snli1 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional-w-bias 8 | label: bert-base-uncased-npz 9 | type: tlm-words-embed-pooled 10 | pooling: mean 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | 17 | name: x 18 | vectorizer: 19 | mxlen: 128 20 | label: bert-base-uncased 21 | loader: 22 | reader_type: tsv-paired-shared-vec 23 | use_token_type: true 24 | col_keys: [pairID, sentence1, sentence2, gold_label] 25 | example_type: dual 26 | model: 27 | model_type: fine-tune-dual 28 | task: classify 29 | train: 30 | early_stopping_metric: acc 31 | epochs: 3 32 | patience: 6 33 | eta: 1.0e-5 34 | optim: adamw 35 | weight_decay: 1.0e-8 36 | unif: 0.1 37 | -------------------------------------------------------------------------------- /mead/config/sst2-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./sst2-bert-base-uncased 3 | batchsz: 32 4 | dataset: SST2 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional-w-bias 8 | label: bert-base-uncased-npz 9 | type: tlm-words-embed-pooled 10 | reduction: sum-layer-norm 11 | layer_norms_after: true 12 | finetune: true 13 | dropout: 0.1 14 | mlm: true 15 | name: bert 16 | vectorizer: 17 | label: bert-base-uncased 18 | loader: 19 | reader_type: default 20 | model: 21 | model_type: fine-tune 22 | task: classify 23 | train: 24 | early_stopping_metric: acc 25 | epochs: 20 26 | eta: 1.0e-5 27 | optim: adamw 28 | weight_decay: 1.0e-5 29 | lr_scheduler_type: cosine 30 | decay_steps: 48100 31 | unif: 0.1 32 | -------------------------------------------------------------------------------- /mead/config/sst2-bert-hf-base-uncased.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "./sst2", 4 | "batchsz": 10, 5 | "features": [ 6 | { 7 | "name": "bert", 8 | "vectorizer": { 9 | "label": "bert-base-uncased" 10 | }, 11 | "embeddings": { 12 | "type": "bert-pooled", 13 | "label": "bert-base-uncased-pooled-pytorch" 14 | } 15 | } 16 | ], 17 | "preproc": { 18 | "mxlen": 100 19 | }, 20 | "backend": "pytorch", 21 | "dataset": "SST2", 22 | "loader": { 23 | "reader_type": "default" 24 | }, 25 | "unif": 0.25, 26 | "model": { 27 | "model_type": "fine-tune" 28 | }, 29 | "train": { 30 | "epochs": 5, 31 | "optim": "adamw", 32 | "eta": 0.00001, 33 | "weight_decay": 1.0e-8, 34 | "early_stopping_metric": "acc", 35 | "verbose": { 36 | "console": true, 37 | "file": "sst2-cm.csv" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mead/config/sst2-bert-official-base-uncased.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "./sst2-bert", 4 | "batchsz": 12, 5 | "features": [ 6 | { 7 | "name": "bert", 8 | "vectorizer": { 9 | "label": "bert-base-uncased", 10 | "dtype": "int32" 11 | }, 12 | "embeddings": { 13 | "label": "bert-base-uncased-pooled-tf" 14 | } 15 | } 16 | ], 17 | "preproc": { 18 | "mxlen": 100 19 | }, 20 | "backend": "tensorflow", 21 | "dataset": "SST2", 22 | "loader": { 23 | "reader_type": "default" 24 | }, 25 | "unif": 0.25, 26 | "model": { 27 | "model_type": "fine-tune" 28 | }, 29 | "train": { 30 | "epochs": 2, 31 | "optim": "adam", 32 | "eta": 4.0e-5, 33 | "early_stopping_metric": "acc", 34 | "verbose": { 35 | "console": true, 36 | "file": "sst2-cm.csv" 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mead/config/sst2-demolib.yml: -------------------------------------------------------------------------------- 1 | # To pass in a slack reporting hook, pass in 2 | # --reporting slack --slack:webhook 3 | modules: 4 | - hub:v1:addons:demolib 5 | batchsz: 50 6 | basedir: demolib 7 | dataset: SST2 8 | preproc: 9 | clean: true 10 | loader: 11 | reader_type: default 12 | unif: 0.25 13 | model: 14 | model_type: default 15 | filtsz: [3,4,5] 16 | cmotsz: 100 17 | dropout: 0.5 18 | features: 19 | - name: word 20 | vectorizer: 21 | type: token1d 22 | transform: baseline.lowercase 23 | embeddings: 24 | label: w2v-gn 25 | - name: char 26 | vectorizer: 27 | type: char2d 28 | embeddings: 29 | type: cbow 30 | dsz: 50 31 | 32 | 33 | train: 34 | fit_func: test_every_n_epochs 35 | nsteps: 100 36 | epochs: 2 37 | optim: adadelta 38 | eta: 1.0 39 | early_stopping_metric: acc 40 | verbose: 41 | console: True 42 | file: sst2-cm.csv 43 | 44 | -------------------------------------------------------------------------------- /mead/config/sst2-distributed.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "task": "classify", 4 | "basedir": "./sst2", 5 | "batchsz": 50, 6 | "features": [ 7 | { 8 | "name": "word", 9 | "vectorizer": { 10 | "type": "token1d", 11 | "transform": "baseline.lowercase" 12 | }, 13 | "embeddings": { 14 | "label": "w2v-gn" 15 | } 16 | } 17 | ], 18 | "preproc": { 19 | "mxlen": 100, 20 | "rev": false, 21 | "clean": true 22 | }, 23 | "backend": "tensorflow", 24 | "dataset": "SST2", 25 | "loader": { 26 | "reader_type": "default", 27 | "truncate": true 28 | }, 29 | "unif": 0.25, 30 | "model": { 31 | "model_type": "default", 32 | "filtsz": [ 33 | 3, 34 | 4, 35 | 5 36 | ], 37 | "cmotsz": 100, 38 | "dropout": 0.5, 39 | "finetune": true 40 | }, 41 | "train": { 42 | "fit_func": "distributed", 43 | "epochs": 5, 44 | "optim": "adamw", 45 | "lr_scheduler_type": "cosine", 46 | "decay_steps": 7700, 47 | "eta": 0.001, 48 | "model_zip": true, 49 | "early_stopping_metric": "acc", 50 | "verbose": { 51 | "console": true, 52 | "file": "sst2-cm.csv" 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /mead/config/sst2-elmo-eh.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "modules": ["hub:v1:addons:embed_elmo_tf"], 4 | "task": "classify", 5 | "basedir": "./sst2", 6 | "batchsz": 50, 7 | "features": [ 8 | { 9 | "name": "word", 10 | "vectorizer": { 11 | "type": "token1d", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "w2v-gn" 16 | } 17 | }, 18 | { 19 | "name": "elmo", 20 | "vectorizer": { 21 | "type": "elmo" 22 | }, 23 | "embeddings": { 24 | "label": "elmo-small-tf" 25 | } 26 | } 27 | ], 28 | "preproc": { 29 | "mxlen": 100, 30 | "rev": false, 31 | "clean": true 32 | }, 33 | "backend": "tensorflow", 34 | "dataset": "SST2", 35 | "loader": { 36 | "reader_type": "default" 37 | }, 38 | "unif": 0.25, 39 | "model": { 40 | "model_type": "default", 41 | "filtsz": [ 42 | 3, 43 | 4, 44 | 5 45 | ], 46 | "cmotsz": 100, 47 | "dropout": 0.5, 48 | "finetune": true 49 | }, 50 | "train": { 51 | "epochs": 2, 52 | "optim": "adadelta", 53 | "eta": 1.0, 54 | "model_zip": true, 55 | "early_stopping_metric": "acc", 56 | "verbose": { 57 | "console": true, 58 | "file": "sst2-cm.csv" 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /mead/config/sst2-elmo-hub.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules": ["vec_text", "embed_elmo"], 3 | "task": "classify", 4 | "basedir": "./sst2", 5 | "batchsz": 50, 6 | "features": [ 7 | { 8 | "name": "word", 9 | "vectorizer": { 10 | "type": "token1d", 11 | "transform": "baseline.lowercase" 12 | }, 13 | "embeddings": { 14 | "label": "w2v-gn" 15 | } 16 | }, 17 | { 18 | "name": "elmo", 19 | "vectorizer": { 20 | "type": "text" 21 | }, 22 | "embeddings": { 23 | "type": "elmo", "dsz": 1024 24 | } 25 | } 26 | ], 27 | "preproc": { 28 | "mxlen": 100, 29 | "rev": false, 30 | "clean": true 31 | }, 32 | "backend": "tensorflow", 33 | "dataset": "SST2", 34 | "loader": { 35 | "reader_type": "default" 36 | }, 37 | "unif": 0.25, 38 | "model": { 39 | "model_type": "default", 40 | "filtsz": [ 41 | 3, 42 | 4, 43 | 5 44 | ], 45 | "cmotsz": 100, 46 | "dropout": 0.5, 47 | "finetune": true 48 | }, 49 | "train": { 50 | "epochs": 2, 51 | "optim": "adadelta", 52 | "eta": 1.0, 53 | "model_zip": true, 54 | "early_stopping_metric": "acc", 55 | "verbose": { 56 | "console": true, 57 | "file": "sst2-cm.csv" 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /mead/config/sst2-elmo-large.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "modules": ["hub:v1:addons:embed_elmo_tf"], 4 | "task": "classify", 5 | "basedir": "./sst2", 6 | "batchsz": 50, 7 | "features": [ 8 | { 9 | "name": "word", 10 | "vectorizer": { 11 | "type": "token1d", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "w2v-gn" 16 | } 17 | }, 18 | { 19 | "name": "elmo", 20 | "vectorizer": { 21 | "type": "elmo" 22 | }, 23 | "embeddings": { 24 | "label": "elmo-large-tf" 25 | } 26 | } 27 | ], 28 | "preproc": { 29 | "mxlen": 100, 30 | "rev": false, 31 | "clean": true 32 | }, 33 | "backend": "tensorflow", 34 | "dataset": "SST2", 35 | "loader": { 36 | "reader_type": "default" 37 | }, 38 | "unif": 0.25, 39 | "model": { 40 | "model_type": "default", 41 | "filtsz": [ 42 | 3, 43 | 4, 44 | 5 45 | ], 46 | "cmotsz": 100, 47 | "dropout": 0.5, 48 | "finetune": true 49 | }, 50 | "train": { 51 | "epochs": 2, 52 | "optim": "adadelta", 53 | "eta": 1.0, 54 | "model_zip": true, 55 | "early_stopping_metric": "acc", 56 | "verbose": { 57 | "console": true, 58 | "file": "sst2-cm.csv" 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /mead/config/sst2-gpt2-small.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./sst2-gpt2-small 3 | batchsz: 32 4 | dataset: SST2 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | label: gpt2-small-npz 9 | type: tlm-words-embed-pooled 10 | pooling: mean 11 | transformer_type: pre-layer-norm 12 | layer_norms_after: false 13 | layer_norm_eps: 1.0e-5 14 | activation: gpt2_gelu 15 | finetune: true 16 | dropout: 0.1 17 | mlm: false 18 | dsz: 768 19 | name: gpt2 20 | vectorizer: 21 | mxlen: 100 22 | label: gpt2-small-bpe1d 23 | loader: 24 | reader_type: default 25 | model: 26 | model_type: fine-tune 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 20 31 | eta: 1.0e-5 32 | optim: adamw 33 | weight_decay: 1.0e-5 34 | lr_scheduler_type: cosine 35 | decay_steps: 48100 36 | unif: 0.1 37 | -------------------------------------------------------------------------------- /mead/config/sst2-lstm-840b.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "batchsz": 50, 4 | "basedir": "./sst2-lstm", 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { "type": "token1d" }, 9 | "embeddings": { "label": "glove-840B" } 10 | } 11 | ], 12 | "preproc": { 13 | "mxlen": 100, 14 | "clean": true 15 | }, 16 | "backend": "tensorflow", 17 | "dataset": "SST2", 18 | "loader": { 19 | "reader_type": "default" 20 | }, 21 | "unif": 0.25, 22 | "model": { 23 | "model_type": "lstm", 24 | "hsz": 200, 25 | "dropout": 0.5, 26 | "finetune": true 27 | }, 28 | "train": { 29 | "epochs": 5, 30 | "optim": "adamw", 31 | "eta": 0.0008, 32 | "weight_decay": 1.0e-5, 33 | "early_stopping_metric": "acc" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /mead/config/sst2-lstm-char.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "batchsz": 50, 4 | "features": [ 5 | { 6 | "name": "chars", 7 | "vectorizer": { 8 | "type": "char1d" 9 | }, 10 | "embeddings": { 11 | "dsz": 32 12 | } 13 | } 14 | ], 15 | "preproc": { 16 | "mxlen": 1000, 17 | "clean": true 18 | }, 19 | "backend": "tensorflow", 20 | "dataset": "SST2", 21 | "loader": { 22 | "reader_type": "default" 23 | }, 24 | "unif": 0.25, 25 | "model": { 26 | "model_type": "lstm", 27 | "rnn_type": "lstm", 28 | "hsz": 200, 29 | "dropout": 0.5, 30 | "lengths_key": "chars", 31 | "finetune": true 32 | }, 33 | "train": { 34 | "epochs": 2, 35 | "optim": "adadelta", 36 | "eta": 1.0, 37 | "model_base": "./models/sst2-lstm", 38 | "early_stopping_metric": "acc" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mead/config/sst2-lstm-pyt.yml: -------------------------------------------------------------------------------- 1 | task: classify 2 | batchsz: 50 3 | basedir: ./sst2-lstm-pyt 4 | 5 | preproc: 6 | mxlen: 100 7 | clean: true 8 | 9 | backend: pytorch 10 | dataset: SST2 11 | loader: 12 | reader_type: default 13 | 14 | unif: 0.25 15 | 16 | model: 17 | model_type: lstm 18 | rnnsz: 100 19 | dropout: 0.5 20 | finetune: true 21 | 22 | features: 23 | - name: word 24 | vectorizer: 25 | type: token1d 26 | embeddings: 27 | label: glove-840B 28 | - name: word2 29 | vectorizer: 30 | type: token1d 31 | embeddings: 32 | label: w2v-gn 33 | 34 | train: 35 | epochs: 2 36 | optim: adamw 37 | eta: 0.0008 38 | weight_decay: 1.0e-5 39 | early_stopping_metric: acc 40 | 41 | 42 | -------------------------------------------------------------------------------- /mead/config/sst2-lstm.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "batchsz": 50, 4 | "basedir": "./sst2-lstm", 5 | "features": [ 6 | { 7 | "name": "word", 8 | "vectorizer": { 9 | "type": "token1d" 10 | }, 11 | "embeddings": { 12 | "label": [ 13 | "glove-840B", 14 | "w2v-gn" 15 | ] 16 | } 17 | } 18 | ], 19 | "preproc": { 20 | "clean": true 21 | }, 22 | "backend": "tensorflow", 23 | "dataset": "SST2", 24 | "loader": { 25 | "reader_type": "default" 26 | }, 27 | "unif": 0.25, 28 | "model": { 29 | "model_type": "lstm", 30 | "hsz": 400, 31 | "dropout": 0.5 32 | }, 33 | "train": { 34 | "epochs": 5, 35 | "optim": "adamw", 36 | "eta": 0.0008, 37 | "weight_decay": 1.0e-5, 38 | "early_stopping_metric": "acc" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mead/config/sst2-nogpu-pyt.yml: -------------------------------------------------------------------------------- 1 | batchsz: 50 2 | basedir: sst2-pyt 3 | preproc: 4 | mxlen: 100 5 | rev: false 6 | clean: true 7 | backend: pytorch 8 | dataset: SST2 9 | loader: 10 | reader_type: default 11 | unif: 0.25 12 | model: 13 | nogpu: true 14 | model_type: default 15 | filtsz: [3,4,5] 16 | cmotsz: 100 17 | dropout: 0.5 18 | 19 | features: 20 | - name: word 21 | vectorizer: 22 | type: token1d 23 | transform: baseline.lowercase 24 | embeddings: 25 | label: w2v-gn 26 | train: 27 | gpus: 0 28 | epochs: 2 29 | optim: adadelta 30 | eta: 1.0 31 | early_stopping_metric: acc 32 | verbose: 33 | console: True 34 | file: sst2-cm.csv 35 | 36 | -------------------------------------------------------------------------------- /mead/config/sst2-pyt.yml: -------------------------------------------------------------------------------- 1 | batchsz: 50 2 | basedir: sst2-pyt 3 | preproc: 4 | mxlen: 100 5 | clean: true 6 | backend: pytorch 7 | dataset: SST2 8 | loader: 9 | reader_type: default 10 | unif: 0.25 11 | model: 12 | model_type: default 13 | filtsz: [3,4,5] 14 | cmotsz: 100 15 | dropout: 0.5 16 | 17 | features: 18 | - name: word 19 | vectorizer: 20 | type: token1d 21 | transform: baseline.lowercase 22 | embeddings: 23 | label: w2v-gn 24 | train: 25 | epochs: 2 26 | optim: adadelta 27 | eta: 1.0 28 | early_stopping_metric: acc 29 | verbose: 30 | console: True 31 | file: sst2-cm.csv 32 | 33 | -------------------------------------------------------------------------------- /mead/config/sst2-resconv.yml: -------------------------------------------------------------------------------- 1 | batchsz: 50 2 | basedir: sst2-pyt 3 | modules: ["hub:v1:addons:resconv"] 4 | preproc: 5 | mxlen: 100 6 | clean: true 7 | backend: pytorch 8 | dataset: SST2 9 | loader: 10 | reader_type: default 11 | unif: 0.25 12 | model: 13 | model_type: resconv 14 | filtsz: 3 15 | dropout: 0.5 16 | 17 | features: 18 | - name: word 19 | vectorizer: 20 | type: token1d 21 | transform: baseline.lowercase 22 | embeddings: 23 | label: w2v-gn 24 | train: 25 | epochs: 5 26 | optim: adadelta 27 | eta: 1 28 | early_stopping_metric: acc 29 | verbose: 30 | console: True 31 | file: sst2-cm.csv 32 | 33 | -------------------------------------------------------------------------------- /mead/config/sst2-rnf-pyt.yml: -------------------------------------------------------------------------------- 1 | modules: 2 | - hub:v1:addons:rnf_pytorch 3 | batchsz: 32 4 | preproc: 5 | mxlen: 100 6 | rev: true 7 | clean: true 8 | backend: pytorch 9 | dataset: SST2 10 | loader: 11 | reader_type: default 12 | unif: 0.25 13 | model: 14 | model_type: rnf 15 | filtsz: 5 16 | rnnsz: 300 17 | dropout: 0.4 18 | finetune: true 19 | features: 20 | - name: word 21 | vectorizer: 22 | type: token1d 23 | transform: baseline.lowercase 24 | embeddings: 25 | label: glove-840B 26 | 27 | train: 28 | epochs: 2 29 | optim: adam 30 | eta: 0.001 31 | early_stopping_metric: acc 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /mead/config/sst2-wandb.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "task": "classify", 4 | "basedir": "./sst2", 5 | "batchsz": 50, 6 | "modules":["reporting_wandb"], 7 | "features": [ 8 | { 9 | "name": "word", 10 | "vectorizer": { 11 | "type": "token1d", 12 | "transform": "baseline.lowercase" 13 | }, 14 | "embeddings": { 15 | "label": "w2v-gn" 16 | } 17 | } 18 | ], 19 | "preproc": { 20 | "mxlen": 100, 21 | "rev": false, 22 | "clean": true 23 | }, 24 | "backend": "tensorflow", 25 | "dataset": "SST2", 26 | "loader": { 27 | "reader_type": "default" 28 | }, 29 | "unif": 0.25, 30 | "model": { 31 | "model_type": "default", 32 | "filtsz": [ 33 | 3, 34 | 4, 35 | 5 36 | ], 37 | "cmotsz": 100, 38 | "dropout": 0.5, 39 | "finetune": true 40 | }, 41 | "train": { 42 | "epochs": 2, 43 | "optim": "adadelta", 44 | "eta": 1.0, 45 | "model_zip": true, 46 | "early_stopping_metric": "acc", 47 | "verbose": { 48 | "console": true, 49 | "file": "sst2-cm.csv" 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mead/config/sst2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "task": "classify", 4 | "basedir": "./sst2", 5 | "batchsz": 50, 6 | "features": [ 7 | { 8 | "name": "word", 9 | "vectorizer": { 10 | "type": "token1d", 11 | "transform": "baseline.lowercase" 12 | }, 13 | "embeddings": { 14 | "label": "w2v-gn" 15 | } 16 | } 17 | ], 18 | "preproc": { 19 | "rev": false, 20 | "clean": true 21 | }, 22 | "backend": "tensorflow", 23 | "dataset": "SST2", 24 | "reader": { 25 | "type": "default" 26 | }, 27 | "unif": 0.25, 28 | "model": { 29 | "type": "default", 30 | "filtsz": [ 31 | 3, 32 | 4, 33 | 5 34 | ], 35 | "cmotsz": 100, 36 | "dropout": 0.5, 37 | "finetune": true 38 | }, 39 | "train": { 40 | "epochs": 2, 41 | "optim": "adadelta", 42 | "eta": 1.0, 43 | "model_zip": true, 44 | "early_stopping_metric": "acc", 45 | "verbose": { 46 | "console": true, 47 | "file": "sst2-cm.csv" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /mead/config/trec-bert-base-uncased.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "./trec-bert", 4 | "backend": "pytorch", 5 | "dataset": "trec", 6 | "batchsz": 10, 7 | "features": [ 8 | { 9 | "name": "bert", 10 | "vectorizer": { 11 | "label": "bert-base-uncased" 12 | }, 13 | "embeddings": { 14 | "finetune": true, 15 | "word_embed_type": "learned-positional-w-bias", 16 | "label": "bert-base-uncased-npz", 17 | "type": "tlm-words-embed-pooled", 18 | "reduction": "sum-layer-norm", 19 | "layer_norms_after": true, 20 | "dropout": 0.1, 21 | "mlm": true 22 | } 23 | } 24 | ], 25 | "preproc": { 26 | "mxlen": 100 27 | }, 28 | "loader": { 29 | "reader_type": "default" 30 | }, 31 | "unif": 0.25, 32 | "model": { 33 | "model_type": "fine-tune" 34 | }, 35 | "train": { 36 | "epochs": 5, 37 | "optim": "adamw", 38 | "eta": 0.00001, 39 | "weight_decay": 1.0e-8, 40 | "early_stopping_metric": "acc", 41 | "verbose": { 42 | "console": true, 43 | "file": "trec-cm.csv" 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /mead/config/trec-bert-finetune-pytorch-eh.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "./trec-bert", 4 | "batchsz": 10, 5 | "features": [ 6 | { 7 | "name": "bert", 8 | "vectorizer": { 9 | "label": "bert-base-uncased" 10 | }, 11 | "embeddings": { 12 | "label": "bert-base-uncased-pooled-pytorch" 13 | } 14 | } 15 | ], 16 | "preproc": { 17 | "mxlen": 100 18 | }, 19 | "backend": "pytorch", 20 | "dataset": "trec", 21 | "loader": { 22 | "reader_type": "default" 23 | }, 24 | "unif": 0.25, 25 | "model": { 26 | "model_type": "fine-tune" 27 | }, 28 | "train": { 29 | "epochs": 5, 30 | "optim": "adamw", 31 | "eta": 0.00001, 32 | "weight_decay": 1.0e-8, 33 | "early_stopping_metric": "acc", 34 | "verbose": { 35 | "console": true, 36 | "file": "trec-cm.csv" 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mead/config/trec-bert-finetune-tf-eh.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "./trec-bert", 4 | "batchsz": 10, 5 | "features": [ 6 | { 7 | "name": "bert", 8 | "vectorizer": { 9 | "label": "bert-base-uncased", 10 | "dtype": "int32" 11 | }, 12 | "embeddings": { 13 | "label": "bert-base-uncased-pooled-tf" 14 | } 15 | } 16 | ], 17 | "preproc": { 18 | "mxlen": 100 19 | }, 20 | "backend": "tf", 21 | "dataset": "trec", 22 | "loader": { 23 | "reader_type": "default" 24 | }, 25 | "unif": 0.25, 26 | "model": { 27 | "model_type": "fine-tune" 28 | }, 29 | "train": { 30 | "epochs": 5, 31 | "optim": "adam", 32 | "eta": 0.00001, 33 | "weight_decay": 1.0e-8, 34 | "early_stopping_metric": "acc", 35 | "verbose": { 36 | "console": true, 37 | "file": "trec-cm.csv" 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /mead/config/trec-cnn.yml: -------------------------------------------------------------------------------- 1 | batchsz: 50 2 | preproc: 3 | mxlen: -1 4 | 5 | backend: tensorflow 6 | dataset: trec 7 | loader: 8 | reader_type: default 9 | 10 | unif: 0.25 11 | model: 12 | model_type: default 13 | filtsz: [3] 14 | dropout: 0.5 15 | cmotsz: 100 16 | 17 | features: 18 | - name: word 19 | vectorizer: 20 | type: token1d 21 | embeddings: 22 | label: w2v-gn 23 | 24 | - name: word2 25 | vectorizer: 26 | type: token1d 27 | embeddings: 28 | label: glove-42B 29 | transform: baseline.lowercase 30 | 31 | 32 | train: 33 | epochs: 30 34 | optim: adadelta 35 | eta: 1.0 36 | model_base: ./models/trec 37 | early_stopping_metric: acc 38 | patience: 25 39 | -------------------------------------------------------------------------------- /mead/config/trec-demolib.yml: -------------------------------------------------------------------------------- 1 | # NOTE: This example only works in declarative mode! 2 | # To pass in a slack reporting hook, pass in 3 | # --reporting slack --slack:webhook 4 | batchsz: 50 5 | modules: 6 | - hub:v1:addons:demolib 7 | preproc: 8 | mxlen: -1 9 | 10 | backend: tensorflow 11 | dataset: trec 12 | basedir: trec-demolib 13 | loader: 14 | reader_type: default 15 | 16 | unif: 0.25 17 | model: 18 | model_type: default 19 | filtsz: [3] 20 | dropout: 0.5 21 | cmotsz: 100 22 | 23 | features: 24 | - name: word 25 | vectorizer: 26 | type: token1d 27 | embeddings: 28 | label: w2v-gn 29 | 30 | - name: word2 31 | vectorizer: 32 | type: token1d 33 | embeddings: 34 | label: glove-42B 35 | transform: baseline.lowercase 36 | 37 | 38 | train: 39 | fit_func: test_every_n_epochs 40 | epochs: 30 41 | optim: adadelta 42 | eta: 1.0 43 | model_base: ./models/trec 44 | early_stopping_metric: acc 45 | patience: 25 46 | -------------------------------------------------------------------------------- /mead/config/trec-gpt2-small.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./trec-gpt2-small 3 | batchsz: 10 4 | dataset: trec 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | label: gpt2-small-npz 9 | type: tlm-words-embed-pooled 10 | pooling: mean 11 | transformer_type: pre-layer-norm 12 | layer_norms_after: false 13 | layer_norm_eps: 1.0e-5 14 | activation: gpt2_gelu 15 | finetune: true 16 | dropout: 0.1 17 | mlm: false 18 | dsz: 768 19 | name: gpt2 20 | vectorizer: 21 | mxlen: 100 22 | label: gpt2-small-bpe1d 23 | loader: 24 | reader_type: default 25 | model: 26 | model_type: fine-tune 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 5 31 | eta: 1.0e-5 32 | optim: adam 33 | weight_decay: 1.0e-8 34 | unif: 0.25 35 | -------------------------------------------------------------------------------- /mead/config/trec-lstm.yml: -------------------------------------------------------------------------------- 1 | model_base: ./trec-qa-lstm 2 | batchsz: 10 3 | preproc: 4 | mxlen: -1 5 | 6 | backend: tensorflow 7 | dataset: trec 8 | loader: 9 | reader_type: default 10 | 11 | unif: 0.25 12 | model: 13 | model_type: lstm 14 | rnnsz: 100 15 | hsz: 100 16 | dropout: 0.5 17 | layers: 1 18 | 19 | features: 20 | - name: word 21 | vectorizer: 22 | type: token1d 23 | transform: baseline.lowercase 24 | embeddings: 25 | label: w2v-gn 26 | - name: word2 27 | vectorizer: 28 | type: token1d 29 | embeddings: 30 | label: glove-840B 31 | 32 | train: 33 | epochs: 30 34 | optim: adam 35 | eta: 0.001 36 | early_stopping_metric: macro_f1 37 | patience: 25 -------------------------------------------------------------------------------- /mead/config/trec-roberta-base.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "basedir": "./trec-roberta-base", 4 | "backend": "pytorch", 5 | "dataset": "trec", 6 | "batchsz": 10, 7 | "features": [ 8 | { 9 | "name": "roberta", 10 | "vectorizer": { 11 | "label": "roberta-base" 12 | }, 13 | "embeddings": { 14 | "finetune": true, 15 | "word_embed_type": "learned-positional-w-bias", 16 | "offset": 2, 17 | "mxlen": 514, 18 | "label": "roberta-base-npz", 19 | "type": "tlm-words-embed-pooled", 20 | "reduction": "sum-layer-norm", 21 | "layer_norms_after": true, 22 | "layer_norm_eps": 1e-5, 23 | "dropout": 0.1, 24 | "mlm": true 25 | } 26 | } 27 | ], 28 | "preproc": { 29 | "mxlen": 100 30 | }, 31 | "loader": { 32 | "reader_type": "default" 33 | }, 34 | "unif": 0.25, 35 | "model": { 36 | "model_type": "fine-tune" 37 | }, 38 | "train": { 39 | "epochs": 5, 40 | "optim": "adamw", 41 | "eta": 0.00001, 42 | "weight_decay": 1.0e-8, 43 | "early_stopping_metric": "acc", 44 | "verbose": { 45 | "console": true, 46 | "file": "trec-cm.csv" 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /mead/config/twpos-blstm-lan.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "modules": ["hub:v1:addons:lan_pyt"], 4 | "basedir": "./twpos", 5 | "conll_output": "twposresults.conll", 6 | "charsz": 16, 7 | "unif": 0.1, 8 | "preproc": { 9 | }, 10 | "backend": "pytorch", 11 | "dataset": "twpos", 12 | "loader": { 13 | "reader_type": "default", 14 | "named_fields": { 15 | "0": "text", 16 | "-1": "y" 17 | } 18 | }, 19 | "features": [ 20 | { 21 | "name": "word", 22 | "vectorizer": { 23 | "type": "dict1d", 24 | "fields": "text", 25 | "transform": "baseline.lowercase" 26 | }, 27 | "embeddings": { "label": "glove-twitter-27B"} 28 | }, 29 | { 30 | "name": "word2", 31 | "vectorizer": { 32 | "type": "dict1d", 33 | "fields": "text", 34 | "transform": "baseline.lowercase" 35 | }, 36 | "embeddings": { "label": "glove-42B"} 37 | }, 38 | { 39 | "name": "word3", 40 | "vectorizer": { 41 | "type": "dict1d", 42 | "fields": "text", 43 | "transform": "baseline.web_cleanup" 44 | }, 45 | "embeddings": { "label": "w2v-twitter-30M" } 46 | }, 47 | { 48 | "name": "char", 49 | "vectorizer": { "type": "dict2d" }, 50 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 51 | } 52 | ], 53 | "model": { 54 | "model_type": "blstm-lan", 55 | "hsz": 200, 56 | "blstm_dropout": 0.5, 57 | "mha_dropout": 0.1, 58 | "rnntype": "blstm", 59 | "layers": 3, 60 | "crf": false 61 | }, 62 | "train": { 63 | "batchsz": 20, 64 | "epochs": 300, 65 | "optim": "sgd", 66 | "eta": 0.01, 67 | "mom": 0.9, 68 | "patience": 100, 69 | "early_stopping_metric": "acc", 70 | "span_type": "token", 71 | "clip": 5.0 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /mead/config/twpos-nogpu-pyt.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "./twpos", 4 | "conll_output": "twposresults.conll", 5 | "charsz": 16, 6 | "unif": 0.1, 7 | "preproc": { 8 | }, 9 | "backend": "pytorch", 10 | "dataset": "twpos", 11 | "loader": { 12 | "reader_type": "default", 13 | "named_fields": { 14 | "0": "text", 15 | "-1": "y" 16 | } 17 | }, 18 | "features": [ 19 | { 20 | "name": "word", 21 | "vectorizer": { 22 | "type": "dict1d", 23 | "fields": "text", 24 | "transform": "baseline.lowercase" 25 | }, 26 | "embeddings": { "label": "glove-twitter-27B"} 27 | }, 28 | { 29 | "name": "word2", 30 | "vectorizer": { 31 | "type": "dict1d", 32 | "fields": "text", 33 | "transform": "baseline.lowercase" 34 | }, 35 | "embeddings": { "label": "glove-42B"} 36 | }, 37 | { 38 | "name": "word3", 39 | "vectorizer": { 40 | "type": "dict1d", 41 | "fields": "text", 42 | "transform": "baseline.web_cleanup" 43 | }, 44 | "embeddings": { "label": "w2v-twitter-30M" } 45 | }, 46 | { 47 | "name": "char", 48 | "vectorizer": { "type": "dict2d" }, 49 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 50 | } 51 | ], 52 | "model": { 53 | "nogpu": true, 54 | "model_type": "default", 55 | "hsz": 200, 56 | "dropout": 0.5, 57 | "rnntype": "blstm", 58 | "layers": 1, 59 | "crf": true 60 | }, 61 | "train": { 62 | "batchsz": 20, 63 | "epochs": 40, 64 | "optim": "sgd", 65 | "eta": 0.01, 66 | "mom": 0.9, 67 | "patience": 20, 68 | "early_stopping_metric": "acc", 69 | "span_type": "token", 70 | "clip": 5.0 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /mead/config/twpos-stacked.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "./twpos", 4 | "conll_output": "twposresults.conll", 5 | "charsz": 16, 6 | "unif": 0.1, 7 | "preproc": { 8 | }, 9 | "backend": "tensorflow", 10 | "dataset": "twpos", 11 | "loader": { 12 | "reader_type": "default", 13 | "named_fields": { 14 | "0": "text", 15 | "-1": "y" 16 | } 17 | }, 18 | "features": [{ 19 | "name": "word", 20 | "vectorizer": { 21 | "type": "dict1d", 22 | "fields": "text", 23 | "transform": "baseline.lowercase" 24 | }, 25 | "embeddings": { "labels": ["glove-twitter-27B", "glove-42B"]} 26 | }, { 27 | "name": "word2", 28 | "vectorizer": { 29 | "type": "dict1d", 30 | "fields": "text", 31 | "transform": "baseline.web_cleanup" 32 | }, 33 | "embeddings": { "label": "w2v-twitter-30M" } 34 | }, { 35 | "name": "char", 36 | "vectorizer": { "type": "dict2d" }, 37 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 38 | }], 39 | "model": { 40 | "model_type": "default", 41 | "hsz": 200, 42 | "dropout": 0.5, 43 | "rnntype": "blstm", 44 | "layers": 1, 45 | "crf": false 46 | }, 47 | "train": { 48 | "batchsz": 20, 49 | "epochs": 40, 50 | "optim": "sgd", 51 | "eta": 0.01, 52 | "mom": 0.9, 53 | "patience": 20, 54 | "early_stopping_metric": "acc", 55 | "span_type": "token", 56 | "clip": 5.0 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /mead/config/twpos.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "./twpos", 4 | "conll_output": "twposresults.conll", 5 | "charsz": 16, 6 | "unif": 0.1, 7 | "preproc": { 8 | }, 9 | "backend": "tensorflow", 10 | "dataset": "twpos", 11 | "loader": { 12 | "reader_type": "default", 13 | "named_fields": { 14 | "0": "text", 15 | "-1": "y" 16 | } 17 | }, 18 | "features": [ 19 | { 20 | "name": "word", 21 | "vectorizer": { 22 | "type": "dict1d", 23 | "fields": "text", 24 | "transform": "baseline.lowercase" 25 | }, 26 | "embeddings": { "label": "glove-twitter-27B"} 27 | }, 28 | { 29 | "name": "word2", 30 | "vectorizer": { 31 | "type": "dict1d", 32 | "fields": "text", 33 | "transform": "baseline.lowercase" 34 | }, 35 | "embeddings": { "label": "glove-42B"} 36 | }, 37 | { 38 | "name": "word3", 39 | "vectorizer": { 40 | "type": "dict1d", 41 | "fields": "text", 42 | "transform": "baseline.web_cleanup" 43 | }, 44 | "embeddings": { "label": "w2v-twitter-30M" } 45 | }, 46 | { 47 | "name": "char", 48 | "vectorizer": { "type": "dict2d" }, 49 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 50 | } 51 | ], 52 | "model": { 53 | "model_type": "default", 54 | "hsz": 200, 55 | "dropout": 0.5, 56 | "rnntype": "blstm", 57 | "layers": 1, 58 | "crf": true 59 | }, 60 | "train": { 61 | "batchsz": 20, 62 | "epochs": 40, 63 | "optim": "sgd", 64 | "eta": 0.01, 65 | "mom": 0.9, 66 | "patience": 20, 67 | "early_stopping_metric": "acc", 68 | "span_type": "token", 69 | "clip": 5.0 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /mead/config/wmt-de-en-luong.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 0, 4 | "batchsz": 128, 5 | "unif": 0.1, 6 | "features": [ 7 | { 8 | "name": "src", 9 | "vectorizer": { "type": "token1d"}, 10 | "embeddings": { "dsz": 1024 } 11 | }, 12 | { 13 | "name": "tgt", 14 | "vectorizer": { "type": "token1d"}, 15 | "embeddings": { "dsz": 1024 } 16 | } 17 | ], 18 | "preproc": { 19 | "mxlen": 50 20 | }, 21 | "backend": "tensorflow", 22 | "dataset": "wmt14-de-en", 23 | "loader": { 24 | "reader_type": "default", 25 | "pair_suffix": ["de", "en"] 26 | }, 27 | "model": { 28 | "model_type": "attn", 29 | "rnntype": "blstm", 30 | "hsz": 1024, 31 | "dropout": 0.2, 32 | "layers": 4 33 | }, 34 | "train": { 35 | "epochs": 10, 36 | "optim": "sgd", 37 | "start_decay_epoch": 5, 38 | "decay_rate": 2.0, 39 | "decay_type": "zaremba", 40 | "lr": 1.0, 41 | "do_early_stopping": false, 42 | "clip": 5.0 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mead/config/wnli-bert-base-uncased.yml: -------------------------------------------------------------------------------- 1 | backend: pytorch 2 | basedir: ./wnli-bert-base-uncased 3 | batchsz: 16 4 | dataset: wnli 5 | features: 6 | - embeddings: 7 | word_embed_type: learned-positional 8 | token_type_vsz: 2 9 | label: bert-base-uncased-npz 10 | type: tlm-words-embed-pooled 11 | reduction: sum-layer-norm 12 | layer_norms_after: true 13 | finetune: true 14 | dropout: 0.1 15 | mlm: true 16 | name: bert 17 | vectorizer: 18 | mxlen: 400 19 | label: bert-base-uncased-no-cls 20 | loader: 21 | reader_type: tsv-paired-shared-vec 22 | use_token_type: true 23 | col_keys: [index, sentence1, sentence2, label] 24 | start_tokens_1: ["[CLS]"] 25 | model: 26 | model_type: fine-tune-paired 27 | task: classify 28 | train: 29 | early_stopping_metric: acc 30 | epochs: 3 31 | warmup_steps: 12 32 | eta: 5.0e-5 33 | optim: adamw 34 | weight_decay: 1.0e-8 35 | lr_scheduler_type: warmup_linear 36 | #lr_scheduler_type: [warmup_linear, cosine] 37 | #decay_steps: 40*3 38 | unif: 0.1 39 | -------------------------------------------------------------------------------- /mead/config/wnut-bert-hf.yml: -------------------------------------------------------------------------------- 1 | # This configuration file uses the HuggingFace library via mead-hub 2 | # To run it, do `mead-config --config/wnut-bert-hf.yml --embeddings hub:v1:embeddings 3 | # 4 | # To see an example of a BERT configuration that does not require mead-hub 5 | # or HuggingFace dependencies, see `config/wnut-bert.yml` 6 | task: tagger 7 | backend: pytorch 8 | dataset: wnut-iobes 9 | conll_output: wnut-bert.conll 10 | basedir: ./ 11 | unif: 0.1 12 | preproc: 13 | mxlen: -1 14 | mxwlen: -1 15 | features: 16 | - name: word 17 | vectorizer: 18 | label: bert-base-cased-dict1d 19 | embeddings: 20 | label: bert-base-cased-pytorch 21 | layers: [-1] 22 | 23 | loader: 24 | reader_type: default 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | embed_file: bert-base-cased 30 | 31 | model: 32 | model_type: pass 33 | constrain_decode: 0 34 | crf: 0 35 | 36 | train: 37 | epochs: 40 38 | optim: adam 39 | eta: 1.0e-5 40 | early_stopping_metric: f1 41 | clip: 5.0 42 | span_type: iobes 43 | batchsz: 32 44 | -------------------------------------------------------------------------------- /mead/config/wnut-bert.yml: -------------------------------------------------------------------------------- 1 | task: tagger 2 | backend: pytorch 3 | dataset: wnut-iobes 4 | conll_output: wnut-bert.conll 5 | basedir: ./ 6 | unif: 0.1 7 | preproc: 8 | mxlen: -1 9 | mxwlen: -1 10 | 11 | features: 12 | - name: word 13 | vectorizer: 14 | label: bert-base-cased-dict1d 15 | embeddings: 16 | type: tlm-words-embed 17 | word_embed_type: learned-positional-w-bias 18 | label: bert-base-cased-npz 19 | reduction: sum-layer-norm 20 | layer_norms_after: true 21 | finetune: true 22 | mlm: true 23 | loader: 24 | reader_type: default 25 | named_fields: {"0": "text", "-1": "y"} 26 | label_vectorizer: 27 | label: y 28 | type: wordpiece-label-dict1d 29 | 30 | model: 31 | model_type: pass 32 | constrain_decode: 0 33 | crf: 0 34 | 35 | train: 36 | epochs: 40 37 | optim: adam 38 | eta: 1.0e-5 39 | early_stopping_metric: f1 40 | clip: 5.0 41 | span_type: iobes 42 | batchsz: 32 43 | -------------------------------------------------------------------------------- /mead/config/wnut-elmo.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "modules": ["hub:v1:addons:embed_elmo_tf"], 4 | "batchsz": 20, 5 | "conll_output": "wnut-elmo-results.conll", 6 | "charsz": 16, 7 | "unif": 0.1, 8 | "preproc": { 9 | "mxlen": 60, 10 | "mxwlen": 40, 11 | "lower": true 12 | }, 13 | "features": [ 14 | { 15 | "name": "word", 16 | "vectorizer": { 17 | "type": "dict1d", 18 | "transform": "baseline.lowercase" 19 | }, 20 | "embeddings": { 21 | "label": "glove-42B" 22 | } 23 | }, 24 | { 25 | "name": "elmo", 26 | "vectorizer": { 27 | "type": "dict_elmo" 28 | }, 29 | "embeddings": { 30 | "label": "elmo-small-tf" 31 | } 32 | }, { 33 | "name":"char", 34 | "vectorizer": {"type":"dict2d"}, 35 | "embeddings": {"dsz":16,"wsz":10,"cfiltsz":[3],"type":"char-conv"} 36 | } 37 | ], 38 | "backend": "tensorflow", 39 | "dataset": "wnut", 40 | "loader": { 41 | "reader_type": "default", 42 | "named_fields": { 43 | "0":"text", 44 | "-1":"y" 45 | } 46 | }, 47 | "model": { 48 | "model_type": "default", 49 | "hsz": 512, 50 | "wsz": 10, 51 | "dropout": 0.5, 52 | "rnntype": "blstm", 53 | "constrain_decode": true, 54 | "crf": 1 55 | }, 56 | "train": { 57 | "epochs": 60, 58 | "optim": "sgd", 59 | "decay": 0, 60 | "eta": 0.01, 61 | "mom": 0.9, 62 | "patience": 20, 63 | "early_stopping_metric": "f1", 64 | "span_type": "bio", 65 | "clip": 5.0 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /mead/config/wnut-no-crf.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "wnut-multi-emb-iobes", 4 | "batchsz": 20, 5 | "conll_output": "wnutresults.conll", 6 | "unif": 0.1, 7 | "preproc": { 8 | "mxlen": 60, 9 | "mxwlen": 40 10 | }, 11 | "features": [ 12 | { 13 | "name": "word", 14 | "vectorizer": { 15 | "type": "dict1d", 16 | "fields": "text", 17 | "transform": "baseline.lowercase" 18 | }, 19 | "embeddings": { "label": "glove-twitter-27B"} 20 | }, 21 | { 22 | "name": "word2", 23 | "vectorizer": { 24 | "type": "dict1d", 25 | "fields": "text", 26 | "transform": "baseline.lowercase" 27 | }, 28 | "embeddings": { "label": "glove-42B"} 29 | }, 30 | { 31 | "name": "word3", 32 | "vectorizer": { 33 | "type": "dict1d", 34 | "fields": "text", 35 | "transform": "baseline.web_cleanup" 36 | }, 37 | "embeddings": { "label": "w2v-twitter-30M" } 38 | }, 39 | { 40 | "name": "char", 41 | "vectorizer": { "type": "dict2d" }, 42 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 43 | } 44 | ], 45 | "backend": "pytorch", 46 | "dataset": "wnut-iobes", 47 | "loader": { 48 | "reader_type": "default", 49 | "named_fields": { 50 | "0":"text", 51 | "-1":"y" 52 | } 53 | }, 54 | "model": { 55 | "model_type": "default", 56 | "cfiltsz": [ 57 | 3 58 | ], 59 | "hsz": 200, 60 | "dropout": 0.5, 61 | "rnntype": "blstm", 62 | "layers": 1, 63 | "constrain_decode":true, 64 | "crf": 0 65 | }, 66 | "train": { 67 | "epochs": 60, 68 | "optim": "sgd", 69 | "decay": 0, 70 | "eta": 0.015, 71 | "mom": 0.9, 72 | "patience": 20, 73 | "early_stopping_metric": "f1", 74 | "clip": 5.0, 75 | "span_type": "iobes" 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /mead/config/wnut-single-no-crf.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "wnut-iobes", 4 | "batchsz": 20, 5 | "conll_output": "wnut-iobes-results.conll", 6 | "unif": 0.1, 7 | "preproc": { 8 | "mxlen": 60, 9 | "mxwlen": 40 10 | }, 11 | "features": [ 12 | { 13 | "name": "word", 14 | "vectorizer": { 15 | "type": "dict1d", 16 | "fields": "text", 17 | "transform": "baseline.lowercase" 18 | }, 19 | "embeddings": { "label": "glove-twitter-27B"} 20 | }, 21 | { 22 | "name": "char", 23 | "vectorizer": { "type": "dict2d" }, 24 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 25 | } 26 | ], 27 | "backend": "pytorch", 28 | "dataset": "wnut-iobes", 29 | "loader": { 30 | "reader_type": "default", 31 | "named_fields": { 32 | "0":"text", 33 | "-1":"y" 34 | } 35 | }, 36 | "model": { 37 | "model_type": "default", 38 | "cfiltsz": [ 39 | 3 40 | ], 41 | "hsz": 200, 42 | "dropout": 0.5, 43 | "rnntype": "blstm", 44 | "layers": 1, 45 | "constrain_decode":true, 46 | "crf": 0 47 | }, 48 | "train": { 49 | "epochs": 60, 50 | "optim": "sgd", 51 | "decay": 0, 52 | "eta": 0.015, 53 | "mom": 0.9, 54 | "patience": 20, 55 | "early_stopping_metric": "f1", 56 | "clip": 5.0, 57 | "span_type": "iobes" 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /mead/config/wnut-single.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "wnut-iobes", 4 | "batchsz": 20, 5 | "conll_output": "wnut-iobes-results.conll", 6 | "unif": 0.1, 7 | "preproc": { 8 | "mxlen": 60, 9 | "mxwlen": 40 10 | }, 11 | "features": [ 12 | { 13 | "name": "word", 14 | "vectorizer": { 15 | "type": "dict1d", 16 | "fields": "text", 17 | "transform": "baseline.lowercase" 18 | }, 19 | "embeddings": { "label": "glove-twitter-27B"} 20 | }, 21 | { 22 | "name": "char", 23 | "vectorizer": { "type": "dict2d" }, 24 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 25 | } 26 | ], 27 | "backend": "pytorch", 28 | "dataset": "wnut-iobes", 29 | "loader": { 30 | "reader_type": "default", 31 | "named_fields": { 32 | "0":"text", 33 | "-1":"y" 34 | } 35 | }, 36 | "model": { 37 | "model_type": "default", 38 | "cfiltsz": [ 39 | 3 40 | ], 41 | "hsz": 200, 42 | "dropout": 0.5, 43 | "rnntype": "blstm", 44 | "layers": 1, 45 | "constrain_decode":true, 46 | "crf": 1 47 | }, 48 | "train": { 49 | "epochs": 60, 50 | "optim": "sgd", 51 | "decay": 0, 52 | "eta": 0.015, 53 | "mom": 0.9, 54 | "patience": 20, 55 | "early_stopping_metric": "f1", 56 | "clip": 5.0, 57 | "span_type": "iobes" 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /mead/config/wnut.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "basedir": "wnut-multi-emb-iobes", 4 | "batchsz": 20, 5 | "conll_output": "wnutresults.conll", 6 | "unif": 0.1, 7 | "preproc": { 8 | "mxlen": 60, 9 | "mxwlen": 40 10 | }, 11 | "features": [ 12 | { 13 | "name": "word", 14 | "vectorizer": { 15 | "type": "dict1d", 16 | "fields": "text", 17 | "transform": "baseline.lowercase" 18 | }, 19 | "embeddings": { "label": "glove-twitter-27B"} 20 | }, 21 | { 22 | "name": "word2", 23 | "vectorizer": { 24 | "type": "dict1d", 25 | "fields": "text", 26 | "transform": "baseline.lowercase" 27 | }, 28 | "embeddings": { "label": "glove-42B"} 29 | }, 30 | { 31 | "name": "word3", 32 | "vectorizer": { 33 | "type": "dict1d", 34 | "fields": "text", 35 | "transform": "baseline.web_cleanup" 36 | }, 37 | "embeddings": { "label": "w2v-twitter-30M" } 38 | }, 39 | { 40 | "name": "char", 41 | "vectorizer": { "type": "dict2d" }, 42 | "embeddings": { "dsz": 30, "wsz": 30, "type": "char-conv" } 43 | } 44 | ], 45 | "backend": "pytorch", 46 | "dataset": "wnut-iobes", 47 | "loader": { 48 | "reader_type": "default", 49 | "named_fields": { 50 | "0":"text", 51 | "-1":"y" 52 | } 53 | }, 54 | "model": { 55 | "model_type": "default", 56 | "cfiltsz": [ 57 | 3 58 | ], 59 | "hsz": 200, 60 | "dropout": 0.5, 61 | "rnntype": "blstm", 62 | "layers": 1, 63 | "constrain_decode":true, 64 | "crf": 1 65 | }, 66 | "train": { 67 | "epochs": 60, 68 | "optim": "sgd", 69 | "decay": 0, 70 | "eta": 0.015, 71 | "mom": 0.9, 72 | "patience": 20, 73 | "early_stopping_metric": "f1", 74 | "clip": 5.0, 75 | "span_type": "iobes" 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /mead/exporters.py: -------------------------------------------------------------------------------- 1 | import os 2 | from baseline.utils import exporter, optional_params 3 | 4 | __all__ = [] 5 | export = exporter(__all__) 6 | 7 | 8 | @export 9 | class Exporter: 10 | 11 | def __init__(self, task, **kwargs): 12 | super().__init__() 13 | self.task = task 14 | 15 | @classmethod 16 | def preproc_type(cls): 17 | return 'client' 18 | 19 | def _run(self, model_file, output_dir, project=None, name=None, model_version=None, **kwargs): 20 | raise NotImplementedError 21 | 22 | def run(self, model_file, output_dir, project=None, name=None, model_version=None, use_all_features=False, **kwargs): 23 | client_loc, server_loc = self._run( 24 | model_file, 25 | output_dir, 26 | project=project, 27 | name=name, 28 | model_version=model_version, 29 | use_all_features=use_all_features, 30 | **kwargs 31 | ) 32 | if model_version is None: 33 | try: 34 | model_version = int(os.path.basename(client_loc)) 35 | except ValueError: 36 | pass 37 | msg = { 38 | "client_bundle": client_loc, 39 | "server_bundle": server_loc, 40 | "project": project, 41 | "name": name, 42 | "version": model_version 43 | } 44 | for rep in self.task.reporting: 45 | rep.step(msg, 0, 'Export', 'EXPORT') 46 | self.task._close_reporting_hooks() 47 | return client_loc, server_loc 48 | 49 | 50 | BASELINE_EXPORTERS = {} 51 | 52 | 53 | @export 54 | @optional_params 55 | def register_exporter(cls, task, name=None): 56 | """Register an exporter 57 | 58 | Use this pattern if you want to provide an override to a `Exporter` class. 59 | 60 | """ 61 | if name is None: 62 | name = cls.__name__ 63 | 64 | if task not in BASELINE_EXPORTERS: 65 | BASELINE_EXPORTERS[task] = {} 66 | 67 | if name in BASELINE_EXPORTERS[task]: 68 | raise Exception('Error: attempt to re-defined previously registered handler {} in exporter registry'.format(name)) 69 | 70 | BASELINE_EXPORTERS[task][name] = cls 71 | return cls 72 | 73 | 74 | def create_exporter(task, name=None, **kwargs): 75 | return BASELINE_EXPORTERS[task.task_name()][name](task, **kwargs) 76 | -------------------------------------------------------------------------------- /mead/hash_config.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | from baseline.utils import read_config_stream 3 | from mead.utils import hash_config, convert_path 4 | 5 | 6 | def main(): 7 | parser = argparse.ArgumentParser(description="Get the mead hash of a config.") 8 | parser.add_argument('config', help='JSON/YML Configuration for an experiment: local file or remote URL', type=convert_path, default="$MEAD_CONFIG") 9 | args = parser.parse_args() 10 | 11 | config = read_config_stream(args.config) 12 | print(hash_config(config)) 13 | 14 | 15 | if __name__ == "__main__": 16 | main() 17 | -------------------------------------------------------------------------------- /mead/preprocessors.py: -------------------------------------------------------------------------------- 1 | from baseline.utils import register, exporter, optional_params 2 | 3 | 4 | __all__ = [] 5 | export = exporter(__all__) 6 | 7 | BASELINE_PREPROCESSORS = {} 8 | 9 | 10 | @export 11 | class Preprocessor: 12 | """ 13 | Generic class for creating vectorizers using tensorflow/pyt ops, to be used for exporting models when the service gets 14 | a string instead of a vectorized input. 15 | """ 16 | 17 | def __init__(self, feature, vectorizer, index, vocab, **kwargs): 18 | self.feature = feature 19 | self.vectorizer = vectorizer 20 | self.index = index 21 | self.vocab = vocab 22 | 23 | def preproc(self, tf_example): 24 | """ 25 | Create a preprocessor chain inside of the tensorflow graph. 26 | """ 27 | pass 28 | 29 | 30 | @export 31 | @optional_params 32 | def register_preprocessor(cls, name=None): 33 | """Register a function as a plug-in""" 34 | return register(cls, BASELINE_PREPROCESSORS, name, 'preprocessor') 35 | 36 | 37 | @export 38 | def create_preprocessors(**kwargs): 39 | preprocessor_type = kwargs['preprocessor_type'] # fail early 40 | Constructor = BASELINE_PREPROCESSORS.get(preprocessor_type) 41 | if Constructor is None: 42 | raise NotImplementedError('no preproc exporter found for type {}'.format(preprocessor_type)) 43 | return Constructor(**kwargs) 44 | -------------------------------------------------------------------------------- /mead/pytorch/__init__.py: -------------------------------------------------------------------------------- 1 | from mead.pytorch.exporters import * 2 | -------------------------------------------------------------------------------- /mead/tf/__init__.py: -------------------------------------------------------------------------------- 1 | from mead.tf.exporters import * 2 | from mead.tf.preproc_exporters import * 3 | from mead.tf.preprocessors import * 4 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ['setuptools', 'wheel'] 3 | 4 | [tool.black] 5 | line-length = 120 6 | target-version = ['py36'] 7 | skip-string-normalization = 'true' 8 | -------------------------------------------------------------------------------- /scripts/download_all.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | from baseline.utils import read_json 4 | from mead.utils import index_by_label, convert_path 5 | from baseline.utils import EmbeddingDownloader, DataDownloader 6 | 7 | 8 | parser = argparse.ArgumentParser(description="Download all data and embeddings.") 9 | parser.add_argument("--cache", default="~/.bl-data", type=os.path.expanduser, help="Location of the data cache") 10 | parser.add_argument('--datasets', help='json library of dataset labels', default='config/datasets.json', type=convert_path) 11 | parser.add_argument('--embeddings', help='json library of embeddings', default='config/embeddings.json', type=convert_path) 12 | args = parser.parse_args() 13 | 14 | 15 | datasets = read_json(args.datasets) 16 | datasets = index_by_label(datasets) 17 | 18 | for name, d in datasets.items(): 19 | print(name) 20 | try: 21 | DataDownloader(d, args.cache).download() 22 | except Exception as e: 23 | print(e) 24 | 25 | 26 | emb = read_json(args.embeddings) 27 | emb = index_by_label(emb) 28 | 29 | for name, e in emb.items(): 30 | print(name) 31 | try: 32 | EmbeddingDownloader(e['file'], e['dsz'], e.get('sha1'), args.cache).download() 33 | except Exception as e: 34 | print(e) 35 | -------------------------------------------------------------------------------- /scripts/images/CosineLR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/scripts/images/CosineLR.png -------------------------------------------------------------------------------- /scripts/images/ExampleLR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/scripts/images/ExampleLR.png -------------------------------------------------------------------------------- /scripts/images/LR_Finder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/scripts/images/LR_Finder.png -------------------------------------------------------------------------------- /scripts/images/tagger_find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/scripts/images/tagger_find.png -------------------------------------------------------------------------------- /scripts/lr_compare.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import argparse 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | 7 | 8 | def plot_learning_rates(ys, names): 9 | fig, ax = plt.subplots(1, 1) 10 | ax.set_title('Learning Rates from baseline.') 11 | ax.set_xlabel('Steps') 12 | ax.set_ylabel('Learning Rates') 13 | for y, name in zip(ys, names): 14 | ax.plot(np.arange(len(y)), y, label=name) 15 | ax.legend() 16 | return fig 17 | 18 | 19 | def main(): 20 | parser = argparse.ArgumentParser(description="Compare various schedules") 21 | parser.add_argument("--index", default='.lrs/cache.index', help="The location of the lr index") 22 | args = parser.parse_args() 23 | 24 | dir_ = os.path.dirname(args.index) 25 | index = {} 26 | with open(args.index) as f: 27 | for line in f: 28 | line = json.loads(line) 29 | try: 30 | index[line['name']] = np.load(os.path.join(dir_, line['file'])) 31 | except: 32 | pass 33 | 34 | keys = index.keys() 35 | 36 | plot_learning_rates([index[k] for k in keys], keys) 37 | plt.tight_layout() 38 | plt.show() 39 | 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /scripts/speed_configs/conll-bio.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "batchsz": 10, 4 | "conll_output": "conll-bio-results.conll", 5 | "charsz": 30, 6 | "unif": 0.1, 7 | "preproc": { 8 | "mxlen": -1, 9 | "mxwlen": -1, 10 | "lower": true 11 | }, 12 | "backend": "tensorflow", 13 | "dataset": "conll-bio", 14 | "loader": { 15 | "reader_type": "default" 16 | }, 17 | "model": { 18 | "model_type": "default", 19 | "cfiltsz": [3], 20 | "hsz": 200, 21 | "wsz": 30, 22 | "dropout": 0.5, 23 | "rnntype": "blstm", 24 | "layers": 1, 25 | "crf_mask": true, 26 | "crf": 1 27 | }, 28 | 29 | "word_embeddings": { 30 | "label": "glove-6B-100" 31 | }, 32 | "train": { 33 | "epochs": 1, 34 | "optim": "sgd", 35 | "decay": 0.05, 36 | "eta": 0.015, 37 | "mom": 0.9, 38 | "patience": 40, 39 | "early_stopping_metric": "f1", 40 | "clip": 5.0, 41 | "span_type": "bio" 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /scripts/speed_configs/iwslt15-en-vi.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "seq2seq", 3 | "num_valid_to_show": 5, 4 | "batchsz": 30, 5 | "unif": 0.25, 6 | "preproc": { 7 | "mxlen": 100 8 | }, 9 | "backend": "tensorflow", 10 | "dataset": "iwslt15-en-vi", 11 | "loader": { 12 | "reader_type": "default", 13 | "pair_suffix": ["en", "vi"] 14 | }, 15 | "model": { 16 | "model_type": "attn", 17 | "rnntype": "blstm", 18 | "hsz": 200, 19 | "dropout": 0.5, 20 | "layers": 2 21 | }, 22 | 23 | "word_embeddings": { 24 | "dsz": 200 25 | }, 26 | "train": { 27 | "epochs": 1, 28 | "optim": "adam", 29 | "decay": 0, 30 | "eta": 0.001, 31 | "mom": 0.9, 32 | "patience": 20, 33 | "do_early_stopping": false, 34 | "clip": 1.0 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /scripts/speed_configs/ptb-convchar.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "lm", 3 | "batchsz": 20, 4 | "unif": 0.05, 5 | "nbptt": 35, 6 | "charsz": 16, 7 | "preproc": { 8 | "mxwlen": 40, 9 | "lower": true 10 | }, 11 | "backend": "tensorflow", 12 | "dataset": "ptb", 13 | "loader": { 14 | "reader_type": "default" 15 | }, 16 | "model": { 17 | "model_type": "convchar", 18 | "cfiltsz": [1,2,3,4,5,6,7], 19 | "nfeat_factor": 50, 20 | "hsz": 650, 21 | "layers": 2, 22 | "gating": "highway", 23 | "num_gates": 2 24 | }, 25 | "word_embeddings": { 26 | "dsz": 0 27 | }, 28 | "train": { 29 | "epochs": 1, 30 | "decay_rate": 1.6, 31 | "patience": 40000, 32 | "optim": "sgd", 33 | "start_decay_epoch": 10, 34 | "decay_type": "zaremba", 35 | "eta": 1.0, 36 | "mom": 0.0, 37 | "do_early_stopping": true, 38 | "clip": 5.0 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /scripts/speed_configs/ptb-med.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "lm", 3 | "batchsz": 20, 4 | "unif": 0.05, 5 | "nbptt": 35, 6 | "charsz": 16, 7 | "preproc": { 8 | "mxwlen": 40, 9 | "lower": true 10 | }, 11 | "backend": "dynet", 12 | "dataset": "ptb", 13 | "loader": { 14 | "reader_type": "default" 15 | }, 16 | "model": { 17 | "model_type": "default", 18 | "hsz": 650, 19 | "layers": 2 20 | }, 21 | "word_embeddings": { 22 | "label": "w2v-gn" 23 | }, 24 | "train": { 25 | "epochs": 1, 26 | "decay_rate": 1.2, 27 | "patience": 40000, 28 | "optim": "sgd", 29 | "start_decay_epoch": 6, 30 | "decay_type": "zaremba", 31 | "eta": 1.0, 32 | "mom": 0.0, 33 | "do_early_stopping": true, 34 | "clip": 5.0 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /scripts/speed_configs/sst2-lstm.yml: -------------------------------------------------------------------------------- 1 | task: 'classify' 2 | batchsz: 50 3 | preproc: 4 | mxlen: 100 5 | rev: true 6 | clean: true 7 | backend: keras 8 | dataset: SST2 9 | loader: 10 | reader_type: default 11 | unif: 0.25 12 | model: 13 | model_type: lstm 14 | hsz: 100 15 | dropout: 0.5 16 | finetune: true 17 | batched: true 18 | word_embeddings: 19 | label: w2v-gn 20 | train: 21 | epochs: 1 22 | optim: adam 23 | eta: 0.0001 24 | model_base: ./models/sst2 25 | early_stopping_metric: acc 26 | verbose: 27 | console: true 28 | file: "sst2-cm.csv" 29 | -------------------------------------------------------------------------------- /scripts/speed_configs/sst2.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "classify", 3 | "batchsz": 50, 4 | "preproc": { 5 | "mxlen": 100, 6 | "rev": false, 7 | "clean": true 8 | }, 9 | "backend": "tensorflow", 10 | "dataset": "SST2", 11 | "loader": { 12 | "reader_type": "default" 13 | }, 14 | "unif": 0.25, 15 | "model": { 16 | "model_type": "default", 17 | "filtsz": [3,4,5], 18 | "cmotsz": 100, 19 | "dropout": 0.5, 20 | "finetune": true, 21 | "batched": true 22 | }, 23 | "word_embeddings": { 24 | "label": "w2v-gn" 25 | }, 26 | "train": { 27 | "epochs": 2, 28 | "optim": "adadelta", 29 | "eta": 1.0, 30 | "model_base": "./models/sst2", 31 | "early_stopping_metric": "acc" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /scripts/speed_test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/scripts/speed_test/__init__.py -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | license_files = 3 | LICENSE 4 | NOTICE 5 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Writing tests 2 | 3 | # Dealing with the registry 4 | 5 | Baseline uses a global registry (explained [here](../docs/addons.md)) to handle both user defined and included models. This causes problems with testing where things try to overwrite each other when the tests are being collected. 6 | 7 | To fix this make sure that **all imports** that will import a registered things (models, vectorizers, embeddings, reporting hooks, readers, trainers, and fit funcs) are done inside of the tests themselves. 8 | 9 | 10 | ## Running tests 11 | 12 | Run tests with `pytest --forked`. This runs tests with each test in its own process. 13 | 14 | ## Versions 15 | 16 | Support python 2 and 3 in your tests. This means using the `mock` backport library to import `MagicMock` or `patch` rather than `unittest.mock` 17 | 18 | 19 | ## Frameworks 20 | 21 | There are a lot of optional dependencies that baseline has (various deep learning frameworks, pyyaml, etc). Then writing tests that depend on these libraries use `import_name = pytest.importorskip('import_name')` so that these tests will be skipped if the dependency is not installed. 22 | 23 | 24 | ## Accessing test data 25 | 26 | When accessing test data on disk make sure the paths are based on the location of the test file rather than relative paths based on the current working directory. This lets pytest be run from anywhere. 27 | 28 | ```python 29 | import os 30 | 31 | file_loc = os.path.realpath(os.path.dirname(__file__)) 32 | data_loc = os.path.join(file_loc, 'test_data') 33 | 34 | file_path = os.path.join(data_loc, 'file_name') 35 | ``` 36 | -------------------------------------------------------------------------------- /tests/export-config-classify-grpc.yml: -------------------------------------------------------------------------------- 1 | ERROR_COLOR: \033[0;31m 2 | MSG_COLOR: \033[0;32m 3 | END: \033[0m 4 | BASELINE_DIR: ${PWD}/../../ 5 | SERVING_CONTAINER_NAME: tfserving 6 | TASK: classify 7 | NUM_LINES_TO_REMOVE_LOAD: 0 8 | NUM_LINES_TO_REMOVE_SERVE: 0 9 | DRIVER: ${BASELINE_DIR}/api-examples/classify-text.py 10 | TEST_FILE: ${PWD}/stsa.binary.test 11 | TEST_FILE_LINK: https://www.dropbox.com/s/zm6y79wczkaliat/stsa.binary.test?dl=1 12 | MODEL_FILE: ${PWD}/sst2-8519.zip 13 | MODEL_FILE_LINK: https://www.dropbox.com/s/l3y8oi62le0uczc/sst2-8519.zip?dl=1 14 | CONFIG_FILE: ${PWD}/sst2-comb.json 15 | CONFIG_FILE_LINK: https://www.dropbox.com/s/77m4xjpb6rpm2fx/sst2-comb.json?dl=1 16 | MODEL_NAME: sst2 17 | EXPORT_DIR: ${PWD}/models 18 | EXPORT_DIR_PREPROC: ${PWD}/models-preproc 19 | EXPORT_SETTINGS_MEAD: ${BASELINE_DIR}/python/mead/config/mead-settings.json 20 | MODEL_VERSION: 1 21 | IS_REMOTE: false 22 | RETURN_LABELS: true 23 | REMOTE_HOST: localhost 24 | REMOTE_PORT: 8500 25 | SLEEP: 5 26 | CLEAN_AFTER_TEST: true 27 | TEST_LOAD: ${TEST_FILE}.load 28 | TEST_SERVE: ${TEST_FILE}.serve 29 | TEST_SERVE_PREPROC: ${TEST_FILE}.serve_preproc 30 | -------------------------------------------------------------------------------- /tests/export-config-classify-rest.yml: -------------------------------------------------------------------------------- 1 | ERROR_COLOR: \033[0;31m 2 | MSG_COLOR: \033[0;32m 3 | END: \033[0m 4 | BASELINE_DIR: ${PWD}/../../ 5 | SERVING_CONTAINER_NAME: tfserving 6 | TASK: classify 7 | NUM_LINES_TO_REMOVE_LOAD: 0 8 | NUM_LINES_TO_REMOVE_SERVE: 0 9 | DRIVER: ${BASELINE_DIR}/api-examples/classify-text.py 10 | TEST_FILE: ${PWD}/stsa.binary.test 11 | TEST_FILE_LINK: https://www.dropbox.com/s/zm6y79wczkaliat/stsa.binary.test?dl=1 12 | MODEL_FILE: ${PWD}/sst2-6475.zip 13 | MODEL_FILE_LINK: https://www.dropbox.com/s/pmeips3phwhmqbv/sst2-6475.zip?dl=1 14 | CONFIG_FILE: ${PWD}/sst2-comb.json 15 | CONFIG_FILE_LINK: https://www.dropbox.com/s/77m4xjpb6rpm2fx/sst2-comb.json?dl=1 16 | MODEL_NAME: sst2 17 | EXPORT_DIR: ${PWD}/models 18 | EXPORT_DIR_PREPROC: ${PWD}/models-preproc 19 | EXPORT_SETTINGS_MEAD: ${BASELINE_DIR}/python/mead/config/mead-settings.json 20 | EXPORT_SETTINGS_DATASETS: ${BASELINE_DIR}/python/mead/config/datasets.json 21 | MODEL_VERSION: 1 22 | IS_REMOTE: false 23 | RETURN_LABELS: true 24 | REMOTE_HOST: http://localhost 25 | REMOTE_PORT: 8501 26 | SLEEP: 5 27 | CLEAN_AFTER_TEST: true 28 | TEST_LOAD: ${TEST_FILE}.load 29 | TEST_SERVE: ${TEST_FILE}.serve 30 | TEST_SERVE_PREPROC: ${TEST_FILE}.serve_preproc 31 | -------------------------------------------------------------------------------- /tests/export-config-tagger-grpc.yml: -------------------------------------------------------------------------------- 1 | ERROR_COLOR: \033[0;31m 2 | MSG_COLOR: \033[0;32m 3 | END: \033[0m 4 | BASELINE_DIR: ${PWD}/../../ 5 | SERVING_CONTAINER_NAME: tfserving 6 | TASK: tagger 7 | NUM_LINES_TO_REMOVE_LOAD: 0 8 | NUM_LINES_TO_REMOVE_SERVE: 0 9 | DRIVER: ${BASELINE_DIR}/api-examples/tag-text.py 10 | TEST_FILE: eng.testb.small 11 | TEST_FILE_LINK: https://www.dropbox.com/s/pp3pcq5q5ko1df6/eng.testb.small?dl=1 12 | CONLL: false 13 | FEATURES: text 14 | MODEL_FILE: ${PWD}/conll-19231.zip 15 | MODEL_FILE_LINK: https://www.dropbox.com/s/agft8f1gbyt1w76/conll-19231.zip?dl=1 16 | CONFIG_FILE: ${PWD}/conll-tf.json 17 | CONFIG_FILE_LINK: https://www.dropbox.com/s/97bi7qy15usmvb2/conll-tf.json?dl=1 18 | MODEL_NAME: conll 19 | EXPORT_DIR: ${PWD}/models 20 | EXPORT_DIR_PREPROC: ${PWD}/models-preproc 21 | EXPORT_SETTINGS_MEAD: ${BASELINE_DIR}/python/mead/config/mead-settings.json 22 | MODEL_VERSION: 1 23 | IS_REMOTE: false 24 | RETURN_LABELS: true 25 | REMOTE_HOST: localhost 26 | REMOTE_PORT: 8500 27 | SLEEP: 5 28 | CLEAN_AFTER_TEST: true 29 | TEST_LOAD: ${TEST_FILE}.load 30 | TEST_SERVE: ${TEST_FILE}.serve 31 | TEST_SERVE_PREPROC: ${TEST_FILE}.serve_preproc 32 | -------------------------------------------------------------------------------- /tests/export-config-tagger-rest.yml: -------------------------------------------------------------------------------- 1 | ERROR_COLOR: \033[0;31m 2 | MSG_COLOR: \033[0;32m 3 | END: \033[0m 4 | BASELINE_DIR: ${PWD}/../../ 5 | SERVING_CONTAINER_NAME: tfserving 6 | TASK: tagger 7 | FEATURES: text 8 | NUM_LINES_TO_REMOVE_LOAD: 0 9 | NUM_LINES_TO_REMOVE_SERVE: 0 10 | DRIVER: ${BASELINE_DIR}/api-examples/tag-text.py 11 | TEST_FILE: eng.testb.small 12 | TEST_FILE_LINK: https://www.dropbox.com/s/pp3pcq5q5ko1df6/eng.testb.small?dl=1 13 | CONLL: false 14 | MODEL_FILE: ${PWD}/conll-11083.zip 15 | MODEL_FILE_LINK: https://www.dropbox.com/s/xbapm6moas24tjk/conll-11083.zip?dl=1 16 | CONFIG_FILE: ${PWD}/conll-tf.json 17 | CONFIG_FILE_LINK: https://www.dropbox.com/s/97bi7qy15usmvb2/conll-tf.json?dl=1 18 | MODEL_NAME: conll 19 | EXPORT_DIR: ${PWD}/models 20 | EXPORT_DIR_PREPROC: ${PWD}/models-preproc 21 | EXPORT_SETTINGS_MEAD: ${BASELINE_DIR}/python/mead/config/mead-settings.json 22 | EXPORT_SETTINGS_DATASETS: ${BASELINE_DIR}/python/mead/config/datasets.json 23 | MODEL_VERSION: 1 24 | IS_REMOTE: false 25 | RETURN_LABELS: true 26 | REMOTE_HOST: http://localhost 27 | REMOTE_PORT: 8501 28 | SLEEP: 5 29 | CLEAN_AFTER_TEST: true 30 | TEST_LOAD: ${TEST_FILE}.load 31 | TEST_SERVE: ${TEST_FILE}.serve 32 | TEST_SERVE_PREPROC: ${TEST_FILE}.serve_preproc 33 | -------------------------------------------------------------------------------- /tests/export-elmo-conll-rest.yml: -------------------------------------------------------------------------------- 1 | ERROR_COLOR: \033[0;31m 2 | MSG_COLOR: \033[0;32m 3 | END: \033[0m 4 | BASELINE_DIR: ${PWD}/../../ 5 | SERVING_CONTAINER_NAME: tfserving 6 | TASK: tagger 7 | FEATURES: text 8 | NUM_LINES_TO_REMOVE_LOAD: 0 9 | NUM_LINES_TO_REMOVE_SERVE: 0 10 | DRIVER: ${BASELINE_DIR}/api-examples/tag-text.py 11 | TEST_FILE: eng.testb.tiny 12 | TEST_FILE_LINK: https://www.dropbox.com/s/jn1fdd5kk0kzgv9/eng.testb.tiny?dl=1 13 | CONLL: false 14 | MODEL_FILE: ${PWD}/conll-elmo-16691.zip 15 | MODEL_FILE_LINK: https://www.dropbox.com/s/03euyv9bhlfv85c/conll-elmo-16691.zip?dl=1 16 | CONFIG_FILE: ${PWD}/conll-elmo-hub.yml 17 | CONFIG_FILE_LINK: https://www.dropbox.com/s/epldxo4m1s39q8w/conll-elmo-hub.yml?dl=1 18 | MODEL_NAME: conll 19 | EXPORT_DIR: ${PWD}/models 20 | EXPORT_DIR_PREPROC: ${PWD}/models-preproc 21 | EXPORT_SETTINGS_MEAD: ${BASELINE_DIR}/python/mead/config/mead-settings.json 22 | EXPORT_SETTINGS_DATASETS: ${BASELINE_DIR}/python/mead/config/datasets.json 23 | MODEL_VERSION: 1 24 | IS_REMOTE: false 25 | RETURN_LABELS: true 26 | REMOTE_HOST: http://localhost 27 | REMOTE_PORT: 8501 28 | SLEEP: 5 29 | CLEAN_AFTER_TEST: true 30 | TEST_LOAD: ${TEST_FILE}.load 31 | TEST_SERVE: ${TEST_FILE}.serve 32 | TEST_SERVE_PREPROC: ${TEST_FILE}.serve_preproc 33 | -------------------------------------------------------------------------------- /tests/export-elmo-sst2-rest.yml: -------------------------------------------------------------------------------- 1 | ERROR_COLOR: \033[0;31m 2 | MSG_COLOR: \033[0;32m 3 | END: \033[0m 4 | BASELINE_DIR: ${PWD}/../../ 5 | SERVING_CONTAINER_NAME: tfserving 6 | TASK: classify 7 | NUM_LINES_TO_REMOVE_LOAD: 0 8 | NUM_LINES_TO_REMOVE_SERVE: 0 9 | DRIVER: ${BASELINE_DIR}/api-examples/classify-text.py 10 | TEST_FILE: ${PWD}/stsa.binary.test.tiny 11 | TEST_FILE_LINK: https://www.dropbox.com/s/jgjgazt935rflkz/stsa.binary.test.tiny?dl=1 12 | MODEL_FILE: ${PWD}/sst2-14509.zip 13 | MODEL_FILE_LINK: https://www.dropbox.com/s/wz97lnee83hms7r/sst2-14509.zip?dl=1 14 | CONFIG_FILE: ${PWD}/sst2-elmo-hub.json 15 | CONFIG_FILE_LINK: https://www.dropbox.com/s/c5pjq5zrmhw21yo/sst2-elmo-hub.json?dl=1 16 | MODEL_NAME: sst2 17 | EXPORT_DIR: ${PWD}/models 18 | EXPORT_DIR_PREPROC: ${PWD}/models-preproc 19 | EXPORT_SETTINGS_MEAD: ${BASELINE_DIR}/python/mead/config/mead-settings.json 20 | EXPORT_SETTINGS_DATASETS: ${BASELINE_DIR}/python/mead/config/datasets.json 21 | MODEL_VERSION: 1 22 | IS_REMOTE: false 23 | RETURN_LABELS: false 24 | REMOTE_HOST: http://localhost 25 | REMOTE_PORT: 8501 26 | SLEEP: 5 27 | CLEAN_AFTER_TEST: true 28 | TEST_LOAD: ${TEST_FILE}.load 29 | TEST_SERVE: ${TEST_FILE}.serve 30 | TEST_SERVE_PREPROC: ${TEST_FILE}.serve_preproc 31 | -------------------------------------------------------------------------------- /tests/test_data/bert-base-uncased-vocab.txt: -------------------------------------------------------------------------------- 1 | [PAD] 2 | [UNK] 3 | [CLS] 4 | [SEP] 5 | [MASK] 6 | road 7 | wasn 8 | although 9 | due 10 | major 11 | died 12 | village 13 | third 14 | knew 15 | 2016 16 | asked 17 | turned 18 | st 19 | wanted 20 | say 21 | ##p 22 | together 23 | received 24 | main 25 | son 26 | served 27 | different 28 | ##en 29 | behind 30 | himself 31 | felt 32 | members 33 | power 34 | football 35 | law 36 | voice 37 | play 38 | ##in 39 | near 40 | park 41 | history 42 | 30 43 | having 44 | 2005 45 | 16 46 | ##man 47 | saw 48 | mother 49 | ##al 50 | army 51 | point 52 | front 53 | help 54 | english 55 | street 56 | art 57 | late 58 | hands 59 | games 60 | award 61 | ##ia 62 | young 63 | 14 64 | put 65 | published 66 | country 67 | division 68 | across 69 | told 70 | 13 71 | often 72 | ever 73 | french 74 | london 75 | center 76 | six 77 | red 78 | 2017 79 | led 80 | days 81 | include 82 | light 83 | 25 84 | find 85 | tell 86 | among 87 | species 88 | really 89 | according 90 | central 91 | half 92 | 2004 93 | form 94 | original 95 | gave 96 | office 97 | making 98 | enough 99 | lost 100 | full 101 | opened 102 | must 103 | included 104 | live 105 | given 106 | german 107 | player 108 | run 109 | business 110 | woman 111 | community 112 | cup 113 | might 114 | million 115 | land 116 | 2000 117 | court 118 | development 119 | 17 120 | short 121 | round 122 | ii 123 | km 124 | seen 125 | class 126 | story 127 | always 128 | become 129 | sure 130 | research 131 | almost 132 | director 133 | council 134 | la 135 | ##2 136 | career 137 | things 138 | -------------------------------------------------------------------------------- /tests/test_data/codes.30k: -------------------------------------------------------------------------------- 1 | t h 436867468 2 | o u 298369324 3 | i n 241109883 4 | th e 220105917 5 | a n 212895681 6 | < e 163525745 7 | r e 157200409 8 | ou > 151649762 9 | 151649762 10 | e r 131951759 11 | -------------------------------------------------------------------------------- /tests/test_data/config/datasets.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "train_file": "/data/datasets/test/toy.conll", 4 | "valid_file": "/data/datasets/test/toy.conll", 5 | "test_file": "/data/datasets/test/toy.conll", 6 | "label": "test" 7 | } 8 | ] -------------------------------------------------------------------------------- /tests/test_data/config/embeddings.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "label": "glove-6B-100", 4 | "file": "/data/embeddings/glove.6B.100d.txt", 5 | "dsz": 100 6 | } 7 | ] -------------------------------------------------------------------------------- /tests/test_data/config/test_tagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "task": "tagger", 3 | "batchsz": 1, 4 | "conll_output": "conllresults.conll", 5 | "test_thresh": 10, 6 | "charsz": 5, 7 | "unif": 0.1, 8 | "preproc": { 9 | "mxlen": -1, 10 | "mxwlen": -1, 11 | "lower": true 12 | }, 13 | "backend": "tensorflow", 14 | "dataset": "test", 15 | "loader": { 16 | "reader_type": "default" 17 | }, 18 | "model": { 19 | "model_type": "default", 20 | "cfiltsz": [3], 21 | "hsz": 5, 22 | "wsz": 5, 23 | "dropout": 0.5, 24 | "rnntype": "blstm", 25 | "layers": 1, 26 | "crf_mask": true, 27 | "crf": 1 28 | }, 29 | 30 | "word_embeddings": { 31 | "label": "glove-6B-100" 32 | }, 33 | "train": { 34 | "epochs": 10, 35 | "optim": "sgd", 36 | "eta": 0.015, 37 | "mom": 0.9, 38 | "patience": 5, 39 | "early_stopping_metric": "f1", 40 | "clip": 5.0, 41 | "span_type": "iobes" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/test_data/crf_vocab: -------------------------------------------------------------------------------- 1 | { 2 | "": 0, 3 | "": 1, 4 | "": 2, 5 | "B-ORG": 3, 6 | "O": 4, 7 | "B-MISC": 5, 8 | "B-PER": 6, 9 | "I-PER": 7, 10 | "B-LOC": 8, 11 | "I-ORG": 9, 12 | "I-MISC": 10, 13 | "I-LOC": 11 14 | } 15 | -------------------------------------------------------------------------------- /tests/test_data/eng.testb.small.conll: -------------------------------------------------------------------------------- 1 | SOCCER NN I-NP O 2 | - : O O 3 | JAPAN NNP I-NP I-LOC 4 | GET VB I-VP O 5 | LUCKY NNP I-NP O 6 | WIN NNP I-NP O 7 | , , O O 8 | CHINA NNP I-NP I-PER 9 | IN IN I-PP O 10 | SURPRISE DT I-NP O 11 | DEFEAT NN I-NP O 12 | . . O O 13 | 14 | Nadim NNP I-NP I-PER 15 | Ladki NNP I-NP I-PER 16 | 17 | AL-AIN NNP I-NP I-LOC 18 | , , O O 19 | United NNP I-NP I-LOC 20 | Arab NNP I-NP I-LOC 21 | Emirates NNPS I-NP I-LOC 22 | 1996-12-06 CD I-NP O 23 | 24 | Japan NNP I-NP I-LOC 25 | began VBD I-VP O 26 | the DT I-NP O 27 | defence NN I-NP O 28 | of IN I-PP O 29 | their PRP$ I-NP O 30 | Asian JJ I-NP I-MISC 31 | Cup NNP I-NP I-MISC 32 | title NN I-NP O 33 | with IN I-PP O 34 | a DT I-NP O 35 | lucky JJ I-NP O 36 | 2-1 CD I-NP O 37 | win VBP I-VP O 38 | against IN I-PP O 39 | Syria NNP I-NP I-LOC 40 | in IN I-PP O 41 | a DT I-NP O 42 | Group NNP I-NP O 43 | C NNP I-NP O 44 | championship NN I-NP O 45 | match NN I-NP O 46 | on IN I-PP O 47 | Friday NNP I-NP O 48 | . . O O 49 | 50 | But CC O O 51 | China NNP I-NP I-LOC 52 | saw VBD I-VP O 53 | their PRP$ I-NP O 54 | luck NN I-NP O 55 | desert VB I-VP O 56 | them PRP I-NP O 57 | in IN I-PP O 58 | the DT I-NP O 59 | second NN I-NP O 60 | match NN I-NP O 61 | of IN I-PP O 62 | the DT I-NP O 63 | group NN I-NP O 64 | , , O O 65 | crashing VBG I-VP O 66 | to TO I-PP O 67 | a DT I-NP O 68 | surprise NN I-NP O 69 | 2-0 CD I-NP O 70 | defeat NN I-NP O 71 | to TO I-PP O 72 | newcomers NNS I-NP O 73 | Uzbekistan NNP I-NP I-LOC 74 | . . O O 75 | 76 | China NNP I-NP I-LOC 77 | controlled VBD I-VP O 78 | most JJS I-NP O 79 | of IN I-PP O 80 | the DT I-NP O 81 | match NN I-NP O 82 | and CC O O 83 | saw VBD I-VP O 84 | several JJ I-NP O 85 | chances NNS I-NP O 86 | missed VBD I-VP O 87 | until IN I-SBAR O 88 | the DT I-NP O 89 | 78th JJ I-NP O 90 | minute NN I-NP O 91 | when WRB I-ADVP O 92 | Uzbek NNP I-NP I-MISC 93 | striker NN I-NP O 94 | Igor JJ B-NP I-PER 95 | Shkvyrin NNP I-NP I-PER 96 | took VBD I-VP O 97 | advantage NN I-NP O 98 | of IN I-PP O 99 | a DT I-NP O 100 | misdirected JJ I-NP O 101 | defensive JJ I-NP O 102 | header NN I-NP O 103 | to TO I-VP O 104 | lob VB I-VP O 105 | the DT I-NP O 106 | ball NN I-NP O 107 | over IN I-PP O 108 | the DT I-NP O 109 | advancing VBG I-NP O 110 | Chinese JJ I-NP I-MISC 111 | keeper NN I-NP O 112 | and CC O O 113 | into IN I-PP O 114 | an DT I-NP O 115 | empty JJ I-NP O 116 | net NN I-NP O 117 | . . O O 118 | 119 | -------------------------------------------------------------------------------- /tests/test_data/eng.testb.small.txt: -------------------------------------------------------------------------------- 1 | SOCCER - JAPAN GET LUCKY WIN , CHINA IN SURPRISE DEFEAT . 2 | Nadim Ladki 3 | AL-AIN , United Arab Emirates 1996-12-06 4 | Japan began the defence of their Asian Cup title with a lucky 2-1 win against Syria in a Group C championship match on Friday . 5 | But China saw their luck desert them in the second match of the group , crashing to a surprise 2-0 defeat to newcomers Uzbekistan . 6 | China controlled most of the match and saw several chances missed until the 78th minute when Uzbek striker Igor Shkvyrin took advantage of a misdirected defensive header to lob the ball over the advancing Chinese keeper and into an empty net . 7 | -------------------------------------------------------------------------------- /tests/test_data/multi_col.txt: -------------------------------------------------------------------------------- 1 | one one2 one two 2 | two two2 three four 3 | three three2 five six 4 | four four2 seven eight 5 | five five2 nine ten 6 | -------------------------------------------------------------------------------- /tests/test_data/multi_parallel.1: -------------------------------------------------------------------------------- 1 | a a a 2 | c c 3 | e 4 | -------------------------------------------------------------------------------- /tests/test_data/multi_parallel.2: -------------------------------------------------------------------------------- 1 | b b b 2 | d d 3 | f 4 | -------------------------------------------------------------------------------- /tests/test_data/single_col.txt: -------------------------------------------------------------------------------- 1 | one 2 | two 3 | three 4 | four 5 | five 6 | -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855-char.vocab: -------------------------------------------------------------------------------- 1 | {"": 0, "R": 1, "I": 2, "C": 3, "K": 4, "E": 5, "T": 6, "-": 7, "L": 8, "S": 9, "H": 10, "A": 11, "O": 12, "V": 13, "P": 14, "F": 15, "N": 16, "G": 17, "Y": 18, ".": 19, "D": 20, "1": 21, "9": 22, "6": 23, "0": 24, "8": 25, "3": 26, "W": 27, "e": 28, "s": 29, "t": 30, "n": 31, "d": 32, "i": 33, "a": 34, "l": 35, "r": 36, "o": 37, "u": 38, "h": 39, "m": 40, "k": 41, "f": 42, "y": 43, "c": 44, "b": 45, "g": 46, "w": 47, "v": 48, "p": 49} -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855-word.vocab: -------------------------------------------------------------------------------- 1 | {"the": 1, ".": 2, "of": 3, "to": 4, "and": 5, "in": 6, "for": 7, "-": 8, "on": 9, "as": 10, "by": 11, "at": 12, "an": 13, "after": 14, "two": 15, "over": 16, "four": 17, "friday": 18, "take": 19, "top": 20, "took": 21, "days": 22, "west": 23, "head": 24, "county": 25, "london": 26, "victory": 27, "indian": 28, "championship": 29, "beat": 30, "runs": 31, "innings": 32, "38": 33, "39": 34, "phil": 35, "somerset": 36, "simmons": 37, "leicestershire": 38, "all-rounder": 39, "": 0, "": 40, "ricket": 41, "1996-08-30": 42, "-docstart-": 43} -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/tests/test_data/tagger_model/tagger-model-tf-21855.data-00000-of-00001 -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.graph: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/tests/test_data/tagger_model/tagger-model-tf-21855.graph -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/tests/test_data/tagger_model/tagger-model-tf-21855.index -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.labels: -------------------------------------------------------------------------------- 1 | {"": 0, "": 1, "": 2, "O": 3, "I-ORG": 4, "I-LOC": 5, "I-MISC": 6, "I-PER": 7} -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/tests/test_data/tagger_model/tagger-model-tf-21855.meta -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.saver: -------------------------------------------------------------------------------- 1 | filename_tensor_name: "save/Const:0" 2 | save_tensor_name: "save/control_dependency:0" 3 | restore_op_name: "save/restore_all" 4 | max_to_keep: 5 5 | keep_checkpoint_every_n_hours: 10000.0 6 | version: V2 7 | -------------------------------------------------------------------------------- /tests/test_data/tagger_model/tagger-model-tf-21855.state: -------------------------------------------------------------------------------- 1 | {"mxlen": 35, "maxw": 14, "crf": true, "proj": false, "crf_mask": true, "span_type": "iobes"} -------------------------------------------------------------------------------- /tests/test_data/test.conll: -------------------------------------------------------------------------------- 1 | # begin doc 2 | # This is a comment 3 | a 1 2 4 | b 3 4 5 | c 5 6 6 | 7 | # This is the second sentence 8 | # This is an extra comment 9 | d 7 8 10 | e 9 10 11 | 12 | # end doc 13 | # begin doc 14 | g 11 12 15 | h 13 14 16 | # ex 44 17 | i 15 16 18 | j 17 18 19 | 20 | # 2 2 21 | k 19 20 22 | 23 | # begin doc 24 | l 21 22 25 | m 23 24 26 | n 25 26 27 | 28 | o 27 28 29 | p 29 30 30 | -------------------------------------------------------------------------------- /tests/test_data/test_json.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": 1, 3 | "b": { 4 | "c": 2 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/test_data/test_yaml.yml: -------------------------------------------------------------------------------- 1 | a: 1 2 | b: 3 | c: 2 4 | -------------------------------------------------------------------------------- /tests/test_data/tsv_parallel.tsv: -------------------------------------------------------------------------------- 1 | a a a b b b 2 | c c d d 3 | e f 4 | -------------------------------------------------------------------------------- /tests/test_data/tsv_unstruct_file.tsv: -------------------------------------------------------------------------------- 1 | 1 a a a b 2 | 2 b c d e 3 | 3 f g h i 4 | -------------------------------------------------------------------------------- /tests/test_data/vocab.30k: -------------------------------------------------------------------------------- 1 | . 228857497 2 | the 219659921 3 | 151649762 4 | , 118023819 5 | to 111336263 6 | i 109998194 7 | and 106973872 8 | a 100123582 9 | it 61605929 10 | you 59906129 11 | -------------------------------------------------------------------------------- /tests/test_data/w2v_test.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mead-ml/mead-baseline/5d7632bb151c2d09501ebf49f36ba8c4204df4c8/tests/test_data/w2v_test.bin -------------------------------------------------------------------------------- /tests/test_layers_tf2.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | from eight_mile.utils import get_version 4 | tf = pytest.importorskip('tensorflow') 5 | pytestmark = pytest.mark.skipif(get_version(tf) < 2, reason="TF1.X") 6 | from eight_mile.utils import Offsets 7 | from eight_mile.tf.layers import infer_lengths 8 | 9 | B = 10 10 | T = 15 11 | TRIALS = 100 12 | 13 | @pytest.fixture 14 | def lengths(): 15 | lengths = np.random.randint(1, T, size=(B,)).astype(np.int32) 16 | return lengths 17 | 18 | 19 | def generate_data_with_zeros(lengths): 20 | data = np.random.randint(1, 100, (len(lengths), np.max(lengths))).astype(np.int32) 21 | for i, length in enumerate(lengths): 22 | data[i, length:] = 0 23 | if length // 2 > 0: 24 | extra_zeros = np.random.randint(0, length.item() - 1, size=((length // 2).item(),)) 25 | data[i, extra_zeros] = 0 26 | return data 27 | 28 | 29 | def test_infer_lengths(lengths): 30 | def test(): 31 | data = generate_data_with_zeros(lengths) 32 | data = tf.convert_to_tensor(data) 33 | infered = infer_lengths(data, axis=1) 34 | np.testing.assert_allclose(infered.numpy(), lengths) 35 | 36 | for _ in range(TRIALS): 37 | test() 38 | 39 | 40 | def test_infer_lengths_t_first(lengths): 41 | def test(): 42 | data = generate_data_with_zeros(lengths) 43 | data = tf.convert_to_tensor(data) 44 | data = tf.transpose(data) 45 | infered = infer_lengths(data, axis=0) 46 | np.testing.assert_allclose(infered.numpy(), lengths) 47 | 48 | for _ in range(TRIALS): 49 | test() 50 | 51 | 52 | def test_infer_lengths_multi_dim(): 53 | data = tf.random.uniform((10, 11, 12)) 54 | with pytest.raises(ValueError): 55 | infer_lengths(data, axis=1) 56 | -------------------------------------------------------------------------------- /tests/test_mead_tasks.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | from mead.tasks import Task 4 | 5 | 6 | def test_get_min_f_loader_backoff(): 7 | name = 'a' 8 | gold_val = np.random.randint(5, 10) 9 | fake = np.random.randint(10, 100) 10 | c = { 11 | 'features': [{'name': name}], 12 | 'loader': { 13 | 'min_f': gold_val 14 | }, 15 | 'preproc': { 16 | 'min_f': fake 17 | }, 18 | } 19 | gold = {name: gold_val} 20 | cutoffs = Task._get_min_f(c) 21 | assert cutoffs == gold 22 | 23 | 24 | def test_get_min_f_preproc_backoff(): 25 | name = 'a' 26 | gold_val = np.random.randint(5, 10) 27 | c = { 28 | 'features': [{'name': name}], 29 | 'loader': { 30 | }, 31 | 'preproc': { 32 | 'min_f': gold_val 33 | }, 34 | } 35 | gold = {name: gold_val} 36 | cutoffs = Task._get_min_f(c) 37 | assert cutoffs == gold 38 | 39 | 40 | def test_get_min_f_no_backoff(): 41 | name = 'a' 42 | default = -1 43 | c = { 44 | 'features': [{'name': name}], 45 | 'loader': { 46 | }, 47 | } 48 | gold = {name: default} 49 | cutoffs = Task._get_min_f(c) 50 | assert cutoffs == gold 51 | 52 | 53 | def test_get_min_f_for_each_feature(): 54 | names = ['a', 'b'] 55 | gold_vals = np.random.randint(5, 10, size=len(names)) 56 | c = { 57 | 'features': [{'name': n, 'min_f': mf} for n, mf in zip(names, gold_vals)], 58 | 'loader': {}, 59 | } 60 | gold = {n: m for n, m in zip(names, gold_vals)} 61 | cutoffs = Task._get_min_f(c) 62 | assert cutoffs == gold 63 | 64 | 65 | def test_get_min_f_each_feat_preset(): 66 | names = np.random.choice(np.arange(1000), replace=False, size=np.random.randint(10, 100)) 67 | c = { 68 | 'features': [{'name': n for n in names}], 69 | 'loader': {}, 70 | } 71 | cutoffs = Task._get_min_f(c) 72 | for name in names: 73 | assert name in names 74 | 75 | 76 | -------------------------------------------------------------------------------- /tests/test_parse_extra_args.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from mead.utils import parse_extra_args 3 | 4 | 5 | def test_all_base_name_appear(): 6 | base_names = ['a', 'b'] 7 | reporting = parse_extra_args(base_names, []) 8 | for name in base_names: 9 | assert name in reporting 10 | 11 | 12 | def test_all_special_names_grabbed(): 13 | base_names = ['a', 'b'] 14 | special_names = ['a:one', 'a:two'] 15 | gold_special_names = ['one', 'two'] 16 | reporting = parse_extra_args(base_names, special_names) 17 | for gold in gold_special_names: 18 | assert gold in reporting['a'] 19 | 20 | 21 | def test_nothing_if_no_special(): 22 | base_names = ['a', 'b'] 23 | special_names = ['a:one', 'a:two'] 24 | reporting = parse_extra_args(base_names, special_names) 25 | assert {} == reporting['b'] 26 | 27 | 28 | def test_special_names_multiple_bases(): 29 | base_names = ['a', 'b'] 30 | special_names = ['a:one', 'b:two'] 31 | reporting = parse_extra_args(base_names, special_names) 32 | assert 'one' in reporting['a'] 33 | assert 'two' not in reporting['a'] 34 | assert 'two' in reporting['b'] 35 | assert 'one' not in reporting['b'] 36 | 37 | 38 | def test_special_shared_across_base(): 39 | base_names = ['a', 'b'] 40 | special_names = ['--b:one', 'b', '--a:one', 'a'] 41 | reporting = parse_extra_args(base_names, special_names) 42 | for name in base_names: 43 | assert 'one' in reporting[name] 44 | assert reporting[name]['one'] == name 45 | 46 | 47 | # This depends on `argparse` atm which should be mocked out eventually 48 | def test_values_are_grabbed(): 49 | base_names = ['a', 'b'] 50 | special_names = ['--a:xxx', 'xxx', '--a:yyy', 'yyy', '--b:zzz', 'zzz'] 51 | reporting = parse_extra_args(base_names, special_names) 52 | for name in base_names: 53 | for special, value in reporting[name].items(): 54 | assert special == value 55 | 56 | def test_extra_things_ignored(): 57 | base_names = ['b'] 58 | special_names = ['a:one'] 59 | reporting = parse_extra_args(base_names, special_names) 60 | assert {} == reporting['b'] 61 | 62 | 63 | def test_no_base_names(): 64 | base_names = [] 65 | special_names = ["--visdom:name", "sst2"] 66 | reporting = parse_extra_args(base_names, special_names) 67 | assert {} == reporting 68 | -------------------------------------------------------------------------------- /tests/test_pytorch_weight_sharing.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | 4 | torch = pytest.importorskip("torch") 5 | import torch.nn as nn 6 | from eight_mile.pytorch.layers import pytorch_linear 7 | 8 | 9 | class TiedWeights(nn.Module): 10 | def __init__(self): 11 | super().__init__() 12 | self.tgt_embeddings = nn.Embedding(100, 10) # vsz, dsz 13 | self.preds = pytorch_linear(10, 100) # hsz, output_sz 14 | self.preds.weight = self.tgt_embeddings.weight # tied weights 15 | 16 | def forward(self, input_vec): 17 | return self.preds(self.tgt_embeddings(input_vec)) 18 | 19 | 20 | def test_weight_tying(): 21 | model = TiedWeights() 22 | model.train() 23 | 24 | loss_fn = nn.MSELoss() 25 | 26 | optim = torch.optim.Adam([p for p in model.parameters() if p.requires_grad]) 27 | steps = 0 28 | epoch_loss, epoch_accuracy = 0, 0 29 | for idx in range(100): 30 | inputs, targets = random_ints(10), random_floats(10) 31 | 32 | likelihood = model(inputs) 33 | 34 | loss = loss_fn(likelihood, targets) 35 | 36 | loss.backward() 37 | optim.step() 38 | 39 | assert torch.equal(model.tgt_embeddings.weight, model.preds.weight) 40 | 41 | 42 | def test_weight_tying_cuda(): 43 | if not torch.cuda.is_available(): 44 | pytest.skip("Cuda not available") 45 | 46 | model = TiedWeights().cuda() 47 | model.train() 48 | 49 | loss_fn = nn.MSELoss() 50 | 51 | optim = torch.optim.Adam([p for p in model.parameters() if p.requires_grad]) 52 | steps = 0 53 | epoch_loss, epoch_accuracy = 0, 0 54 | for idx in range(100): 55 | inputs, targets = random_ints(10), random_floats(10) 56 | inputs = inputs.cuda() 57 | targets = targets.cuda() 58 | 59 | likelihood = model(inputs) 60 | 61 | loss = loss_fn(likelihood, targets) 62 | 63 | loss.backward() 64 | optim.step() 65 | 66 | assert torch.equal(model.tgt_embeddings.weight, model.preds.weight) 67 | 68 | 69 | def random_ints(size): 70 | return torch.tensor(np.random.randint(0, 100, size=size)) 71 | 72 | 73 | def random_floats(size): 74 | return torch.rand(size, 100) 75 | # return torch.tensor(np.random.randint(0, 100, size=size)) 76 | -------------------------------------------------------------------------------- /tests/test_sample.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | from baseline.utils import topk 4 | 5 | @pytest.fixture 6 | def setup(): 7 | input_ = np.random.rand(100) 8 | k = np.random.randint(2, 20) 9 | top = np.random.choice(np.arange(len(input_)), size=k, replace=False) 10 | add = np.max(input_) + np.arange(1, len(top) + 1) 11 | input_[top] = add 12 | return input_, top, k 13 | 14 | 15 | def test_k_drawn(setup): 16 | input_, top, k = setup 17 | result = topk(k, input_) 18 | assert len(result) == k 19 | 20 | 21 | def test_k_are_correct(setup): 22 | input_, top, k = setup 23 | result = topk(k, input_) 24 | for x in top: 25 | assert x in result 26 | 27 | 28 | def test_k_in_order(setup): 29 | input_, top, k = setup 30 | result = topk(k, input_) 31 | start = -1e4 32 | for x in top: 33 | assert result[x] > start 34 | start = result[x] 35 | 36 | 37 | def test_k_values_are_correct(setup): 38 | input_, top, k = setup 39 | result = topk(k, input_) 40 | for k, v in result.items(): 41 | assert v == input_[k] 42 | -------------------------------------------------------------------------------- /tests/test_tag_text.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | CONLL_FILE=test_data/eng.testb.small.conll 3 | TEXT_FILE=test_data/eng.testb.small.txt 4 | TAGGER_DRIVER=../../api-examples/tag-text.py 5 | MODEL_LINK=https://www.dropbox.com/s/ftv4amoq7dzxnxo/conll-6419.zip?dl=1 6 | MODEL_FILE=conll-6419.zip 7 | 8 | ERROR_COLOR='\033[0;31m' 9 | MSG_COLOR='\033[0;32m' 10 | END='\033[0m' 11 | 12 | if [ ! -f $MODEL_FILE ]; 13 | then 14 | wget $MODEL_LINK -O $MODEL_FILE 15 | fi 16 | 17 | function check_diff { 18 | DIFF=$(diff $1 $2) 19 | if [ "$DIFF" != "" ] 20 | then 21 | printf "${ERROR_COLOR}Tagger outputs $1 and $2 dont match, test failed \n${END}" 22 | exit 1 23 | fi 24 | } 25 | 26 | python ${TAGGER_DRIVER} --model ${MODEL_FILE} --text ${TEXT_FILE} > tmp1 27 | python ${TAGGER_DRIVER} --model ${MODEL_FILE} --text ${CONLL_FILE} --conll true > tmp2 28 | check_diff tmp1 tmp2 29 | python ${TAGGER_DRIVER} --model ${MODEL_FILE} --text ${CONLL_FILE} --feature text --conll true > tmp3 30 | check_diff tmp2 tmp3 31 | python ${TAGGER_DRIVER} --model ${MODEL_FILE} --text ${CONLL_FILE} --feature text:0 --conll true > tmp4 32 | check_diff tmp3 tmp4 33 | 34 | printf "${MSG_COLOR}Tagger outputs match, test passed\n${END}" 35 | rm tmp1 36 | rm tmp2 37 | rm tmp3 38 | rm tmp4 39 | -------------------------------------------------------------------------------- /tests/test_torchy.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | torch = pytest.importorskip('torch') 4 | from baseline.utils import Offsets 5 | from baseline.pytorch.torchy import SequenceCriterion 6 | 7 | C = 10 8 | B = 50 9 | S = 20 10 | 11 | 12 | @pytest.fixture 13 | def lengths(): 14 | lengths = torch.randint(1, S, size=(B,)).long() 15 | return lengths 16 | 17 | 18 | @pytest.fixture 19 | def logits(lengths): 20 | logits = torch.rand(B, S, C) 21 | for i, l in enumerate(lengths): 22 | logits[i, l:, :] = 0 23 | return logits 24 | 25 | 26 | @pytest.fixture 27 | def labels(lengths): 28 | lab = torch.randint(1, C, size=(B, S)).long() 29 | for i, l in enumerate(lengths): 30 | lab[i, l:] = 0 31 | return lab 32 | 33 | 34 | def raw_loss(logits, labels, loss): 35 | B, T, H = logits.size() 36 | crit = loss(reduce=False, ignore_index=Offsets.PAD) 37 | total_size = labels.nelement() 38 | res = crit(logits.view(total_size, -1), labels.view(total_size)) 39 | return res.view(B, T) 40 | 41 | 42 | def test_batch_sequence_loss(logits, labels): 43 | loss = torch.nn.CrossEntropyLoss 44 | raw = raw_loss(logits, labels, loss) 45 | gold = torch.mean(torch.sum(raw, dim=1)) 46 | crit = SequenceCriterion(LossFn=loss, avg='batch') 47 | res = crit(logits, labels) 48 | np.testing.assert_allclose(res.numpy(), gold.numpy(), rtol=1e-6) 49 | 50 | 51 | def test_token_sequence_loss(logits, labels, lengths): 52 | loss = torch.nn.CrossEntropyLoss 53 | raw = raw_loss(logits, labels, loss) 54 | gold = torch.sum(raw) / torch.sum(lengths).to(logits.dtype) 55 | crit = SequenceCriterion(LossFn=loss, avg='token') 56 | res = crit(logits, labels) 57 | np.testing.assert_allclose(res.numpy(), gold.numpy(), rtol=1e-6) 58 | -------------------------------------------------------------------------------- /tests/test_windowed_ra_pytorch.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pytest 3 | torch = pytest.importorskip("torch") 4 | from eight_mile.pytorch.layers import SeqScaledDotProductRelativeAttention, SeqScaledWindowedRelativeAttention, sequence_mask 5 | 6 | 7 | def make_rpr(rpr_key_emb, rpr_value_emb, rpr_k, seq_len): 8 | seq = torch.arange(seq_len) 9 | window_len = 2 * rpr_k 10 | edges = seq.view(1, -1) - seq.view(-1, 1) + rpr_k 11 | edges = torch.clamp(edges, 0, window_len) 12 | return rpr_key_emb(edges), rpr_value_emb(edges) 13 | 14 | 15 | def unfold_rpr(rpr_key_emb, rpr_value_emb, rpr_k): 16 | window_len = 2 * rpr_k + 1 17 | window = torch.arange(window_len) 18 | return rpr_key_emb(window), rpr_value_emb(window) 19 | 20 | 21 | def test_windowed_ra(): 22 | num_heads = 4 23 | d_model = 64 24 | rpr_k = 1 25 | batchsize = 2 26 | nctx = 12 27 | d_k = d_model // num_heads 28 | 29 | old = SeqScaledDotProductRelativeAttention(pdrop=0.) 30 | new = SeqScaledWindowedRelativeAttention(pdrop=0.) 31 | 32 | rpr_key_emb = torch.nn.Embedding(2 * rpr_k + 1, d_k) 33 | rpr_value_emb = torch.nn.Embedding(2 * rpr_k + 1, d_k) 34 | 35 | Q = torch.randn(batchsize, num_heads, nctx, d_k) 36 | K = torch.randn(batchsize, num_heads, nctx, d_k) 37 | V = torch.randn(batchsize, num_heads, nctx, d_k) 38 | lengths = torch.randint(2, nctx, [batchsize, ]) 39 | seq_mask = sequence_mask(lengths, max_len=nctx) 40 | in_mask = seq_mask.unsqueeze(1).unsqueeze(1) # [B, 1, 1, T] 41 | out_mask = seq_mask.unsqueeze(1).unsqueeze(-1) # [B, 1, T, 1] 42 | 43 | # manually create a ra_mask to prevent attention beyond rpr_k 44 | ones = torch.ones(nctx, nctx) 45 | ra_mask = torch.triu(ones, diagonal=-rpr_k) - torch.triu(ones, diagonal=rpr_k + 1) 46 | mask = in_mask * ra_mask.unsqueeze(0).unsqueeze(0) 47 | rpr_key_old, rpr_value_old = make_rpr(rpr_key_emb, rpr_value_emb, rpr_k, nctx) 48 | old.eval() 49 | out_old = old((Q, K, V, rpr_key_old, rpr_value_old, mask)) 50 | out_old = out_old.masked_fill(out_mask == False, 1).detach().numpy() 51 | print(out_old.shape) 52 | 53 | # using the windowed relative attention with the original sequence mask 54 | rpr_key_new, rpr_value_new = unfold_rpr(rpr_key_emb, rpr_value_emb, rpr_k) 55 | new.eval() 56 | out_new = new((Q, K, V, rpr_key_new, rpr_value_new, in_mask)) 57 | out_new = out_new.masked_fill(out_mask == False, 1).detach().numpy() 58 | print(out_new.shape) 59 | 60 | assert np.allclose(out_old, out_new, atol=1e-6) 61 | --------------------------------------------------------------------------------