├── .flake8 ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── feature_request.yml │ └── question.yml └── pull_request_template.md ├── .gitignore ├── .pre-commit-config.yaml ├── .pre-commit-config_local.yaml ├── CODE_OF_CONDUCT.md ├── CODE_OF_CONDUCT_zh.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── README_zh.md ├── adaseq ├── __init__.py ├── commands │ ├── __init__.py │ ├── pretrain.py │ ├── subcommand.py │ ├── test.py │ └── train.py ├── data │ ├── __init__.py │ ├── batch.py │ ├── constant.py │ ├── data_collators │ │ ├── __init__.py │ │ ├── base.py │ │ ├── multilabel_typing_data_collator_with_padding.py │ │ ├── pretraining_data_collator_with_padding.py │ │ ├── sequence_labeling_data_collator_with_padding.py │ │ ├── span_extraction_data_collator_with_padding.py │ │ ├── twostage_data_collator_with_padding.py │ │ └── word_extraction_data_collator_with_padding.py │ ├── dataset_builders │ │ ├── __init__.py │ │ ├── base.py │ │ ├── entity_typing_dataset_builder.py │ │ ├── mcce_entity_typing_dataset_builder.py │ │ ├── named_entity_recognition_dataset_builder.py │ │ └── relation_extraction_dataset_builder.py │ ├── dataset_dumpers │ │ ├── __init__.py │ │ ├── base.py │ │ └── named_entity_recognition_dataset_dumper.py │ ├── dataset_manager.py │ ├── preprocessors │ │ ├── __init__.py │ │ ├── multilabel_typing_preprocessor.py │ │ ├── nlp_preprocessor.py │ │ ├── pretraining_preprocessor.py │ │ ├── relation_extraction_preprocessor.py │ │ ├── sequence_labeling_preprocessor.py │ │ ├── span_extraction_preprocessor.py │ │ ├── twostage_preprocessor.py │ │ └── word_extraction_preprocessor.py │ ├── span_utils.py │ ├── tokenizer.py │ └── utils.py ├── exporters │ ├── __init__.py │ ├── base.py │ ├── multilabel_typing_model_exporter.py │ └── sequence_labeling_model_exporter.py ├── main.py ├── metainfo.py ├── metrics │ ├── __init__.py │ ├── pretraining_metric.py │ ├── relation_extraction_metric.py │ ├── sequence_labeling_metric.py │ ├── span_extraction_metric.py │ └── typing_metric.py ├── models │ ├── __init__.py │ ├── base.py │ ├── biaffine_ner_model.py │ ├── global_pointer_model.py │ ├── multilabel_typing_model.py │ ├── pretraining_model.py │ ├── relation_extraction_model.py │ ├── sequence_labeling_model.py │ ├── twostage_ner_model.py │ ├── utils.py │ └── w2ner_model.py ├── modules │ ├── __init__.py │ ├── biaffine.py │ ├── decoders │ │ ├── __init__.py │ │ ├── base.py │ │ ├── crf.py │ │ ├── mlm_head.py │ │ ├── pairwise_crf.py │ │ └── partial_crf.py │ ├── dropouts.py │ ├── embedders │ │ ├── __init__.py │ │ ├── base.py │ │ ├── embedding.py │ │ └── transformer_embedder.py │ ├── encoders │ │ ├── __init__.py │ │ ├── base.py │ │ ├── cnn_encoder.py │ │ ├── pytorch_rnn_encoder.py │ │ └── span_encoder.py │ ├── losses.py │ ├── scalar_mix.py │ └── util.py ├── ms_patch.py ├── pipelines │ ├── __init__.py │ ├── base.py │ ├── sequence_labeling_pipeline.py │ └── span_based_ner_pipeline.py ├── training │ ├── __init__.py │ ├── default_config.py │ ├── default_trainer.py │ ├── hooks │ │ ├── __init__.py │ │ └── text_logger_hook.py │ ├── lr_scheduler.py │ ├── optimizer.py │ └── typing_trainer.py ├── utils │ ├── __init__.py │ ├── checks.py │ ├── common_utils.py │ ├── constant.py │ ├── file_utils.py │ ├── hub_utils.py │ ├── logging.py │ └── yaml.py └── version.py ├── docs ├── datasets.md ├── faq_zh.md ├── imgs │ ├── community_qrcode.jpg │ ├── task_examples_en.png │ └── task_examples_zh.png ├── modelcards.md └── tutorials │ ├── customizing_dataset.md │ ├── customizing_dataset_zh.md │ ├── hyperparameter_optimization.md │ ├── hyperparameter_optimization_zh.md │ ├── learning_about_configs.md │ ├── learning_about_configs_zh.md │ ├── model_inference_zh.md │ ├── quick_start.md │ ├── quick_start_zh.md │ ├── reproducing_papers.md │ ├── reproducing_papers_zh.md │ ├── training_a_model.md │ ├── training_a_model_zh.md │ ├── training_acceleration_zh.md │ ├── training_with_multiple_gpus.md │ └── uploading_to_modelscope_zh.md ├── examples ├── ICASSP2023_MUG_track4 │ ├── README.md │ ├── configs │ │ ├── bert_crf_nezha.yaml │ │ └── bert_crf_sbert.yaml │ ├── dataset │ │ └── .gitkeep │ ├── download.py │ ├── end2end.sh │ ├── evaluate_kw.py │ ├── get_keywords.py │ ├── preprocess.py │ └── test_challenge.py ├── MCCE │ ├── README.md │ ├── configs │ │ └── ufet_concat_mcce_threshold_tuning.yaml │ ├── expand_stage │ │ └── expand_exact_match.py │ ├── recall_stage │ │ └── recall.py │ └── utils │ │ ├── evaluate_cands.py │ │ └── merge_cands.py ├── MoRe │ ├── README.md │ ├── configs │ │ ├── mnre-img.yaml │ │ ├── snap-img.yaml │ │ ├── snap-txt.yaml │ │ ├── snap.yaml │ │ ├── twitter-15-img.yaml │ │ ├── twitter-15-txt.yaml │ │ ├── twitter-15.yaml │ │ ├── twitter-17-img.yaml │ │ ├── twitter-17-txt.yaml │ │ ├── twitter-17.yaml │ │ ├── wikidiverse-img.yaml │ │ ├── wikidiverse-txt.yaml │ │ └── wikidiverse.yaml │ └── resource │ │ └── img.png ├── NPCRF │ ├── README.md │ ├── configs │ │ ├── cfet_concat_mlc.yaml │ │ ├── cfet_concat_npcrf.yaml │ │ ├── ufet_concat_mlc.yaml │ │ ├── ufet_concat_mlc_128.yaml │ │ └── ufet_concat_npcrf.yaml │ └── resource │ │ └── img.png ├── RaNER │ ├── README.md │ ├── configs │ │ └── wnut17.yaml │ └── resources │ │ └── model_image.jpg ├── SemEval2023_MultiCoNER_II │ ├── README.md │ ├── configs │ │ ├── orig │ │ │ ├── bn.yaml │ │ │ ├── de.yaml │ │ │ ├── en.yaml │ │ │ ├── es.yaml │ │ │ ├── fa.yaml │ │ │ ├── fr.yaml │ │ │ ├── hi.yaml │ │ │ ├── it.yaml │ │ │ ├── pt.yaml │ │ │ ├── sv.yaml │ │ │ ├── uk.yaml │ │ │ └── zh.yaml │ │ ├── wiki128 │ │ │ ├── bn.yaml │ │ │ ├── de.yaml │ │ │ ├── en.yaml │ │ │ ├── es.yaml │ │ │ ├── fa.yaml │ │ │ ├── fr.yaml │ │ │ ├── hi.yaml │ │ │ ├── it.yaml │ │ │ ├── pt.yaml │ │ │ ├── sv.yaml │ │ │ ├── uk.yaml │ │ │ └── zh.yaml │ │ └── wiki2048 │ │ │ ├── bn.yaml │ │ │ ├── de.yaml │ │ │ ├── en.yaml │ │ │ ├── es.yaml │ │ │ ├── fa.yaml │ │ │ ├── fr.yaml │ │ │ ├── hi.yaml │ │ │ ├── it.yaml │ │ │ ├── pt.yaml │ │ │ ├── sv.yaml │ │ │ ├── uk.yaml │ │ │ └── zh.yaml │ └── resource │ │ └── raner.jpg ├── U-RaNER │ ├── README.md │ └── resources │ │ └── U-RaNER.jpg ├── babert │ ├── README.md │ ├── configs │ │ ├── cws │ │ │ ├── ctb6.yaml │ │ │ ├── msra.yaml │ │ │ └── pku.yaml │ │ ├── ner │ │ │ └── ontonotes4.yaml │ │ └── pos │ │ │ ├── ctb6.yaml │ │ │ ├── ud1.yaml │ │ │ └── ud2.yaml │ └── resource │ │ └── babert.png ├── bert_crf │ ├── README.md │ └── configs │ │ ├── conll03.yaml │ │ ├── conllpp.yaml │ │ ├── ctb6_pos.yaml │ │ ├── maoe_example.yaml │ │ ├── msra.yaml │ │ ├── pku_cws.yaml │ │ ├── resume.yaml │ │ ├── weibo.yaml │ │ ├── wnut16.yaml │ │ └── wnut17.yaml ├── biaffine_ner │ └── configs │ │ ├── conll03.yaml │ │ └── resume.yaml ├── entity_typing │ ├── README.md │ └── configs │ │ └── cfet_span.yaml ├── global_pointer │ ├── README.md │ └── configs │ │ └── resume.yaml ├── partial_bert_crf │ ├── README.md │ └── configs │ │ └── msra.yaml └── twostage_ner │ └── configs │ └── weibo.yaml ├── pyproject.toml ├── requirements.txt ├── scripts ├── grid_search.py ├── pretrain.py ├── test.py └── train.py ├── setup.py ├── tests ├── citest.sh ├── models │ ├── __init__.py │ ├── base.py │ ├── test_base_model.py │ ├── test_bert_crf.py │ ├── test_biaffine_ner.py │ ├── test_global_pointer.py │ ├── test_lstm_crf.py │ ├── test_multilabel_entity_typing.py │ ├── test_partial_bert_crf.py │ ├── test_twostage_ner.py │ └── test_w2ner.py ├── modules │ ├── __init__.py │ └── test_crf.py ├── resources │ ├── configs │ │ ├── bert.yaml │ │ ├── demo.yaml │ │ ├── finetune_bert_crf_from_trained_model.yaml │ │ ├── structbert.yaml │ │ ├── train_bert_crf.yaml │ │ ├── train_biaffine_ner.yaml │ │ ├── train_entity_typing_concat.yaml │ │ ├── train_entity_typing_span.yaml │ │ ├── train_global_pointer.yaml │ │ ├── train_lstm_crf.yaml │ │ ├── train_partial_bert_crf.yaml │ │ ├── train_twostage_ner.yaml │ │ └── train_w2ner.yaml │ ├── datasets │ │ └── toy_msra │ │ │ ├── test.txt │ │ │ ├── toy_msra.py │ │ │ ├── toy_msra.zip │ │ │ ├── toy_msra_hf.py │ │ │ └── train.txt │ └── regression │ │ ├── ut_bert_crf.bin │ │ ├── ut_biaffine_ner.bin │ │ ├── ut_concat_entity_typing.bin │ │ ├── ut_entity_typing.bin │ │ ├── ut_global_pointer.bin │ │ ├── ut_lstm_crf.bin │ │ ├── ut_partial_bert_crf.bin │ │ ├── ut_two_stage_ner.bin │ │ └── ut_w2ner.bin ├── run_tests.py ├── test_commands.py ├── test_datasets.py ├── test_metainfo.py ├── test_pipelines.py ├── test_preprocessor.py ├── test_registry.py └── utils.py └── tools ├── evaluate └── conlleval └── gpu ├── README.md └── queue.py /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | 4 | ignore = 5 | # these rules don't play well with black 6 | E203 # whitespace before : 7 | W503 # line break before binary operator 8 | # docstrings are not checked currently 9 | D107,D2,D4,D100,D104,D105 10 | 11 | per-file-ignores = 12 | # __init__.py files are allowed to have unused imports 13 | */__init__.py:F401 14 | */**/**/__init__.py:F401 15 | 16 | extend-exclude = docs/,experiments/,tools/,*.pyc 17 | 18 | docstring-convention = google 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: 🚀 Feature Request 2 | description: Suggest an idea for AdaSeq 3 | title: "[Feature] " 4 | labels: ['feature request'] 5 | 6 | body: 7 | - type: textarea 8 | id: related-problem 9 | attributes: 10 | label: Is your feature request related to a problem? 11 | description: A clear and concise description of what the problem is. 12 | 13 | - type: textarea 14 | id: solution 15 | attributes: 16 | label: Describe the solution you'd like. 17 | description: A clear and concise description of what you want to happen. 18 | 19 | - type: textarea 20 | id: alternative 21 | attributes: 22 | label: Describe alternatives you've considered. 23 | description: A clear and concise description of any alternative solutions or features you've considered. 24 | 25 | - type: textarea 26 | id: addtion 27 | attributes: 28 | label: Additional context. 29 | description: Add any other context or screenshots about the feature request here. 30 | 31 | - type: checkboxes 32 | id: terms 33 | attributes: 34 | label: Code of Conduct 35 | description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/modelscope/adaseq/blob/master/CODE_OF_CONDUCT.md) 36 | options: 37 | - label: I agree to follow this project's Code of Conduct 38 | required: true 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: ❓ Questions/Help 2 | description: If you have questions, please first search existing issues and docs 3 | title: "[Question] " 4 | labels: ['question'] 5 | 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | ## Before asking: 11 | 1. search the [issues](https://github.com/modelscope/adaseq/issues). 12 | 2. search the docs (if there have). 13 | 14 | If you still can't find what you need: 15 | 16 | - type: textarea 17 | id: question 18 | attributes: 19 | label: What is your question? 20 | 21 | - type: textarea 22 | id: try 23 | attributes: 24 | label: What have you tried? 25 | 26 | - type: textarea 27 | id: code 28 | attributes: 29 | label: Code (if necessary) 30 | description: Please paste a code snippet if your question requires it! 31 | 32 | - type: textarea 33 | id: environment 34 | attributes: 35 | label: What's your environment? 36 | value: | 37 | - AdaSeq Version (e.g., 1.0 or master): 38 | - ModelScope Version (e.g., 1.0 or master): 39 | - PyTorch Version (e.g., 1.12.1): 40 | - OS (e.g., Ubuntu 20.04): 41 | - Python version: 42 | - CUDA/cuDNN version: 43 | - GPU models and configuration: 44 | - Any other relevant information: 45 | 46 | - type: checkboxes 47 | id: terms 48 | attributes: 49 | label: Code of Conduct 50 | description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/modelscope/adaseq/blob/master/CODE_OF_CONDUCT.md) 51 | options: 52 | - label: I agree to follow this project's Code of Conduct 53 | required: true 54 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Fixes # . 5 | 6 | Changes proposed in this pull request: 7 | 8 | - 9 | 10 | ## Before submitting 11 | 12 | 13 | - [ ] I've read and followed all steps in the [Making a pull request](https://github.com/modelscope/adaseq/blob/master/CONTRIBUTING.md#2-making-a-pull-request) 14 | section of the `CONTRIBUTING` docs. 15 | - [ ] I've updated or added any relevant docstrings following the syntax described in the [create a branch and work](https://github.com/modelscope/adaseq/blob/master/CONTRIBUTING.md#23-create-a-new-branch-to-work-on-your-fix-enhancement-or-model) section `CONTRIBUTING` docs. 16 | - [ ] If this PR fixes a bug, I've added a test that will fail without my fix. 17 | - [ ] If this PR adds a new feature, I've added tests that sufficiently cover my new functionality. 18 | 19 | ## PR review 20 | Anyone in the community is free to review the PR once the tests have passed. 21 | If we didn't discuss your PR in Github issues there's a high chance it will not be merged. 22 | 23 | ## Did you have fun? 24 | Make sure you had fun coding 🙃 25 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks.git 3 | rev: v4.3.0 4 | hooks: 5 | - id: trailing-whitespace 6 | exclude: experiments/|tools/ 7 | - id: check-yaml 8 | exclude: experiments/|tools/ 9 | - id: end-of-file-fixer 10 | exclude: experiments/|tools/ 11 | - id: requirements-txt-fixer 12 | exclude: experiments/|tools/ 13 | - id: double-quote-string-fixer 14 | exclude: experiments/|tools/ 15 | - id: check-merge-conflict 16 | exclude: experiments/|tools/ 17 | - id: fix-encoding-pragma 18 | exclude: experiments/|tools/ 19 | args: ["--remove"] 20 | - id: mixed-line-ending 21 | exclude: experiments/|tools/ 22 | args: ["--fix=lf"] 23 | 24 | - repo: https://github.com/PyCQA/isort.git 25 | rev: 5.11.5 26 | hooks: 27 | - id: isort 28 | 29 | - repo: https://github.com/psf/black 30 | rev: 22.10.0 31 | hooks: 32 | - id: black 33 | 34 | - repo: https://github.com/PyCQA/flake8.git 35 | rev: 5.0.4 36 | hooks: 37 | - id: flake8 38 | exclude: configs/|examples/|experiments/|tools/|tests/ 39 | additional_dependencies: [flake8-docstrings] 40 | -------------------------------------------------------------------------------- /.pre-commit-config_local.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: /home/admin/pre-commit/pre-commit-hooks 3 | rev: v4.3.0 4 | hooks: 5 | - id: trailing-whitespace 6 | exclude: experiments/|tools/ 7 | - id: check-yaml 8 | exclude: experiments/|tools/ 9 | - id: end-of-file-fixer 10 | exclude: experiments/|tools/ 11 | - id: requirements-txt-fixer 12 | exclude: experiments/|tools/ 13 | - id: double-quote-string-fixer 14 | exclude: experiments/|tools/ 15 | - id: check-merge-conflict 16 | exclude: experiments/|tools/ 17 | - id: fix-encoding-pragma 18 | exclude: experiments/|tools/ 19 | args: ["--remove"] 20 | - id: mixed-line-ending 21 | exclude: experiments/|tools/ 22 | args: ["--fix=lf"] 23 | 24 | - repo: /home/admin/pre-commit/isort 25 | rev: 5.10.1 26 | hooks: 27 | - id: isort 28 | 29 | - repo: /home/admin/pre-commit/black 30 | rev: 22.10.0 31 | hooks: 32 | - id: black 33 | 34 | - repo: /home/admin/pre-commit/flake8 35 | rev: 5.0.4 36 | hooks: 37 | - id: flake8 38 | exclude: configs/|examples/|experiments/|tools/|tests/ 39 | additional_dependencies: [flake8-docstrings] 40 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT_zh.md: -------------------------------------------------------------------------------- 1 | # 阿里巴巴开源行为准则 2 | 3 | ## 我们的保证 4 | 5 | 为了促进一个开放透明且友好的环境,我们作为贡献者和维护者保证:无论年龄、种族、民族、性别认同和表达(方式)、体型、身体健全与否、经验水平、国籍、个人表现、宗教或性别取向,参与者在我们项目和社区中都免于骚扰。 6 | 7 | ## 我们的标准 8 | 9 | 有助于创造正面环境的行为包括但不限于: 10 | 11 | * 使用友好和包容性语言 12 | * 尊重不同的观点和经历 13 | * 耐心地接受建设性批评 14 | * 关注对社区最有利的事情 15 | * 友善对待其他社区成员 16 | 17 | 身为参与者不能接受的行为包括但不限于: 18 | 19 | * 使用与性有关的言语或是图像,以及不受欢迎的性骚扰 20 | * 捣乱/煽动/造谣的行为或进行侮辱/贬损的评论,人身攻击及政治攻击 21 | * 公开或私下的骚扰 22 | * 未经许可地发布他人的个人资料,例如住址或是电子地址 23 | * 其他可以被合理地认定为不恰当或者违反职业操守的行为 24 | 25 | ## 我们的责任 26 | 27 | 项目维护者有责任为「可接受的行为」标准做出诠释,以及对已发生的不被接受的行为采取恰当且公平的纠正措施。 28 | 29 | 项目维护者有权利及责任去删除、编辑、拒绝与本行为标准有所违背的评论 (comments)、提交 (commits)、代码、wiki 编辑、问题 (issues) 和其他贡献,以及项目维护者可暂时或永久性的禁止任何他们认为有不适当、威胁、冒犯、有害行为的贡献者。 30 | 31 | ## 使用范围 32 | 33 | 当一个人代表该项目或是其社区时,本行为标准适用于其项目平台和公共平台。 34 | 35 | 代表项目或是社区的情况,举例来说包括使用官方项目的电子邮件地址、通过官方的社区媒体账号发布或线上或线下事件中担任指定代表。 36 | 37 | 该项目的呈现方式可由其项目维护者进行进一步的定义及解释。 38 | 39 | ## 强制执行 40 | 41 | 可以通过 opensource@alibaba-inc.com 来联系项目团队来举报滥用、骚扰或其他不被接受的行为。 42 | 43 | 任何维护团队认为有必要且适合的所有投诉都将进行审查及调查,并做出相对应的回应。项目小组有对事件回报者有保密的义务。具体执行的方针近一步细节可能会单独公布。 44 | 45 | 没有切实地遵守或是执行本行为标准的项目维护人员,可能会因项目领导人或是其他成员的决定,暂时或是永久地取消其参与资格。 46 | 47 | ## 来源 48 | 49 | 本行为标准改编自[贡献者公约](https://www.contributor-covenant.org),版本 1.4 50 | 可在此查看[https://www.contributor-covenant.org/zh-cn/version/1/4/code-of-conduct.html](https://www.contributor-covenant.org/zh-cn/version/1/4/code-of-conduct.html) 51 | -------------------------------------------------------------------------------- /adaseq/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | # trigger register mechanism 3 | from adaseq import data, exporters, metrics, models, ms_patch, pipelines, training 4 | from adaseq.utils.logging import prepare_global_logging 5 | from adaseq.version import __version__ 6 | 7 | prepare_global_logging() 8 | -------------------------------------------------------------------------------- /adaseq/commands/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import argparse 3 | from typing import Optional, Tuple 4 | 5 | from adaseq import __version__ 6 | from adaseq.commands.test import Test 7 | from adaseq.commands.train import Train 8 | 9 | 10 | def parse_args( # noqa: D103 11 | prog: Optional[str] = None, 12 | ) -> Tuple[argparse.ArgumentParser, argparse.Namespace]: 13 | parser = argparse.ArgumentParser(prog=prog) 14 | parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}') 15 | 16 | subparsers = parser.add_subparsers(help='commands') 17 | Train.add_subparser(subparsers) 18 | Test.add_subparser(subparsers) 19 | 20 | args = parser.parse_args() 21 | 22 | return parser, args 23 | 24 | 25 | def main(prog: Optional[str] = None) -> None: # noqa: D103 26 | parser, args = parse_args(prog) 27 | 28 | if 'func' in dir(args): 29 | args.func(args) 30 | else: 31 | parser.print_help() 32 | -------------------------------------------------------------------------------- /adaseq/commands/subcommand.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import argparse 3 | from abc import ABC, abstractmethod 4 | 5 | 6 | class Subcommand(ABC): 7 | """Abstract class for subcommands""" 8 | 9 | @classmethod 10 | @abstractmethod 11 | def add_subparser(cls, parser: argparse._SubParsersAction) -> argparse.ArgumentParser: 12 | """Add arguments parser for subcommand""" 13 | pass 14 | -------------------------------------------------------------------------------- /adaseq/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from . import data_collators, dataset_dumpers, preprocessors 3 | from .dataset_manager import DatasetManager 4 | -------------------------------------------------------------------------------- /adaseq/data/constant.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | NON_ENTITY_LABEL = 'O' 3 | NON_ENTITY_LABEL_ID = 0 4 | PAD_LABEL = 'X' 5 | PAD_LABEL_ID = -100 6 | 7 | OBJECT_START_TOKEN = '' 8 | SUBJECT_START_TOKEN = '' 9 | NONE_REL_LABEL = 'None' 10 | NONE_REL_LABEL_ID = 0 11 | 12 | PARTIAL_LABEL = 'PARTIAL' 13 | PARTIAL_LABEL_ID = -1 14 | -------------------------------------------------------------------------------- /adaseq/data/data_collators/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .multilabel_typing_data_collator_with_padding import ( 3 | MultiLabelSpanTypingDataCollatorWithPadding, 4 | ) 5 | from .pretraining_data_collator_with_padding import PretrainingDataCollatorWithPadding 6 | from .sequence_labeling_data_collator_with_padding import ( 7 | SequenceLabelingDataCollatorWithPadding, 8 | ) 9 | from .span_extraction_data_collator_with_padding import ( 10 | SpanExtractionDataCollatorWithPadding, 11 | ) 12 | from .twostage_data_collator_with_padding import TwostageDataCollatorWithPadding 13 | from .word_extraction_data_collator_with_padding import ( 14 | WordExtractionDataCollatorWithPadding, 15 | ) 16 | -------------------------------------------------------------------------------- /adaseq/data/data_collators/pretraining_data_collator_with_padding.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import Optional, Set 3 | 4 | from adaseq.metainfo import DataCollators 5 | 6 | from .base import DATA_COLLATORS, DataCollatorWithPadding 7 | 8 | 9 | @DATA_COLLATORS.register_module(module_name=DataCollators.pretraining_data_collator) 10 | class PretrainingDataCollatorWithPadding(DataCollatorWithPadding): 11 | """Padding method for pretraining dataset.""" 12 | 13 | def __init__( 14 | self, tokenizer, default_pad_id: int = 0, no_pad_fields: Optional[Set[str]] = None, **kwargs 15 | ) -> None: 16 | super().__init__(tokenizer, default_pad_id, no_pad_fields, **kwargs) 17 | self.keep_fields.add('prompt_type') 18 | -------------------------------------------------------------------------------- /adaseq/data/data_collators/sequence_labeling_data_collator_with_padding.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import Any, Dict 3 | 4 | from adaseq.data.constant import PAD_LABEL_ID 5 | from adaseq.metainfo import DataCollators 6 | 7 | from .base import DATA_COLLATORS, DataCollatorWithPadding 8 | 9 | 10 | @DATA_COLLATORS.register_module(module_name=DataCollators.sequence_labeling_data_collator) 11 | class SequenceLabelingDataCollatorWithPadding(DataCollatorWithPadding): 12 | """Collator for the sequence labeling task""" 13 | 14 | pad_label_id: int = PAD_LABEL_ID 15 | 16 | def padding(self, batch: Dict[str, Any], padding_side: str, **kwargs) -> Dict[str, Any]: 17 | """pad label sequence `label_ids`""" 18 | return super().padding(batch, padding_side, 'label_ids', self.pad_label_id) 19 | -------------------------------------------------------------------------------- /adaseq/data/data_collators/span_extraction_data_collator_with_padding.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import Any, Dict 3 | 4 | import numpy as np 5 | 6 | from adaseq.metainfo import DataCollators 7 | 8 | from .base import DATA_COLLATORS, DataCollatorWithPadding 9 | 10 | 11 | @DATA_COLLATORS.register_module(module_name=DataCollators.span_extraction_data_collator) 12 | class SpanExtractionDataCollatorWithPadding(DataCollatorWithPadding): 13 | """Padding method for span extraction dataset.""" 14 | 15 | def padding(self, batch: Dict[str, Any], **kwargs) -> Dict[str, Any]: 16 | """ 17 | Padding a batch. In addition to the fields padded by base class 18 | `DataCollatorWithPadding`, label_matrix is padded here. 19 | """ 20 | field = 'span_labels' 21 | max_length = max(len(i[0]) for i in batch[field]) 22 | for i in range(len(batch[field])): 23 | difference = max_length - len(batch[field][i][0]) 24 | if difference > 0: 25 | padded_labels = np.zeros((max_length, max_length), dtype=int) 26 | padded_labels[: batch[field][i].shape[0], : batch[field][i].shape[1]] = batch[ 27 | field 28 | ][i].astype(int) 29 | batch[field][i] = padded_labels.tolist() 30 | else: 31 | batch[field][i] = batch[field][i].astype(int).tolist() 32 | 33 | return batch 34 | -------------------------------------------------------------------------------- /adaseq/data/data_collators/twostage_data_collator_with_padding.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import Any, Dict 3 | 4 | from adaseq.metainfo import DataCollators 5 | 6 | from .base import DATA_COLLATORS, DataCollatorWithPadding 7 | 8 | 9 | @DATA_COLLATORS.register_module(module_name=DataCollators.twostage_data_collator) 10 | class TwostageDataCollatorWithPadding(DataCollatorWithPadding): 11 | """Padding method for two stage ner dataset.""" 12 | 13 | def padding(self, batch: Dict[str, Any], **kwargs) -> Dict[str, Any]: 14 | """ 15 | Padding a batch. In addition to the fields padded by base class DataCollatorWithPadding, 16 | 'mention_boundary', 'type_ids', 'mention_mask', 'ident_ids', 'ident_mask' are padded here. 17 | """ 18 | 19 | max_length = max(len(i) for i in batch['ident_ids']) 20 | for i in range(len(batch['ident_ids'])): 21 | difference = max_length - len(batch['ident_ids'][i]) 22 | if difference > 0: 23 | batch['ident_ids'][i] = batch['ident_ids'][i] + [-100] * difference 24 | 25 | max_span_count = max([len(x[0]) for x in batch['mention_boundary']]) 26 | max_span_count = max(max_span_count, 1) 27 | for i in range(len(batch['mention_boundary'])): 28 | difference = max_span_count - len(batch['mention_boundary'][i][0]) 29 | if difference > 0: 30 | batch['mention_boundary'][i][0] = batch['mention_boundary'][i][0] + [0] * difference 31 | batch['mention_boundary'][i][1] = batch['mention_boundary'][i][1] + [0] * difference 32 | batch['type_ids'][i] = batch['type_ids'][i] + [-100] * difference 33 | batch['mention_mask'][i] = batch['mention_mask'][i] + [0] * difference 34 | return batch 35 | -------------------------------------------------------------------------------- /adaseq/data/dataset_builders/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/adaseq/data/dataset_builders/__init__.py -------------------------------------------------------------------------------- /adaseq/data/dataset_dumpers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .named_entity_recognition_dataset_dumper import NamedEntityRecognitionDatasetDumper 3 | -------------------------------------------------------------------------------- /adaseq/data/dataset_dumpers/base.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import os 3 | from typing import Dict, Optional 4 | 5 | from modelscope.metrics.base import Metric 6 | 7 | 8 | class DatasetDumper(Metric): 9 | """class to dump model predictions""" 10 | 11 | def __init__(self, save_path: Optional[str] = None, *args, **kwargs): 12 | super().__init__(*args, **kwargs) 13 | self.save_path = save_path 14 | self.data = [] 15 | 16 | def add(self, outputs: Dict, inputs: Dict): 17 | """add predictions to cache""" 18 | raise NotImplementedError 19 | 20 | def evaluate(self): 21 | """creat dump file and dump predicitons.""" 22 | if self.save_path is None: 23 | self.save_path = os.path.join(self.trainer.work_dir, 'pred.txt') 24 | save_path = self.save_path 25 | self.save_path = save_path + '.tmp' # file lock 26 | self.dump() 27 | os.replace(self.save_path, save_path) 28 | self.save_path = save_path 29 | return {} 30 | 31 | def dump(self): 32 | """dump predictions""" 33 | raise NotImplementedError 34 | 35 | def merge(self): 36 | """implement abstract method 37 | This function should never be used. 38 | """ 39 | raise NotImplementedError 40 | -------------------------------------------------------------------------------- /adaseq/data/preprocessors/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .multilabel_typing_preprocessor import ( 3 | MultiLabelConcatTypingMCCEPreprocessor, 4 | MultiLabelConcatTypingPreprocessor, 5 | MultiLabelSpanTypingPreprocessor, 6 | ) 7 | from .nlp_preprocessor import NLPPreprocessor 8 | from .pretraining_preprocessor import PretrainingPreprocessor 9 | from .relation_extraction_preprocessor import RelationExtractionPreprocessor 10 | from .sequence_labeling_preprocessor import SequenceLabelingPreprocessor 11 | from .span_extraction_preprocessor import SpanExtracionPreprocessor 12 | from .twostage_preprocessor import TwoStagePreprocessor 13 | from .word_extraction_preprocessor import WordExtracionPreprocessor 14 | -------------------------------------------------------------------------------- /adaseq/data/preprocessors/relation_extraction_preprocessor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import Any, Dict, List, Union 3 | 4 | from modelscope.preprocessors.builder import PREPROCESSORS 5 | from modelscope.utils.constant import Fields 6 | 7 | from adaseq.metainfo import Preprocessors 8 | 9 | from ..constant import NONE_REL_LABEL, NONE_REL_LABEL_ID 10 | from .nlp_preprocessor import NLPPreprocessor 11 | 12 | 13 | @PREPROCESSORS.register_module( 14 | Fields.nlp, module_name=Preprocessors.relation_extraction_preprocessor 15 | ) 16 | class RelationExtractionPreprocessor(NLPPreprocessor): 17 | """Relation Extraction data preprocessor""" 18 | 19 | def __init__(self, model_dir: str, labels: List[str], **kwargs): 20 | label_to_id = self._gen_label2id(labels) 21 | super().__init__(model_dir, label_to_id=label_to_id, return_offsets=True, **kwargs) 22 | 23 | def __call__(self, data: Union[str, List, Dict]) -> Dict[str, Any]: 24 | """prepare inputs for Relation Extraction model.""" 25 | output = super().__call__(data) 26 | 27 | if isinstance(data, Dict) and 'label' in data: 28 | output['label_id'] = self.label_to_id[data['label']] 29 | output['so_head_mask'] = data['so_head_mask'] 30 | return output 31 | 32 | @staticmethod 33 | def _gen_label2id(labels: List[str]) -> Dict[str, int]: 34 | label2id = {} 35 | label2id[NONE_REL_LABEL] = NONE_REL_LABEL_ID 36 | for label in labels: 37 | if label != NONE_REL_LABEL: 38 | label2id[f'{label}'] = len(label2id) 39 | return label2id 40 | -------------------------------------------------------------------------------- /adaseq/data/preprocessors/span_extraction_preprocessor.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import Any, Dict, List, Union 3 | 4 | import numpy as np 5 | from modelscope.preprocessors.builder import PREPROCESSORS 6 | from modelscope.utils.constant import Fields 7 | 8 | from adaseq.metainfo import Preprocessors 9 | 10 | from .nlp_preprocessor import NLPPreprocessor 11 | 12 | 13 | @PREPROCESSORS.register_module(Fields.nlp, module_name=Preprocessors.span_extraction_preprocessor) 14 | class SpanExtracionPreprocessor(NLPPreprocessor): 15 | """Preprocessor of span-based model. 16 | span targets are processed into `span_labels` 17 | """ 18 | 19 | def __init__(self, model_dir: str, **kwargs): 20 | super().__init__(model_dir, return_offsets=True, **kwargs) 21 | 22 | def __call__(self, data: Union[str, List, Dict]) -> Dict[str, Any]: 23 | """prepare inputs for span-based model.""" 24 | 25 | output = super().__call__(data) 26 | 27 | if not (isinstance(data, dict) and 'spans' in data): 28 | return output 29 | 30 | # origin sequence length 31 | length = len(output['tokens']['mask']) - 2 * int(self.add_special_tokens) 32 | # calculate span labels 33 | span_labels = np.zeros([length, length]) 34 | for span in data['spans']: 35 | # self.label_to_id doesn't have non-entity label, 36 | # we set index 0 as non-entity label, so we add 1 to type_id 37 | type_id = self.label_to_id[span['type']] + 1 38 | if span['end'] > length: 39 | continue 40 | span_labels[span['start']][span['end'] - 1] = type_id 41 | output['span_labels'] = span_labels 42 | return output 43 | -------------------------------------------------------------------------------- /adaseq/data/tokenizer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from modelscope.preprocessors.nlp.transformers_tokenizer import NLPTokenizer 3 | from transformers import AutoTokenizer, BertTokenizer, BertTokenizerFast 4 | from transformers.tokenization_utils import PreTrainedTokenizer 5 | 6 | from adaseq.utils.hub_utils import get_or_download_model_dir 7 | 8 | 9 | def build_tokenizer( 10 | model_name_or_path: str, use_fast: bool = True, is_word2vec: bool = False, **kwargs 11 | ) -> PreTrainedTokenizer: 12 | """build tokenizer from `transformers`.""" 13 | 14 | if is_word2vec: 15 | tokenizer = BertTokenizerFast if use_fast else BertTokenizer 16 | return tokenizer.from_pretrained(model_name_or_path, **kwargs) 17 | 18 | if model_name_or_path.startswith('damo/'): 19 | model_name_or_path = get_or_download_model_dir(model_name_or_path) 20 | return NLPTokenizer(model_name_or_path, use_fast=use_fast).tokenizer 21 | 22 | else: 23 | try: 24 | return AutoTokenizer.from_pretrained(model_name_or_path, use_fast=use_fast, **kwargs) 25 | 26 | except OSError: 27 | model_name_or_path = get_or_download_model_dir(model_name_or_path) 28 | return NLPTokenizer(model_name_or_path, use_fast=use_fast).tokenizer 29 | -------------------------------------------------------------------------------- /adaseq/data/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | 3 | from typing import Dict, List, Optional, Set 4 | 5 | from datasets.arrow_dataset import Dataset 6 | 7 | from .span_utils import bio_tags_to_spans 8 | 9 | 10 | def count_labels(example: Dict, labels: Set, key: str = 'label', **kwargs): 11 | """ 12 | Count labels from dataset. 13 | """ 14 | if isinstance(example[key], str): 15 | labels.add(example[key]) 16 | elif isinstance(example[key], list): 17 | labels.update(example[key]) 18 | else: 19 | raise RuntimeError 20 | return example 21 | 22 | 23 | def count_span_labels(example: Dict, labels: Set, key: str = 'spans', **kwargs): 24 | """ 25 | Count labels from dataset. 26 | """ 27 | for span in example[key]: 28 | label = span['type'] 29 | if isinstance(label, str): 30 | labels.add(label) 31 | elif isinstance(label, list): 32 | labels.update(label) 33 | else: 34 | raise RuntimeError 35 | return example 36 | 37 | 38 | def hf_ner_to_adaseq( 39 | dataset: Dataset, 40 | key: str = 'ner_tags', 41 | scheme: str = 'bio', 42 | classes_to_ignore: Optional[List[str]] = None, 43 | ) -> Dataset: 44 | """ 45 | Map the feature with name `key` from index to label. 46 | """ 47 | if scheme.lower() == 'bio': 48 | to_spans = bio_tags_to_spans 49 | else: 50 | raise NotImplementedError 51 | 52 | to_str = dataset.features[key].feature.int2str 53 | 54 | def to_adaseq(example): 55 | tags = [to_str(i) for i in example[key]] 56 | example['spans'] = to_spans(tags, classes_to_ignore) 57 | return example 58 | 59 | dataset = dataset.map(to_adaseq) 60 | return dataset 61 | 62 | 63 | COUNT_LABEL_FUNCTIONS = {'count_labels': count_labels, 'count_span_labels': count_span_labels} 64 | DATASET_TRANSFORMS = {'hf_ner_to_adaseq': hf_ner_to_adaseq} 65 | -------------------------------------------------------------------------------- /adaseq/exporters/__init__.py: -------------------------------------------------------------------------------- 1 | from .multilabel_typing_model_exporter import MultiLabelSpanTypingModelExporter 2 | from .sequence_labeling_model_exporter import SequenceLabelingModelExporter 3 | -------------------------------------------------------------------------------- /adaseq/exporters/base.py: -------------------------------------------------------------------------------- 1 | from modelscope.exporters.torch_model_exporter import TorchModelExporter 2 | 3 | 4 | class Exporter(TorchModelExporter): 5 | """The base class of exporter inheriting from TorchModelExporter. 6 | 7 | This class provides the default implementations for exporting onnx and torch script. 8 | Each specific model may implement its own exporter by overriding the export_onnx/export_torch_script, 9 | and to provide implementations for generate_dummy_inputs/inputs/outputs methods. 10 | """ 11 | 12 | def __init__(self, model=None, preprocessor=None): 13 | super().__init__(model=model) 14 | self.preprocessor = preprocessor 15 | -------------------------------------------------------------------------------- /adaseq/main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Copyright (c) Alibaba, Inc. and its affiliates. 3 | import os 4 | import sys 5 | 6 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) 7 | 8 | 9 | def run(): 10 | """Command line main interface""" 11 | from adaseq.commands import main 12 | 13 | main(prog='adaseq') 14 | 15 | 16 | if __name__ == '__main__': 17 | run() 18 | -------------------------------------------------------------------------------- /adaseq/metrics/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .pretraining_metric import PretrainingMetric 3 | from .relation_extraction_metric import RelationExtractionMetric 4 | from .sequence_labeling_metric import SequenceLabelingMetric 5 | from .span_extraction_metric import SpanExtractionMetric 6 | from .typing_metric import ConcatTypingThresholdMetric, TypingMetric 7 | -------------------------------------------------------------------------------- /adaseq/models/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | 3 | from .biaffine_ner_model import BiaffineNerModel 4 | from .global_pointer_model import GlobalPointerModel 5 | from .multilabel_typing_model import ( 6 | MultiLabelConcatTypingModel, 7 | MultiLabelConcatTypingModelMCCES, 8 | MultiLabelSpanTypingModel, 9 | ) 10 | from .pretraining_model import PretrainingModel 11 | from .relation_extraction_model import RelationExtractionModel 12 | from .sequence_labeling_model import SequenceLabelingModel 13 | from .twostage_ner_model import TwoStageNERModel 14 | from .w2ner_model import W2NerModel 15 | -------------------------------------------------------------------------------- /adaseq/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/adaseq/modules/__init__.py -------------------------------------------------------------------------------- /adaseq/modules/decoders/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .base import DECODERS, Decoder, build_decoder 3 | from .crf import CRF, CRFwithConstraints 4 | from .mlm_head import OnlyMLMHead 5 | from .pairwise_crf import PairwiseCRF 6 | from .partial_crf import PartialCRF 7 | -------------------------------------------------------------------------------- /adaseq/modules/dropouts.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import torch 3 | import torch.nn as nn 4 | 5 | 6 | class WordDropout(nn.Module): 7 | """Word-level Dropout module 8 | 9 | During training, randomly zeroes some of the elements of the input tensor at word level 10 | with probability `dropout_rate` using samples from a Bernoulli distribution. 11 | 12 | Args: 13 | dropout_rate (float): dropout rate for each word 14 | """ 15 | 16 | def __init__(self, dropout_rate: float = 0.1): 17 | super(WordDropout, self).__init__() 18 | assert 0.0 <= dropout_rate < 1.0, '0.0 <= dropout rate < 1.0 must be satisfied!' 19 | self.dropout_rate = dropout_rate 20 | 21 | def forward(self, inputs: torch.Tensor) -> torch.Tensor: 22 | """Dropout the input tensor at word level 23 | 24 | Args: 25 | inputs (torch.Tensor): input tensor 26 | 27 | Returns: 28 | outputs (torch.Tensor): output tensor of the same shape as input 29 | """ 30 | if not self.training or not self.dropout_rate: 31 | return inputs 32 | 33 | mask = inputs.new_empty(*inputs.shape[:2], 1, requires_grad=False).bernoulli_( 34 | 1.0 - self.dropout_rate 35 | ) 36 | mask = mask.expand_as(inputs) 37 | return inputs * mask 38 | -------------------------------------------------------------------------------- /adaseq/modules/embedders/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .base import EMBEDDERS, Embedder, build_embedder 3 | from .embedding import Embedding 4 | from .transformer_embedder import TransformerEmbedder 5 | -------------------------------------------------------------------------------- /adaseq/modules/encoders/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .base import ENCODERS, Encoder, build_encoder 3 | from .cnn_encoder import CnnEncoder 4 | from .pytorch_rnn_encoder import GruEncoder, LstmEncoder, RnnEncoder 5 | from .span_encoder import SpanEncoder 6 | -------------------------------------------------------------------------------- /adaseq/modules/encoders/cnn_encoder.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from typing import List, Optional 3 | 4 | import torch 5 | import torch.nn as nn 6 | import torch.nn.functional as func 7 | 8 | from adaseq.metainfo import Encoders 9 | 10 | from .base import ENCODERS, Encoder 11 | 12 | 13 | @ENCODERS.register_module(module_name=Encoders.cnn_encoder) 14 | class CnnEncoder(Encoder): 15 | """Turn token embedding sequenece to a single vector.""" 16 | 17 | def __init__( 18 | self, 19 | input_size: int, 20 | channels: int = 128, 21 | dropout: float = 0.0, 22 | dilation: Optional[List[int]] = None, 23 | ): 24 | super().__init__() 25 | self.base = nn.Sequential( 26 | nn.Dropout2d(dropout), 27 | nn.Conv2d(input_size, channels, kernel_size=1), 28 | nn.GELU(), 29 | ) 30 | if dilation is None: 31 | dilation = [1, 2, 3] 32 | self.input_dim = input_size 33 | self.output_dim = channels * len(dilation) 34 | self.convs = nn.ModuleList( 35 | [ 36 | nn.Conv2d(channels, channels, kernel_size=3, groups=channels, dilation=d, padding=d) 37 | for d in dilation 38 | ] 39 | ) 40 | 41 | def forward(self, x, **kwargs): # noqa: D102 42 | x = x.permute(0, 3, 1, 2).contiguous() 43 | x = self.base(x) 44 | 45 | outputs = [] 46 | for conv in self.convs: 47 | x = conv(x) 48 | x = func.gelu(x) 49 | outputs.append(x) 50 | outputs = torch.cat(outputs, dim=1) 51 | outputs = outputs.permute(0, 2, 3, 1).contiguous() 52 | return outputs 53 | 54 | def get_input_dim(self) -> int: # noqa: D102 55 | return self.input_dim 56 | 57 | def get_output_dim(self) -> int: # noqa: D102 58 | return self.output_dim 59 | -------------------------------------------------------------------------------- /adaseq/ms_patch.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | # Fix some modelscope bugs temporarily. 3 | # These bugs will be fixed in the next modelscope version. 4 | 5 | 6 | def suppress_modelscope_ast_warning(): # noqa 7 | try: 8 | from modelscope.utils.logger import get_logger 9 | 10 | def filter_modelscope_ast_warning(record): 11 | return 'not found in ast index file' not in record.msg 12 | 13 | logger = get_logger() 14 | logger.addFilter(filter_modelscope_ast_warning) 15 | except IsADirectoryError: 16 | pass 17 | 18 | 19 | suppress_modelscope_ast_warning() 20 | -------------------------------------------------------------------------------- /adaseq/pipelines/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .sequence_labeling_pipeline import SequenceLabelingPipeline 3 | from .span_based_ner_pipeline import SpanBasedNERPipeline 4 | -------------------------------------------------------------------------------- /adaseq/pipelines/base.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | 3 | from typing import Any, Dict, Optional, Union 4 | 5 | import torch 6 | from modelscope.models import Model 7 | from modelscope.pipelines.base import Pipeline as MsPipeline 8 | from modelscope.preprocessors import Preprocessor 9 | 10 | 11 | class Pipeline(MsPipeline): 12 | """use `model` and `preprocessor` to create a pipeline for prediction 13 | 14 | Args: 15 | model (str or Model): A model instance or a model local dir or a model id in the model hub. 16 | preprocessor (Preprocessor): a preprocessor instance, must not be None. 17 | kwargs (dict, `optional`): 18 | Extra kwargs passed into the preprocessor's constructor. 19 | """ 20 | 21 | def __init__( 22 | self, 23 | model: Union[Model, str], 24 | preprocessor: Optional[Preprocessor] = None, 25 | config_file: str = None, 26 | device: str = 'gpu', 27 | auto_collate: bool = True, 28 | **kwargs 29 | ): 30 | super().__init__( 31 | model=model, 32 | preprocessor=preprocessor, 33 | config_file=config_file, 34 | device=device, 35 | auto_collate=auto_collate, 36 | ) 37 | 38 | if preprocessor is None: 39 | self.preprocessor = Preprocessor.from_pretrained(self.model.model_dir, **kwargs) 40 | self.model.eval() 41 | 42 | assert hasattr(self.preprocessor, 'id_to_label') 43 | self.id2label = self.preprocessor.id_to_label 44 | 45 | def forward(self, inputs: Dict[str, Any], **forward_params) -> Dict[str, Any]: # noqa: D102 46 | with torch.no_grad(): 47 | return {**self.model(**inputs, **forward_params), **inputs} 48 | 49 | def postprocess( # noqa: D102 50 | self, inputs: Dict[str, Any], **postprocess_params 51 | ) -> Dict[str, Any]: 52 | raise NotImplementedError 53 | -------------------------------------------------------------------------------- /adaseq/training/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | from .default_trainer import DefaultTrainer, build_trainer 3 | from .hooks.text_logger_hook import AdaSeqTextLoggerHook 4 | from .typing_trainer import TyingTrainer 5 | -------------------------------------------------------------------------------- /adaseq/training/default_config.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | DEFAULT_CONFIG = { 3 | 'train': { 4 | 'dataloader': {'workers_per_gpu': 0}, 5 | 'hooks': [ 6 | {'type': 'EvaluationHook'}, 7 | { 8 | 'type': 'BestCkptSaverHook', 9 | 'save_file_name': 'best_model.pth', 10 | 'metric_key': 'f1', 11 | 'save_optimizer': False, 12 | 'restore_best': True, 13 | }, 14 | {'type': 'TextLoggerHook', 'interval': 50}, 15 | {'type': 'IterTimerHook'}, 16 | ], 17 | }, 18 | 'evaluation': {'dataloader': {'workers_per_gpu': 0, 'shuffle': False}}, 19 | } 20 | -------------------------------------------------------------------------------- /adaseq/training/hooks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/adaseq/training/hooks/__init__.py -------------------------------------------------------------------------------- /adaseq/training/lr_scheduler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | 3 | from typing import Any, Dict 4 | 5 | from modelscope.trainers.lrscheduler.builder import ( 6 | build_lr_scheduler as ms_build_lr_scheduler, 7 | ) 8 | from modelscope.utils.config import Config 9 | from transformers import optimization 10 | 11 | 12 | def build_lr_scheduler(config: Config, total_steps: int, default_args: Dict[str, Any]): 13 | """ 14 | Build lr scheduler, `constant` by default. 15 | """ 16 | if config is None: 17 | config = dict(type='constant') 18 | 19 | name = config.get('type') 20 | warmup_rate = config.get('warmup_rate', 0.0) 21 | 22 | # transformers lr_scheduler 23 | if name in optimization.TYPE_TO_SCHEDULER_FUNCTION: 24 | return optimization.get_scheduler( 25 | name, 26 | default_args['optimizer'], 27 | num_warmup_steps=int(total_steps * warmup_rate), 28 | num_training_steps=total_steps, 29 | ) 30 | 31 | # torch lr_scheduler 32 | else: 33 | return ms_build_lr_scheduler(config, default_args) 34 | -------------------------------------------------------------------------------- /adaseq/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/adaseq/utils/__init__.py -------------------------------------------------------------------------------- /adaseq/utils/checks.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | """ 3 | Functions and exceptions for checking that 4 | AdaSeq and its models are configured correctly. 5 | """ 6 | from typing import Any, Tuple, Union 7 | 8 | 9 | # Copyright (c) AI2 AllenNLP. Licensed under the Apache License, Version 2.0. 10 | class ConfigurationError(Exception): 11 | """ 12 | The exception raised by any Adaseq object when it's misconfigured 13 | (e.g. missing properties, invalid properties, unknown properties). 14 | """ 15 | 16 | def __reduce__(self) -> Union[str, Tuple[Any, ...]]: 17 | return type(self), (self.message,) 18 | 19 | def __init__(self, message: str): 20 | super().__init__() 21 | self.message = message 22 | 23 | def __str__(self): 24 | return self.message 25 | -------------------------------------------------------------------------------- /adaseq/utils/common_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import datetime 3 | from typing import Dict 4 | 5 | from modelscope.utils.config import Config 6 | 7 | 8 | def create_datetime_str() -> str: 9 | """Create a string indicating current time 10 | 11 | Create a string indicating current time in microsecond precision, 12 | for example, 221109144626.861616 13 | 14 | Returns: 15 | str: current time string 16 | """ 17 | datetime_dt = datetime.datetime.today() 18 | datetime_str = datetime_dt.strftime('%y%m%d%H%M%S.%f') 19 | return datetime_str 20 | 21 | 22 | def has_keys(_dict: Dict, *keys: str): 23 | """Check whether a nested dict has a key 24 | 25 | Args: 26 | _dict (Dict): a nested dict like object 27 | *keys (str): flattened key list 28 | 29 | Returns: 30 | bool: whether _dict has keys 31 | """ 32 | if not _dict or not keys: 33 | return False 34 | 35 | sub_dict = _dict 36 | for key in keys: 37 | if isinstance(sub_dict, (dict, Config)) and key in sub_dict: 38 | sub_dict = sub_dict[key] 39 | else: 40 | return False 41 | return True 42 | -------------------------------------------------------------------------------- /adaseq/utils/constant.py: -------------------------------------------------------------------------------- 1 | DEMO_CONFIG = 'http://mitalinlp.oss-cn-hangzhou.aliyuncs.com/adaseq/configs/demo.yaml' 2 | -------------------------------------------------------------------------------- /adaseq/utils/file_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import os 3 | 4 | 5 | def is_empty_dir(path): 6 | """Check if a directory is empty""" 7 | return len(list(filter(lambda x: not x.startswith('.nfs'), os.listdir(path)))) == 0 8 | -------------------------------------------------------------------------------- /adaseq/utils/hub_utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from modelscope.hub.check_model import check_local_model_is_latest 4 | from modelscope.hub.snapshot_download import snapshot_download 5 | from modelscope.utils.constant import Invoke 6 | 7 | 8 | def get_or_download_model_dir(model, model_revision=None): 9 | """get model cache dir""" 10 | if os.path.exists(model): 11 | model_cache_dir = model if os.path.isdir(model) else os.path.dirname(model) 12 | check_local_model_is_latest(model_cache_dir, user_agent={Invoke.KEY: Invoke.LOCAL_TRAINER}) 13 | else: 14 | model_cache_dir = snapshot_download( 15 | model, revision=model_revision, user_agent={Invoke.KEY: Invoke.TRAINER} 16 | ) 17 | return model_cache_dir 18 | -------------------------------------------------------------------------------- /adaseq/version.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | __version__ = '0.6.6' 3 | -------------------------------------------------------------------------------- /docs/imgs/community_qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/docs/imgs/community_qrcode.jpg -------------------------------------------------------------------------------- /docs/imgs/task_examples_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/docs/imgs/task_examples_en.png -------------------------------------------------------------------------------- /docs/imgs/task_examples_zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/docs/imgs/task_examples_zh.png -------------------------------------------------------------------------------- /docs/tutorials/model_inference_zh.md: -------------------------------------------------------------------------------- 1 | # 模型推理 2 | 3 | 以配置文件 [resume.yaml](../../examples/bert_crf/configs/resume.yaml) 为例,AdaSeq模型训练完成后,可用于推理的的模型文件和相关配置会存放于 `./experiments/resume/${RUN_NAME}/output`(modelscope>=1.3.0版本后目录变为`output_best`)。 4 | 5 | ``` 6 | ./experiments/resume/${RUN_NAME}/output 7 | ├── config.json 8 | ├── configuration.json 9 | ├── pytorch_model.bin 10 | ├── special_tokens_map.json # 可选 11 | ├── tokenizer_config.json # 可选 12 | ├── tokenizer.json # 可选 13 | └── vocab.txt # 可选 14 | ``` 15 | 16 | ### 1. 使用本地模型进行推理 17 | 18 | 可以使用以下python代码进行模型推理,其中模型路径请使用本地绝对路径。 19 | ```python 20 | from modelscope.pipelines import pipeline 21 | from modelscope.utils.constant import Tasks 22 | 23 | p = pipeline( 24 | Tasks.named_entity_recognition, 25 | '/work_dir/experiments/resume/221227191502.310576/output' # 绝对路径 26 | ) 27 | result = p('1984年出生,中国国籍,汉族,硕士学历') 28 | 29 | print(result) 30 | # {'output': [{'type': 'CONT', 'start': 8, 'end': 12, 'span': '中国国籍'}, {'type': 'RACE', 'start': 13, 'end': 15, 'span': '汉族'}, {'type': 'EDU', 'start': 16, 'end': 20, 'span': '硕士学历'}]} 31 | ``` 32 | 33 | ### 2. 使用ModelScope模型进行推理 34 | 35 | > 保存的模型可以直接发布到ModelScope,参考 [模型发布到ModelScope](./uploading_to_modelscope_zh.md) 36 | 37 | 可以使用以下python代码进行模型推理,其中模型路径请使用创建的model_id。 38 | 39 | ```python 40 | from modelscope.pipelines import pipeline 41 | from modelscope.utils.constant import Tasks 42 | 43 | p = pipeline( 44 | Tasks.named_entity_recognition, 45 | 'damo/nlp_raner_named-entity-recognition_chinese-base-resume' # model_id 46 | ) 47 | result = p('1984年出生,中国国籍,汉族,硕士学历') 48 | 49 | print(result) 50 | # {'output': [{'type': 'CONT', 'start': 8, 'end': 12, 'span': '中国国籍'}, {'type': 'RACE', 'start': 13, 'end': 15, 'span': '汉族'}, {'type': 'EDU', 'start': 16, 'end': 20, 'span': '硕士学历'}]} 51 | ``` 52 | -------------------------------------------------------------------------------- /docs/tutorials/quick_start.md: -------------------------------------------------------------------------------- 1 | # Quick Start 2 | 3 | This tutorial introduces how to install AdaSeq and use it train a model. 4 | 5 | - [1. Requirements and Installation](#1-requirements-and-installation) 6 | - [a. Installation from source](#1a-installation-from-source) 7 | - [b. Installation via pip](#1b-installation-via-pip) 8 | - [2. Example Usage](#2-example-usage) 9 | - [a. Usage by code](#2a-usage-by-code) 10 | - [b. Usage via command-line tool](#2b-usage-via-command-line-tool) 11 | 12 | ## 1. Requirements and Installation 13 | 14 | AdaSeq project is based on `Python version >= 3.7` and `PyTorch version >= 1.8`. 15 | 16 | ### 1.a Installation from source 17 | 18 | ```commandline 19 | git clone https://github.com/modelscope/adaseq.git 20 | cd adaseq 21 | pip install -r requirements.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html 22 | ``` 23 | 24 | ### 1.b Installation via pip 25 | ```commandline 26 | pip install adaseq 27 | ``` 28 | 29 | ## 2. Example Usage 30 | 31 | Let's train a Bert-CRF model for NER on the `resume` dataset as an example. All you need to do is to write a 32 | configuration file and use it to run a command. 33 | 34 | We've already prepared a configuration file [resume.yaml](../../examples/bert_crf/configs/resume.yaml) for you. Try it! 35 | 36 | ### 2.a Usage by code 37 | 38 | #### 2.a.1 Train a model 39 | ``` 40 | python scripts/train.py -c examples/bert_crf/configs/resume.yaml 41 | ``` 42 | 43 | #### (b) Test a model 44 | ``` 45 | python scripts/test.py -w ${checkpoint_dir} 46 | ``` 47 | 48 | ### 2.b Usage via command-line tool 49 | 50 | #### 2.b.1 Train a model 51 | ``` 52 | adaseq train -c examples/bert_crf/configs/resume.yaml 53 | ``` 54 | 55 | #### 2.b.2 Test a model 56 | ``` 57 | adaseq test -w ${checkpoint_dir} 58 | ``` 59 | -------------------------------------------------------------------------------- /docs/tutorials/quick_start_zh.md: -------------------------------------------------------------------------------- 1 | # 快速开始 2 | 3 | 本教程介绍如何安装 `AdaSeq` 并且使用它训练一个模型。 4 | 5 | - [1. 需求环境和安装方式](#1-需求环境和安装方式) 6 | - [a. 直接使用源代码](#1a-直接使用源代码) 7 | - [b. 使用 pip 安装](#1b-使用-pip-安装未来可用) 8 | - [2. 使用示例](#2-使用示例) 9 | - [a. 使用代码脚本](#2a-使用代码脚本) 10 | - [b. 使用命令行](#2b-使用命令未来可用) 11 | 12 | ## 1. 需求环境和安装方式 13 | 14 | AdaSeq 基于 `Python version >= 3.7` 和 `PyTorch version >= 1.8` 15 | 16 | ### 1.a 直接使用源代码 17 | 18 | ```commandline 19 | git clone https://github.com/modelscope/adaseq.git 20 | cd adaseq 21 | pip install -r requirements.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html 22 | ``` 23 | 24 | ### 1.b 使用 pip 安装 25 | ```commandline 26 | pip install adaseq 27 | ``` 28 | 29 | ## 2. 使用示例 30 | 31 | 本节将以在 `resume` 数据集上训练 BERT-CRF 模型作为示例。 32 | 训练一个模型,你只需要编写一个配置文件,然后允许一个命令即可。 33 | 34 | 我们已经准备了一个 [resume.yaml](../../examples/bert_crf/configs/resume.yaml) 配置文件,来试试吧! 35 | 36 | ### 2.a 使用代码脚本 37 | 38 | #### 2.a.1 训练模型 39 | ``` 40 | python scripts/train.py -c examples/bert_crf/configs/resume.yaml 41 | ``` 42 | 43 | #### (b) 测试模型 44 | ``` 45 | python scripts/test.py -w ${checkpoint_dir} 46 | ``` 47 | 48 | ### 2.b 使用命令 49 | 50 | #### 2.b.1 训练模型 51 | ``` 52 | adaseq train -c examples/bert_crf/configs/resume.yaml 53 | ``` 54 | 55 | #### 2.b.2 测试模型 56 | ``` 57 | adaseq test -w ${checkpoint_dir} 58 | ``` 59 | -------------------------------------------------------------------------------- /docs/tutorials/reproducing_papers.md: -------------------------------------------------------------------------------- 1 | # Reproducing Results in Published Papers 2 | 3 | AdaSeq provides several re-implementations and experiment settings of papers in the area of Sequence Understanding. You can reproduce the results simply using one command. 4 | 5 | For example, to reproduce [BABERT](../../examples/babert), you can run: 6 | ```commandline 7 | python scripts/train.py -c examples/babert/configs/cws/pku.yaml 8 | ``` 9 | 10 | *Notice*: Due to the differences in PyTorch version or AdaSeq version, the metrics MAY fluctuate within a narrow range. 11 | 12 | We are continuously working hard to re-implement more and more classic or SOTA papers in this area. And all contributions are welcome to improve AdaSeq. 13 | -------------------------------------------------------------------------------- /docs/tutorials/reproducing_papers_zh.md: -------------------------------------------------------------------------------- 1 | # 复现论文实验结果 2 | AdaSeq提供了很多序列理解相关论文的代码复现和实验参数。用户可以简单的通过一条命令来复现论文。 3 | 4 | 比如说,复现 [BABERT](../../examples/babert),你可以运行: 5 | ```commandline 6 | python scripts/train.py -c examples/babert/configs/cws/pku.yaml 7 | ``` 8 | 9 | *注意*:由于PyTorch版本的差异或者AdaSeq版本的差异,复现出的结果可能会在小范围内发生波动。 10 | 11 | 最后,我们正在持续性地复现领域中更多的经典论文和SOTA论文。我们也欢迎社区用户参与进来,一起丰富AdaSeq。 12 | -------------------------------------------------------------------------------- /docs/tutorials/training_acceleration_zh.md: -------------------------------------------------------------------------------- 1 | # 训练加速 2 | 3 | 4 | - [使用混合精度训练](#使用混合精度训练) 5 | - [使用多GPU训练](#使用多gpu训练) 6 | - [单机多卡](#单机多卡) 7 | - [多机多卡](#多机多卡) 8 | 9 | 10 | ## 使用混合精度训练 11 | 12 | 只需在训练命令中加入参数 `--use_fp16` 即可启用混合精度训练。 13 | 14 | ``` 15 | adaseq train -c ${cfg_file} --use_fp16 16 | ``` 17 | 18 | ## 使用多GPU训练 19 | 20 | 这部分的教程介绍如何使用多块GPU训练模型。 21 | 22 | ### 单机多卡 23 | ```shell 24 | python -m torch.distributed.launch --nproc_per_node=${NUMBER_GPUS} --master_port=${MASTER_PORT} scripts/train.py -c ${cfg_file} 25 | ``` 26 | - **nproc_per_node** (`int`): 当前主机创建的进程数(使用的GPU个数), 例如 `--nproc_per_node=8`。 27 | - **master_port** (`int`): 主节点的端口号,例如 `--master_port=29527`。 28 | 29 | ### 多机多卡 30 | 比如说,我们有两个节点(机器): 31 | 32 | Node 1: 33 | ```shell 34 | python -m torch.distributed.launch --nproc_per_node=${NUMBER_GPUS} --nnodes=2 --node_rank=0 --master_addr=${MASTER_IP_ADDRESS} --master_port=${MASTER_PORT} scripts/train.py -c ${cfg_file} 35 | ``` 36 | 37 | Node 2: 38 | ```shell 39 | python -m torch.distributed.launch --nproc_per_node=${NUMBER_GPUS} --nnodes=2 --node_rank=1 --master_addr=${MASTER_IP_ADDRESS} --master_port=${MASTER_PORT} scripts/train.py -c ${cfg_file} 40 | ``` 41 | - **nproc_per_node**(`int`): 当前主机创建的进程数(使用的GPU个数), 例如 `--nproc_per_node=8`。 42 | - **nnodes**(`int`): 节点的个数。 43 | - **node_rank**(`int`): 当前节点的索引值,从0开始。 44 | - **master_addr**(`int`): 主节点的ip地址,例如 `--master_addr=192.168.1.1`。 45 | - **master_port**(`int`): 主节点的端口号,例如 `--master_port=29527`。 46 | 47 | ### [可选] 修改配置文件 48 | 如果运行中发生RuntimeError,可以尝试加入下面这段代码到你的配置文件中。 49 | ```yaml 50 | parallel: 51 | type: DistributedDataParallel 52 | find_unused_parameters: true 53 | ``` 54 | -------------------------------------------------------------------------------- /docs/tutorials/training_with_multiple_gpus.md: -------------------------------------------------------------------------------- 1 | # Training with Multiple GPUs 2 | This part of tutorial shows how you can train models with multiple GPUs. 3 | 4 | ## single machine & multi gpus 5 | ```shell 6 | python -m torch.distributed.launch --nproc_per_node=${NUMBER_GPUS} --master_port=${MASTER_PORT} scripts/train.py -c ${cfg_file} 7 | ``` 8 | - **nproc_per_node** (`int`): Number of GPUs in the current machine, for example `--nproc_per_node=8`. 9 | - **master_port** (`int`): Master port, for example `--master_port=29527`. 10 | 11 | ## multi machines & multi gpus 12 | For example, we have 2 nodes. 13 | 14 | Node 1: 15 | ```shell 16 | python -m torch.distributed.launch --nproc_per_node=${NUMBER_GPUS} --nnodes=2 --node_rank=0 --master_addr=${MASTER_IP_ADDRESS} --master_port=${MASTER_PORT} scripts/train.py -c ${cfg_file} 17 | ``` 18 | 19 | Node 2: 20 | ```shell 21 | python -m torch.distributed.launch --nproc_per_node=${NUMBER_GPUS} --nnodes=2 --node_rank=1 --master_addr=${MASTER_IP_ADDRESS} --master_port=${MASTER_PORT} scripts/train.py -c ${cfg_file} 22 | ``` 23 | - **nproc_per_node**(`int`): Number of GPUs in the current machine, for example `--nproc_per_node=8`. 24 | - **nnodes**(`int`): Number of nodes. 25 | - **node_rank**(`int`): Rank of current node, starting from 0. 26 | - **master_addr**(`int`): Master IP, for example `--master_addr=192.168.1.1`. 27 | - **master_port**(`int`): Master port, for example `--master_port=29527`. 28 | 29 | ## [Optional] Modify configuration file 30 | Add this script to the end of your configuration file when RuntimeError occurs. 31 | ```yaml 32 | parallel: 33 | type: DistributedDataParallel 34 | find_unused_parameters: true 35 | ``` 36 | -------------------------------------------------------------------------------- /docs/tutorials/uploading_to_modelscope_zh.md: -------------------------------------------------------------------------------- 1 | # 模型发布到 ModelScope 2 | 3 | 1. 在ModelScope官网点击右上角 "+创建" -> "创建模型" 4 | 2. 填写模型基本信息,点击"创建模型" 5 | 3. 本地运行命令,初始化模型仓库 6 | 7 | ``` 8 | git clone https://www.modelscope.cn/${model_id}.git 9 | ``` 10 | 11 | 4. 将训练后保存的`output` 文件夹中的所有文件拷贝到模型仓库 12 | 5. 编辑README.md,填写模型卡片说明,详见 [如何撰写好用的模型卡片](https://www.modelscope.cn/docs/如何撰写好用的模型卡片) 13 | 6. 在模型仓库,运行以下命令,将模型上传到ModelScope 14 | 15 | ``` 16 | git add . 17 | git commit -m "upload my model" 18 | git push origin master 19 | ``` 20 | 21 | 7. 然后就可以直接使用ModelScope进行推理了,详见 [模型推理](./model_inference_zh.md) 22 | -------------------------------------------------------------------------------- /examples/ICASSP2023_MUG_track4/configs/bert_crf_nezha.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments 3 | exp_name: kpe_nezha 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_type: conll 10 | data_file: 11 | train: ${root_dir}/examples/ICASSP2023_MUG_track4/dataset/processed_train.json.txt 12 | dev: ${root_dir}/examples/ICASSP2023_MUG_track4/dataset/processed_dev.json.txt 13 | test: ${root_dir}/examples/ICASSP2023_MUG_track4/dataset/processed_dev.json.txt 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | model_dir: bert-base-chinese 18 | max_length: 192 19 | 20 | data_collator: SequenceLabelingDataCollatorWithPadding 21 | 22 | model: 23 | type: sequence-labeling-model 24 | embedder: 25 | model_name_or_path: sijunhe/nezha-cn-base 26 | dropout: 0.1 27 | use_crf: true 28 | 29 | train: 30 | max_epochs: 10 31 | dataloader: 32 | batch_size_per_gpu: 64 33 | optimizer: 34 | type: AdamW 35 | lr: 2.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 10 44 | 45 | evaluation: 46 | dataloader: 47 | batch_size_per_gpu: 256 48 | metrics: 49 | - type: ner-metric 50 | - type: ner-dumper 51 | model_type: sequence_labeling 52 | dump_format: conll 53 | -------------------------------------------------------------------------------- /examples/ICASSP2023_MUG_track4/configs/bert_crf_sbert.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments 3 | exp_name: kpe_sbert 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_type: conll 10 | data_file: 11 | train: ${root_dir}/examples/ICASSP2023_MUG_track4/dataset/processed_train.json.txt 12 | dev: ${root_dir}/examples/ICASSP2023_MUG_track4/dataset/processed_dev.json.txt 13 | test: ${root_dir}/examples/ICASSP2023_MUG_track4/dataset/processed_dev.json.txt 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | model_dir: bert-base-chinese 18 | max_length: 192 19 | 20 | data_collator: SequenceLabelingDataCollatorWithPadding 21 | 22 | model: 23 | type: sequence-labeling-model 24 | embedder: 25 | model_name_or_path: damo/nlp_structbert_backbone_base_std 26 | dropout: 0.1 27 | use_crf: true 28 | 29 | train: 30 | max_epochs: 10 31 | dataloader: 32 | batch_size_per_gpu: 64 33 | optimizer: 34 | type: AdamW 35 | lr: 2.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 10 44 | 45 | evaluation: 46 | dataloader: 47 | batch_size_per_gpu: 256 48 | shuffle: false 49 | metrics: 50 | - type: ner-metric 51 | - type: ner-dumper 52 | model_type: sequence_labeling 53 | dump_format: conll 54 | -------------------------------------------------------------------------------- /examples/ICASSP2023_MUG_track4/dataset/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/ICASSP2023_MUG_track4/dataset/.gitkeep -------------------------------------------------------------------------------- /examples/ICASSP2023_MUG_track4/download.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sys 3 | 4 | from modelscope.hub.api import HubApi 5 | from modelscope.msdatasets import MsDataset 6 | from modelscope.utils.constant import DownloadMode 7 | from preprocess import process_data 8 | 9 | 10 | def csv2json(csv_name, out_name='test.json'): 11 | data_frame = pd.read_csv(csv_name, sep='\t') 12 | jsons = [] 13 | for i, row in data_frame.iterrows(): 14 | content = json.loads(row['content']) 15 | jsons.append(content) 16 | data_dir = csv_name.split('/')[0] 17 | f = open(f'{data_dir}/{out_name}', 'w') 18 | json.dump(jsons, f, ensure_ascii=False) 19 | return jsons 20 | 21 | 22 | def data2json(data, out_name='test.json'): 23 | jsons = [] 24 | for eve in data: 25 | content = json.loads(eve['content']) 26 | jsons.append(content) 27 | f = open(out_name, 'w') 28 | json.dump(jsons, f, ensure_ascii=False) 29 | return jsons 30 | 31 | 32 | if __name__ == '__main__': 33 | api = HubApi() 34 | sdk_token = sys.argv[1] # 必填, 从modelscope WEB端个人中心获取 35 | print('sdk_token is', sdk_token) 36 | api.login(sdk_token) # online 37 | 38 | input_config_kwargs = {'delimiter': '\t'} 39 | data = MsDataset.load( 40 | 'Alimeeting4MUG', 41 | namespace='modelscope', 42 | download_mode=DownloadMode.FORCE_REDOWNLOAD, 43 | subset_name='default', 44 | **input_config_kwargs, 45 | ) 46 | 47 | # print(data["test"][0]) 48 | dataset = 'dataset' 49 | data2json(data['train'], f'{dataset}/train.json') 50 | data2json(data['validation'], f'{dataset}/dev.json') 51 | data2json(data['test'], f'{dataset}/test.json') 52 | test_doc, test = process_data(f'{dataset}/test.json') 53 | dev_doc, dev = process_data(f'{dataset}/dev.json') 54 | train_doc, train = process_data(f'{dataset}/train.json') 55 | -------------------------------------------------------------------------------- /examples/ICASSP2023_MUG_track4/end2end.sh: -------------------------------------------------------------------------------- 1 | # download files 2 | export root_dir=`pwd` 3 | export comp_dir=$root_dir/examples/ICASSP2023_MUG_track4 4 | export yaml=$comp_dir/configs/bert_crf_sbert.yaml 5 | export data_dir=dataset 6 | 7 | 8 | # download and preprocess data 9 | cd $comp_dir 10 | mkdir -p $data_dir 11 | if [ $1 ] 12 | then 13 | python download.py $1 14 | else 15 | echo "please pass your sdk_token, which can be achieved from 'personal center' of MODELSCOPE HOME PAGE. " 16 | echo "e.g. ./end2end.sh 3af3-faega-geagea" 17 | exit 18 | fi 19 | # start training 20 | cd $root_dir 21 | echo $root_dir 22 | echo "start training...." 23 | sed -i "s?\${root_dir}?${root_dir}?g" $yaml 24 | 25 | python scripts/train.py -c $yaml 26 | 27 | export best_path=`find experiments/kpe_* -name best_model.pth | tail -1` 28 | export exp_path=${best_path%/*} 29 | echo "exp path is $exp_path" 30 | 31 | # start evaluating on dev... 32 | echo "start evaluating on dev..." 33 | pip install jieba rouge yake 34 | cd $comp_dir 35 | python evaluate_kw.py $data_dir/dev.json ../../$exp_path/pred.txt $data_dir/split_list_dev.json evaluation.log 36 | 37 | # output test 38 | echo "start predicting on test set...." 39 | cd ${root_dir} 40 | sed -i 's/_dev/_test/g' $exp_path/config.yaml 41 | python scripts/test.py -w $exp_path 42 | echo "have predicted test file" 43 | mv $exp_path/pred.txt $exp_path/pred_test.txt 44 | 45 | cd $comp_dir 46 | python get_keywords.py $data_dir/test.json $root_dir/$exp_path/pred_test.txt $data_dir/split_list_test.json submit.json 47 | echo "predictions on test set has been output to $comp_dir/submit.json" 48 | -------------------------------------------------------------------------------- /examples/ICASSP2023_MUG_track4/get_keywords.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sys 3 | 4 | from test_challenge import load_json_file 5 | 6 | MEETING_KEY = 'meeting_key' 7 | KEYWORD = 'key_word' 8 | 9 | 10 | def get_predictions(cur_tagging): 11 | j = 0 12 | predictions = set({}) 13 | word = '' 14 | for cur_line in cur_tagging: 15 | if not cur_line: 16 | continue 17 | char, label, predict = cur_line.split('\t') 18 | if predict[0] in 'BSO': 19 | if word: 20 | predictions.add(word) 21 | word = '' 22 | if predict[0] in 'BIES': 23 | word += char 24 | if word: 25 | predictions.add(word) 26 | return predictions 27 | 28 | 29 | if __name__ == '__main__': 30 | 31 | if len(sys.argv) != 5: 32 | print('Usage: python ') 33 | exit(1) 34 | 35 | testdata = load_json_file(sys.argv[1]) 36 | tagging = open(sys.argv[2], 'r').read().split('\n') 37 | split_doc = load_json_file(sys.argv[3]) 38 | out_path = sys.argv[4] 39 | output_f = open(out_path, 'w') 40 | for i, document in enumerate(testdata): 41 | cur_outputs = tagging[split_doc[i] : split_doc[i + 1]] 42 | cur_key_words = list(get_predictions(cur_outputs)) 43 | cur_data = json.dumps( 44 | {MEETING_KEY: document[MEETING_KEY], KEYWORD: cur_key_words}, ensure_ascii=False 45 | ) 46 | output_f.write(cur_data + '\n') 47 | output_f.close() 48 | -------------------------------------------------------------------------------- /examples/MCCE/README.md: -------------------------------------------------------------------------------- 1 | # Recall, Expand and Multi-Candidate Cross-Encode: Fast and Accurate Ultra-Fine Entity Typing 2 | Code of the paper: Recall, Expand and Multi-Candidate Cross-Encode: Fast and Accurate Ultra-Fine Entity Typing. 3 | In preparation, the code will be released soon. 4 | -------------------------------------------------------------------------------- /examples/MCCE/configs/ufet_concat_mcce_threshold_tuning.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ufet_mcce 4 | seed: 42 5 | 6 | task: mcce-entity-typing 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=train.json' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=dev.json' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=test.json' 13 | cand: PATH_TO_CAND 14 | tokenizer: blank 15 | labels: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=labels.txt' 16 | 17 | preprocessor: 18 | type: multilabel-concat-typing-mcce-preprocessor 19 | max_length: 300 20 | cand_size: 256 21 | 22 | data_collator: MultiLabelConcatTypingDataCollatorWithPadding 23 | 24 | model: 25 | type: multilabel-concat-typing-model-mcce-s 26 | embedder: 27 | model_name_or_path: roberta-base 28 | drop_special_tokens: false 29 | dropout: 0 30 | decoder: 31 | type: linear 32 | loss_function: WBCE 33 | pos_weight: 1 34 | 35 | train: 36 | trainer: typing-trainer 37 | max_epochs: 20 38 | dataloader: 39 | batch_size_per_gpu: 4 40 | optimizer: 41 | type: AdamW 42 | lr: 1.0e-5 43 | lr_scheduler: 44 | type: cosine 45 | warmup_rate: 0 46 | options: 47 | by_epoch: false 48 | hooks: 49 | - type: "CheckpointHook" 50 | interval: 100 51 | - type: "BestCkptSaverHook" 52 | save_file_name: "best_model.pth" 53 | - type: "EvaluationHook" 54 | interval: 100 55 | by_epoch: False 56 | 57 | evaluation: 58 | dataloader: 59 | batch_size_per_gpu: 32 60 | metrics: typing-threshold-metric 61 | -------------------------------------------------------------------------------- /examples/MoRe/configs/mnre-img.yaml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/MoRe/configs/mnre-img.yaml -------------------------------------------------------------------------------- /examples/MoRe/configs/snap-img.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-snap-img 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=snap-img.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: true 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 1 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 1.0e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/snap-txt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-snap-txt 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=snap-txt.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: true 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 0.5 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 2.5e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/snap.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-snap 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=snap.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: xlm-roberta-large 23 | word_dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 10 28 | dataloader: 29 | batch_size_per_gpu: 4 30 | optimizer: 31 | type: AdamW 32 | lr: 5.0e-6 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 10 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 32 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/MoRe/configs/twitter-15-img.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-twitter-15-img 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=twitter2015-img.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: false 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 0.0 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 2.5e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/twitter-15-txt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-twitter-15-txt 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=twitter2015-txt.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: true 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 1 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 1.0e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/twitter-15.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-twitter-15 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=twitter2015.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: xlm-roberta-large 23 | word_dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 10 28 | dataloader: 29 | batch_size_per_gpu: 4 30 | optimizer: 31 | type: AdamW 32 | lr: 1.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 10 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 32 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/MoRe/configs/twitter-17-img.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-twitter-17-img 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=twitter2017-img.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: false 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 0.0 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 5.0e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/twitter-17-txt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-twitter-17-txt 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=twitter2017-txt.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: true 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 1 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 1.0e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/twitter-17.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-twitter-17 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=twitter2017.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: xlm-roberta-large 23 | word_dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 10 28 | dataloader: 29 | batch_size_per_gpu: 4 30 | optimizer: 31 | type: AdamW 32 | lr: 1.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 10 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 32 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/MoRe/configs/wikidiverse-img.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-wikidiverse-img 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=WikiDiverseNER-img.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: true 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 1.0 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 2.5e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/wikidiverse-txt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-wikidiverse-txt 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=WikiDiverseNER-txt.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | model_dir: xlm-roberta-large 15 | max_length: 512 16 | return_original_view: true 17 | 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: xlm-roberta-large 25 | word_dropout: 0.1 26 | use_crf: true 27 | multiview: false 28 | mv_interpolation: 0.5 29 | mv_loss_type: crf_kl 30 | temperature: 0.0 31 | 32 | train: 33 | max_epochs: 15 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-6 39 | param_groups: 40 | - regex: crf 41 | lr: 2.5e-2 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 15 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/MoRe/configs/wikidiverse.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: more-wikidiverse 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://modelscope.cn/api/v1/datasets/caijiong_sijun/MoRE-processed-data/repo/files?Revision=master&FilePath=WikiDiverseNER.zip' 10 | data_type: conll 11 | 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | model_dir: xlm-roberta-large 16 | max_length: 512 17 | 18 | data_collator: SequenceLabelingDataCollatorWithPadding 19 | 20 | model: 21 | type: sequence-labeling-model 22 | embedder: 23 | model_name_or_path: xlm-roberta-large 24 | word_dropout: 0.1 25 | use_crf: true 26 | 27 | train: 28 | max_epochs: 10 29 | dataloader: 30 | batch_size_per_gpu: 4 31 | optimizer: 32 | type: AdamW 33 | lr: 1.0e-5 34 | param_groups: 35 | - regex: crf 36 | lr: 5.0e-2 37 | lr_scheduler: 38 | type: LinearLR 39 | start_factor: 1.0 40 | end_factor: 0.0 41 | total_iters: 10 42 | 43 | evaluation: 44 | dataloader: 45 | batch_size_per_gpu: 32 46 | metrics: 47 | - type: ner-metric 48 | - type: ner-dumper 49 | model_type: sequence_labeling 50 | dump_format: conll 51 | -------------------------------------------------------------------------------- /examples/MoRe/resource/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/MoRe/resource/img.png -------------------------------------------------------------------------------- /examples/NPCRF/README.md: -------------------------------------------------------------------------------- 1 | # Neural Pairwise Conditional Random Field for Ultra-Fine Entity Typing 2 | 3 | The NPCRF module proposed in the EMNLP 2022 paper: Modeling Label Correlations for Ultra-Fine Entity Typing with 4 | Neural Pairwise Conditional Random Field. NPCRF performs mean-field variational inference on a probabilistic model 5 | designed for better modeling label correlations in ultra-fine entity typing task. 6 | ![](resource/img.png) 7 | 8 | ## Static Label Embeding 9 | NPCRF requires static label embeddings, the preprocessed label embeddings (from [GloVe](https://nlp.stanford.edu/projects/glove/) for EN, Tencent for ZH) 10 | can be downloaded here: [UFET](https://drive.google.com/file/d/1cizhVviRtBohmBkwlC6V2fhmJGeA0rAJ/view?usp=share_link), [CFET](https://drive.google.com/file/d/1cizhVviRtBohmBkwlC6V2fhmJGeA0rAJ/view?usp=share_link), 11 | and you can place them in yoru folder and run the following config: (you need to reset your **target_emb_dir** in the config). 12 | Or you can provide the path of the glove embedding file (e.g., /path/to/your/glove.6B.300d.txt) and the code will generate label embedding for you. 13 | 14 | ## Example of Training a model with NPCRF 15 | ``` 16 | python -m scripts.train -c examples/npcrf/configs/ufet_concat_npcrf.yaml 17 | ``` 18 | 19 | ## Benchmarks 20 | | UFET | ma-F1 | ma-P | ma-R | 21 | |---------------------|-------|------|------| 22 | | NPCRF-roberta-large | 47.1 | 49.5 | 44.9 | 23 | -------------------------------------------------------------------------------- /examples/NPCRF/configs/cfet_concat_mlc.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: cfet 4 | seed: 42 5 | 6 | task: entity-typing 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=train.json' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=dev.json' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=test.json' 13 | tokenizer: char 14 | labels: 15 | type: count_span_labels 16 | 17 | preprocessor: 18 | type: multilabel-concat-typing-preprocessor 19 | model_dir: sijunhe/nezha-cn-base 20 | max_length: 500 21 | 22 | data_collator: MultiLabelConcatTypingDataCollatorWithPadding 23 | 24 | model: 25 | type: multilabel-concat-typing-model 26 | embedder: 27 | model_name_or_path: sijunhe/nezha-cn-base 28 | drop_special_tokens: false 29 | dropout: 0.1 30 | decoder: 31 | type: linear 32 | loss_function: WBCE 33 | pos_weight: 2 34 | 35 | train: 36 | max_epochs: 50 37 | dataloader: 38 | batch_size_per_gpu: 16 39 | optimizer: 40 | type: AdamW 41 | lr: 5.0e-5 42 | lr_scheduler: 43 | type: cosine 44 | warmup_rate: 0.1 # when choose concat typing model, default to use cosine_linear_with_warmup 45 | options: 46 | by_epoch: false 47 | hooks: 48 | - type: "CheckpointHook" 49 | interval: 100 50 | - type: "BestCkptSaverHook" 51 | save_file_name: "best_model.pt" 52 | 53 | evaluation: 54 | dataloader: 55 | batch_size_per_gpu: 32 56 | metrics: typing-metric 57 | -------------------------------------------------------------------------------- /examples/NPCRF/configs/cfet_concat_npcrf.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: cfet 4 | seed: 42 5 | 6 | task: entity-typing 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=train.json' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=dev.json' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=test.json' 13 | tokenizer: char 14 | 15 | preprocessor: 16 | type: multilabel-concat-typing-preprocessor 17 | model_dir: sijunhe/nezha-cn-base 18 | max_length: 500 19 | 20 | data_collator: MultiLabelConcatTypingDataCollatorWithPadding 21 | 22 | model: 23 | type: multilabel-concat-typing-model 24 | embedder: 25 | model_name_or_path: sijunhe/nezha-cn-base 26 | drop_special_tokens: false 27 | dropout: 0.1 28 | decoder: 29 | type: pairwise-crf 30 | label_emb_type: tencent 31 | label_emb_dim: 200 32 | source_emb_file_path: ${PATH_TO_DIR}/tencent-ailab-embedding-zh-d200-v0.2.0.txt 33 | target_emb_dir: ${PATH_TO_DIR} # TODO 34 | target_emb_name: tencent.200.emb 35 | pairwise_factor: 30 36 | mfvi_iteration: 6 37 | loss_function: WBCE 38 | pos_weight: 2 39 | 40 | train: 41 | max_epochs: 50 42 | dataloader: 43 | batch_size_per_gpu: 16 44 | optimizer: 45 | type: AdamW 46 | lr: 5.0e-5 47 | lr_scheduler: 48 | type: cosine 49 | warmup_rate: 0.1 # when choose concat typing model, default to use cosine_linear_with_warmup 50 | options: 51 | by_epoch: false 52 | hooks: 53 | - type: "CheckpointHook" 54 | interval: 100 55 | - type: "BestCkptSaverHook" 56 | save_file_name: "best_model.pt" 57 | 58 | evaluation: 59 | dataloader: 60 | batch_size_per_gpu: 32 61 | metrics: typing-metric 62 | -------------------------------------------------------------------------------- /examples/NPCRF/configs/ufet_concat_mlc.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ufet 4 | seed: 42 5 | 6 | task: entity-typing 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=train.json' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=dev.json' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=test.json' 13 | tokenizer: blank 14 | lower: true 15 | labels: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=labels.txt' 16 | 17 | preprocessor: 18 | type: multilabel-concat-typing-preprocessor 19 | model_dir: roberta-large 20 | max_length: 150 21 | 22 | data_collator: MultiLabelConcatTypingDataCollatorWithPadding 23 | 24 | model: 25 | type: multilabel-concat-typing-model 26 | embedder: 27 | model_name_or_path: roberta-large 28 | drop_special_tokens: false 29 | dropout: 0 30 | decoder: 31 | type: linear 32 | loss_function: WBCE 33 | pos_weight: 4 34 | 35 | train: 36 | max_epochs: 100 37 | dataloader: 38 | batch_size_per_gpu: 8 39 | optimizer: 40 | type: AdamW 41 | lr: 2.0e-5 42 | lr_scheduler: 43 | type: cosine 44 | warmup_rate: 0.1 # when choose concat typing model, default to use cosine_linear_with_warmup 45 | options: 46 | by_epoch: false 47 | hooks: 48 | - type: "CheckpointHook" 49 | interval: 100 50 | - type: "BestCkptSaverHook" 51 | save_file_name: "best_model.pt" 52 | 53 | evaluation: 54 | dataloader: 55 | batch_size_per_gpu: 32 56 | metrics: typing-metric 57 | -------------------------------------------------------------------------------- /examples/NPCRF/configs/ufet_concat_mlc_128.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ufet 4 | seed: 42 5 | 6 | task: entity-typing 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=train.json' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=dev.json' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=test.json' 13 | tokenizer: blank 14 | lower: true 15 | labels: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ufet/repo/files?Revision=master&FilePath=labels.txt' 16 | 17 | preprocessor: 18 | type: multilabel-concat-typing-preprocessor 19 | model_dir: roberta-large 20 | max_length: 150 21 | 22 | data_collator: MultiLabelConcatTypingDataCollatorWithPadding 23 | 24 | model: 25 | type: multilabel-concat-typing-model 26 | embedder: 27 | model_name_or_path: roberta-large 28 | drop_special_tokens: false 29 | dropout: 0 30 | decoder: 31 | type: linear 32 | loss_function: WBCE 33 | pos_weight: 4 34 | top_k: 128 35 | 36 | train: 37 | max_epochs: 100 38 | dataloader: 39 | batch_size_per_gpu: 8 40 | optimizer: 41 | type: AdamW 42 | lr: 2.0e-5 43 | lr_scheduler: 44 | type: cosine 45 | warmup_rate: 0.1 46 | options: 47 | by_epoch: false 48 | hooks: 49 | - type: "CheckpointHook" 50 | interval: 100 51 | - type: "BestCkptSaverHook" 52 | save_file_name: "best_model.pt" 53 | metric_key: "recall" 54 | 55 | evaluation: 56 | dataloader: 57 | batch_size_per_gpu: 32 58 | metrics: typing-metric 59 | -------------------------------------------------------------------------------- /examples/NPCRF/resource/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/NPCRF/resource/img.png -------------------------------------------------------------------------------- /examples/RaNER/configs/wnut17.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: wnut17_ra 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut17_ner/repo/files?Revision=master&FilePath=train.txt.ret' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut17_ner/repo/files?Revision=master&FilePath=dev.txt.ret' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut17_ner/repo/files?Revision=master&FilePath=test.txt.ret' 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | # return_original_view: true 18 | max_length: 512 19 | 20 | data_collator: SequenceLabelingDataCollatorWithPadding 21 | 22 | model: 23 | type: sequence-labeling-model 24 | # multiview: true 25 | embedder: 26 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 27 | dropout: 0.1 28 | use_crf: true 29 | 30 | train: 31 | max_epochs: 20 32 | dataloader: 33 | batch_size_per_gpu: 4 34 | optimizer: 35 | type: AdamW 36 | lr: 5.0e-6 37 | param_groups: 38 | - regex: crf 39 | lr: 5.0e-2 40 | lr_scheduler: 41 | type: LinearLR 42 | start_factor: 1.0 43 | end_factor: 0.0 44 | total_iters: 20 45 | 46 | evaluation: 47 | dataloader: 48 | batch_size_per_gpu: 32 49 | metrics: ner-metric 50 | -------------------------------------------------------------------------------- /examples/RaNER/resources/model_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/RaNER/resources/model_image.jpg -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/bn.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-bn 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: bn 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 5.0e-6 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/de.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-de 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: de 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/en.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-en 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: en 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/es.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-es 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: es 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/fa.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-fa 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: fa 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/fr.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-fr 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: fr 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/hi.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-hi 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: hi 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/it.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-it 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: it 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 5.0e-6 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/pt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-pt 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: pt 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/sv.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-sv 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: sv 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/uk.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-uk 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: uk 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/orig/zh.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-zh 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023 11 | subset_name: zh 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/bn.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-bn-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: bn 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/de.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-de-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: de 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/en.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-en-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: en 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/es.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-es-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: es 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/fa.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-fa-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: fa 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/fr.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-fr-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: fr 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/hi.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-hi-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: hi 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/it.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-it-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: it 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/pt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-pt-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: pt 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/sv.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-sv-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: sv 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/uk.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-uk-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: uk 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki128/zh.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-zh-wiki128 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki128 11 | subset_name: zh 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 150 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-2 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | hooks: 42 | - type: BestCkptSaverHook 43 | save_file_name: best_model.pth 44 | metric_key: macro-f1 45 | save_optimizer: false 46 | restore_best: true 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 32 51 | metrics: 52 | - type: ner-metric 53 | return_macro_f1: true 54 | - type: ner-dumper 55 | model_type: sequence_labeling 56 | dump_format: conll 57 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/bn.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-bn-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: bn 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/de.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-de-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: de 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/en.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-en-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: en 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/es.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-es-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: es 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/fa.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-fa-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: fa 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/fr.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-fr-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: fr 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/hi.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-hi-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: hi 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/it.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-it-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: it 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/pt.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-pt-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: pt 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/sv.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-sv-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: sv 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/uk.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-uk-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: uk 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/configs/wiki2048/zh.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: multiconer2-zh-wiki2048 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | namespace: pangda 10 | name: multico_ner_2023_wiki2048 11 | subset_name: zh 12 | 13 | preprocessor: 14 | type: sequence-labeling-preprocessor 15 | max_length: 1024 16 | chunk_size: 256 17 | chunk_num: 4 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | chunk: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 8 33 | optimizer: 34 | type: AdamW 35 | lr: 1.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 5.0e-2 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | hooks: 45 | - type: BestCkptSaverHook 46 | save_file_name: best_model.pth 47 | metric_key: macro-f1 48 | save_optimizer: false 49 | restore_best: true 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 32 54 | metrics: 55 | - type: ner-metric 56 | return_macro_f1: true 57 | - type: ner-dumper 58 | model_type: sequence_labeling 59 | dump_format: conll 60 | -------------------------------------------------------------------------------- /examples/SemEval2023_MultiCoNER_II/resource/raner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/SemEval2023_MultiCoNER_II/resource/raner.jpg -------------------------------------------------------------------------------- /examples/U-RaNER/resources/U-RaNER.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/U-RaNER/resources/U-RaNER.jpg -------------------------------------------------------------------------------- /examples/babert/configs/cws/ctb6.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ctb6 4 | 5 | task: word-segmentation 6 | 7 | dataset: 8 | data_file: ${PATH_TO_DATASET} 9 | data_type: conll 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: babert-base 14 | max_length: 256 15 | bio2bioes: true 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: babert-base 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 2.0e-5 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 128 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/babert/configs/cws/msra.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: msra 4 | 5 | task: word-segmentation 6 | 7 | dataset: 8 | name: msra_cws 9 | namespace: izhx404 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: babert-base 14 | max_length: 256 15 | bio2bioes: true 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: babert-base 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 2.0e-5 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 128 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/babert/configs/cws/pku.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: pku 4 | 5 | task: word-segmentation 6 | 7 | dataset: 8 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/pku_cws/repo/files?Revision=master&FilePath=pku.zip' 9 | data_type: conll 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: bert-base-chinese 14 | max_length: 256 15 | bio2bioes: true 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: bert-base-chinese 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 2.0e-5 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 128 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/babert/configs/ner/ontonotes4.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ontonotes4 4 | 5 | task: named-entity-recognition 6 | 7 | dataset: 8 | data_file: ${PATH_TO_DATASET} 9 | data_type: conll 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: babert-base 14 | max_length: 256 15 | bio2bioes: true 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: babert-base 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 2.0e-1 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 30 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 128 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/babert/configs/pos/ctb6.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ctb6 4 | 5 | task: part-of-speech 6 | 7 | dataset: 8 | data_file: ${PATH_TO_DATASET} 9 | data_type: conll 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: babert-base 14 | max_length: 256 15 | bio2bioes: false 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: babert-base 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 20 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 5.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-1 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 20 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 128 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/babert/configs/pos/ud1.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ud1 4 | 5 | task: part-of-speech 6 | 7 | dataset: 8 | name: ud1_pos 9 | namespace: izhx404 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: bert-base 14 | max_length: 256 15 | bio2bioes: true 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: babert-base 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | lr_scheduler: 34 | type: LinearLR 35 | start_factor: 1.0 36 | end_factor: 0.0 37 | total_iters: 30 38 | 39 | evaluation: 40 | dataloader: 41 | batch_size_per_gpu: 128 42 | metrics: 43 | - type: ner-metric 44 | - type: ner-dumper 45 | model_type: sequence_labeling 46 | dump_format: conll 47 | -------------------------------------------------------------------------------- /examples/babert/configs/pos/ud2.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ud2 4 | 5 | task: part-of-speech 6 | 7 | dataset: 8 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/ud1_pos/repo/files?Revision=master&FilePath=ud2.zip' 9 | data_type: conll 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: babert-base 14 | max_length: 256 15 | bio2bioes: true 16 | 17 | data_collator: SequenceLabelingDataCollatorWithPadding 18 | 19 | model: 20 | type: sequence-labeling-model 21 | embedder: 22 | model_name_or_path: babert-base 23 | dropout: 0.1 24 | use_crf: true 25 | 26 | train: 27 | max_epochs: 30 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 2.0e-5 33 | lr_scheduler: 34 | type: LinearLR 35 | start_factor: 1.0 36 | end_factor: 0.0 37 | total_iters: 30 38 | 39 | evaluation: 40 | dataloader: 41 | batch_size_per_gpu: 128 42 | metrics: 43 | - type: ner-metric 44 | - type: ner-dumper 45 | model_type: sequence_labeling 46 | dump_format: conll 47 | -------------------------------------------------------------------------------- /examples/babert/resource/babert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/examples/babert/resource/babert.png -------------------------------------------------------------------------------- /examples/bert_crf/configs/conll03.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: conll03 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: https://data.deepai.org/conll2003.zip 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | max_length: 100 15 | 16 | data_collator: SequenceLabelingDataCollatorWithPadding 17 | 18 | model: 19 | type: sequence-labeling-model 20 | embedder: 21 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 22 | dropout: 0.1 23 | use_crf: true 24 | 25 | train: 26 | max_epochs: 20 27 | dataloader: 28 | batch_size_per_gpu: 16 29 | optimizer: 30 | type: AdamW 31 | lr: 5.0e-6 32 | param_groups: 33 | - regex: crf 34 | lr: 5.0e-2 35 | lr_scheduler: 36 | type: LinearLR 37 | start_factor: 1.0 38 | end_factor: 0.0 39 | total_iters: 20 40 | 41 | evaluation: 42 | dataloader: 43 | batch_size_per_gpu: 128 44 | metrics: 45 | - type: ner-metric 46 | - type: ner-dumper 47 | model_type: sequence_labeling 48 | dump_format: conll 49 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/conllpp.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: conllpp 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/conllpp_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/conllpp_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/conllpp_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | max_length: 100 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | 28 | train: 29 | max_epochs: 20 30 | dataloader: 31 | batch_size_per_gpu: 16 32 | optimizer: 33 | type: AdamW 34 | lr: 5.0e-6 35 | param_groups: 36 | - regex: crf 37 | lr: 5.0e-2 38 | lr_scheduler: 39 | type: LinearLR 40 | start_factor: 1.0 41 | end_factor: 0.0 42 | total_iters: 20 43 | 44 | evaluation: 45 | dataloader: 46 | batch_size_per_gpu: 128 47 | metrics: 48 | - type: ner-metric 49 | - type: ner-dumper 50 | model_type: sequence_labeling 51 | dump_format: conll 52 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/ctb6_pos.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: ctb6 4 | seed: 42 5 | 6 | task: part-of-speech 7 | 8 | dataset: 9 | data_file: 10 | train: https://modelscope.cn/api/v1/datasets/dingkun/chinese_pos_ctb6/repo?Revision=master&FilePath=train.txt 11 | dev: https://modelscope.cn/api/v1/datasets/dingkun/chinese_pos_ctb6/repo?Revision=master&FilePath=dev.txt 12 | test: https://modelscope.cn/api/v1/datasets/dingkun/chinese_pos_ctb6/repo?Revision=master&FilePath=test.txt 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | max_length: 256 18 | tag_scheme: BIES 19 | 20 | data_collator: SequenceLabelingDataCollatorWithPadding 21 | 22 | model: 23 | type: sequence-labeling-model 24 | embedder: 25 | model_name_or_path: damo/nlp_structbert_part-of-speech_chinese-base 26 | dropout: 0.1 27 | use_crf: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 16 33 | optimizer: 34 | type: AdamW 35 | lr: 2.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 2.0e-1 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | 45 | evaluation: 46 | dataloader: 47 | batch_size_per_gpu: 64 48 | metrics: 49 | - type: ner-metric 50 | - type: ner-dumper 51 | model_type: sequence_labeling 52 | dump_format: conll 53 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/maoe_example.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: weibo_maoe 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | labels: 15 | type: count_span_labels 16 | 17 | preprocessor: 18 | type: sequence-labeling-preprocessor 19 | model_dir: bert-base-chinese 20 | max_length: 160 21 | 22 | data_collator: SequenceLabelingDataCollatorWithPadding 23 | 24 | model: 25 | type: sequence-labeling-model 26 | embedder: 27 | model_name_or_path: damo/nlp_maoe_named-entity-recognition_general 28 | #model_name_or_path: bert-base-chinese 29 | dropout: 0.1 30 | use_crf: true 31 | 32 | train: 33 | max_epochs: 20 34 | dataloader: 35 | batch_size_per_gpu: 16 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-5 39 | param_groups: 40 | - regex: crf 41 | lr: 5.0e-1 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 20 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 128 51 | metrics: 52 | - type: ner-metric 53 | - type: ner-dumper 54 | model_type: sequence_labeling 55 | dump_format: conll 56 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/msra.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: msra 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: https://www.modelscope.cn/api/v1/datasets/damo/msra_ner/repo/files?Revision=master&FilePath=train.txt 11 | test: https://www.modelscope.cn/api/v1/datasets/damo/msra_ner/repo/files?Revision=master&FilePath=test.txt 12 | data_type: conll 13 | 14 | preprocessor: 15 | type: sequence-labeling-preprocessor 16 | max_length: 150 17 | 18 | data_collator: SequenceLabelingDataCollatorWithPadding 19 | 20 | model: 21 | type: sequence-labeling-model 22 | embedder: 23 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 24 | dropout: 0.1 25 | use_crf: true 26 | 27 | train: 28 | max_epochs: 20 29 | dataloader: 30 | batch_size_per_gpu: 32 31 | optimizer: 32 | type: AdamW 33 | lr: 5.0e-5 34 | param_groups: 35 | - regex: crf 36 | lr: 5.0e-1 37 | lr_scheduler: 38 | type: LinearLR 39 | start_factor: 1.0 40 | end_factor: 0.0 41 | total_iters: 20 42 | 43 | evaluation: 44 | dataloader: 45 | batch_size_per_gpu: 128 46 | metrics: 47 | - type: ner-metric 48 | - type: ner-dumper 49 | model_type: sequence_labeling 50 | dump_format: conll 51 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/pku_cws.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: pku 4 | seed: 42 5 | 6 | task: word-segmentation 7 | 8 | dataset: 9 | data_file: 10 | train: https://modelscope.cn/api/v1/datasets/dingkun/chinese_word_segmentation_pku/repo?Revision=master&FilePath=train.txt 11 | dev: https://modelscope.cn/api/v1/datasets/dingkun/chinese_word_segmentation_pku/repo?Revision=master&FilePath=dev.txt 12 | test: https://modelscope.cn/api/v1/datasets/dingkun/chinese_word_segmentation_pku/repo?Revision=master&FilePath=test.txt 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | max_length: 256 18 | tag_scheme: BIES 19 | 20 | data_collator: SequenceLabelingDataCollatorWithPadding 21 | 22 | model: 23 | type: sequence-labeling-model 24 | embedder: 25 | model_name_or_path: damo/nlp_structbert_word-segmentation_chinese-base 26 | dropout: 0.1 27 | use_crf: true 28 | 29 | train: 30 | max_epochs: 30 31 | dataloader: 32 | batch_size_per_gpu: 32 33 | optimizer: 34 | type: AdamW 35 | lr: 2.0e-5 36 | param_groups: 37 | - regex: crf 38 | lr: 2.0e-1 39 | lr_scheduler: 40 | type: LinearLR 41 | start_factor: 1.0 42 | end_factor: 0.0 43 | total_iters: 30 44 | 45 | evaluation: 46 | dataloader: 47 | batch_size_per_gpu: 64 48 | metrics: 49 | - type: ner-metric 50 | - type: ner-dumper 51 | model_type: sequence_labeling 52 | dump_format: conll 53 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/resume.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: resume 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | max_length: 150 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 25 | dropout: 0.1 26 | use_crf: true 27 | 28 | train: 29 | max_epochs: 20 30 | dataloader: 31 | batch_size_per_gpu: 16 32 | optimizer: 33 | type: AdamW 34 | lr: 5.0e-5 35 | param_groups: 36 | - regex: crf 37 | lr: 5.0e-1 38 | lr_scheduler: 39 | type: LinearLR 40 | start_factor: 1.0 41 | end_factor: 0.0 42 | total_iters: 20 43 | 44 | evaluation: 45 | dataloader: 46 | batch_size_per_gpu: 128 47 | metrics: 48 | - type: ner-metric 49 | - type: ner-dumper 50 | model_type: sequence_labeling 51 | dump_format: conll 52 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/weibo.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: weibo 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | labels: 15 | type: count_span_labels 16 | 17 | preprocessor: 18 | type: sequence-labeling-preprocessor 19 | max_length: 160 20 | 21 | data_collator: SequenceLabelingDataCollatorWithPadding 22 | 23 | model: 24 | type: sequence-labeling-model 25 | embedder: 26 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 27 | dropout: 0.1 28 | use_crf: true 29 | 30 | train: 31 | max_epochs: 20 32 | dataloader: 33 | batch_size_per_gpu: 16 34 | optimizer: 35 | type: AdamW 36 | lr: 5.0e-5 37 | param_groups: 38 | - regex: crf 39 | lr: 5.0e-1 40 | lr_scheduler: 41 | type: LinearLR 42 | start_factor: 1.0 43 | end_factor: 0.0 44 | total_iters: 20 45 | 46 | evaluation: 47 | dataloader: 48 | batch_size_per_gpu: 128 49 | metrics: 50 | - type: ner-metric 51 | - type: ner-dumper 52 | model_type: sequence_labeling 53 | dump_format: conll 54 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/wnut16.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: wnut16 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut16_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut16_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut16_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | max_length: 100 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | 28 | train: 29 | max_epochs: 20 30 | dataloader: 31 | batch_size_per_gpu: 16 32 | optimizer: 33 | type: AdamW 34 | lr: 5.0e-6 35 | param_groups: 36 | - regex: crf 37 | lr: 5.0e-2 38 | lr_scheduler: 39 | type: LinearLR 40 | start_factor: 1.0 41 | end_factor: 0.0 42 | total_iters: 20 43 | 44 | evaluation: 45 | dataloader: 46 | batch_size_per_gpu: 128 47 | metrics: 48 | - type: ner-metric 49 | - type: ner-dumper 50 | model_type: sequence_labeling 51 | dump_format: conll 52 | -------------------------------------------------------------------------------- /examples/bert_crf/configs/wnut17.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: wnut17 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut17_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut17_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/wnut17_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | 15 | preprocessor: 16 | type: sequence-labeling-preprocessor 17 | max_length: 100 18 | 19 | data_collator: SequenceLabelingDataCollatorWithPadding 20 | 21 | model: 22 | type: sequence-labeling-model 23 | embedder: 24 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 25 | dropout: 0.1 26 | use_crf: true 27 | 28 | train: 29 | max_epochs: 20 30 | dataloader: 31 | batch_size_per_gpu: 16 32 | optimizer: 33 | type: AdamW 34 | lr: 5.0e-6 35 | param_groups: 36 | - regex: crf 37 | lr: 5.0e-2 38 | lr_scheduler: 39 | type: LinearLR 40 | start_factor: 1.0 41 | end_factor: 0.0 42 | total_iters: 20 43 | 44 | evaluation: 45 | dataloader: 46 | batch_size_per_gpu: 128 47 | metrics: 48 | - type: ner-metric 49 | - type: ner-dumper 50 | model_type: sequence_labeling 51 | dump_format: conll 52 | -------------------------------------------------------------------------------- /examples/biaffine_ner/configs/conll03.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: conll03 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: https://data.deepai.org/conll2003.zip 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: span-extraction-preprocessor 14 | max_length: 200 15 | 16 | data_collator: SpanExtractionDataCollatorWithPadding 17 | 18 | model: 19 | type: biaffine-ner-model 20 | embedder: 21 | model_name_or_path: damo/nlp_raner_named-entity-recognition_multilingual-large-generic 22 | biaffine_ffnn_size: 150 23 | flat_ner: true 24 | dropout: 0.2 25 | 26 | train: 27 | max_epochs: 20 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 1.0e-3 33 | eps: 1.0e-08 34 | weight_decay: 0.01 35 | param_groups: 36 | - regex: ".*transformer_model((?!(bias|LayerNorm)).)*$" 37 | lr: 1.0e-5 38 | - regex: ".*transformer_model.*(bias|LayerNorm)" 39 | lr: 1.0e-05 40 | weight_decay": 0 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 64 45 | metrics: span-extraction-metric 46 | -------------------------------------------------------------------------------- /examples/biaffine_ner/configs/resume.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: resume 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | delimiter: ' ' 15 | labels: 16 | type: count_span_labels 17 | 18 | preprocessor: 19 | type: span-extraction-preprocessor 20 | max_length: 200 21 | 22 | data_collator: SpanExtractionDataCollatorWithPadding 23 | 24 | model: 25 | type: biaffine-ner-model 26 | embedder: 27 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 28 | biaffine_ffnn_size: 150 29 | flat_ner: true 30 | dropout: 0.1 31 | 32 | train: 33 | max_epochs: 20 34 | dataloader: 35 | batch_size_per_gpu: 32 36 | optimizer: 37 | type: AdamW 38 | lr: 1.0e-3 39 | param_groups: 40 | - regex: transformer_model 41 | lr: 2.0e-5 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 20 47 | 48 | evaluation: 49 | dataloader: 50 | batch_size_per_gpu: 64 51 | metrics: 52 | - type: span-extraction-metric 53 | - type: ner-dumper 54 | model_type: span_based 55 | dump_format: jsonline 56 | -------------------------------------------------------------------------------- /examples/entity_typing/README.md: -------------------------------------------------------------------------------- 1 | # Entity Typing 2 | 3 | ## Training a new model 4 | ``` 5 | python -m scripts.train -c examples/entity_typing/configs/cfet_span.yaml 6 | ``` 7 | 8 | ## Benchmarks 9 | TODO 10 | -------------------------------------------------------------------------------- /examples/entity_typing/configs/cfet_span.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: cfet 4 | seed: 42 5 | 6 | task: entity-typing 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=train.json' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=dev.json' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/izhx404/cfet/repo/files?Revision=master&FilePath=test.json' 13 | tokenizer: char 14 | labels: 15 | type: count_span_labels 16 | 17 | preprocessor: 18 | type: multilabel-span-typing-preprocessor 19 | model_dir: sijunhe/nezha-cn-base 20 | max_length: 500 21 | 22 | data_collator: MultiLabelSpanTypingDataCollatorWithPadding 23 | 24 | model: 25 | type: multilabel-span-typing-model 26 | embedder: 27 | model_name_or_path: sijunhe/nezha-cn-base 28 | dropout: 0.1 29 | 30 | train: 31 | max_epochs: 50 32 | dataloader: 33 | batch_size_per_gpu: 16 34 | optimizer: 35 | type: AdamW 36 | lr: 5.0e-5 37 | lr_scheduler: 38 | type: LinearLR 39 | start_factor: 1.0 40 | end_factor: 0.0 41 | total_iters: 50 42 | 43 | evaluation: 44 | dataloader: 45 | batch_size_per_gpu: 32 46 | metrics: typing-metric 47 | -------------------------------------------------------------------------------- /examples/global_pointer/README.md: -------------------------------------------------------------------------------- 1 | # Global Pointer 2 | This example introduces how to train a Global Pointer ([Su et al., 2022](https://arxiv.org/abs/2208.03054)) model for sequence labeling tasks. 3 | 4 | --- 5 | 6 | ## Training a new model 7 | ``` 8 | python -m scripts.train -c examples/global_pointer/configs/resume.yaml 9 | ``` 10 | 11 | ## Benchmarks 12 | TODO 13 | 14 | ## Citation 15 | ``` 16 | @article{Su2022GlobalPN, 17 | title={Global Pointer: Novel Efficient Span-based Approach for Named Entity Recognition}, 18 | author={Jianlin Su and Ahmed Murtadha and Shengfeng Pan and Jing Hou and Jun Sun and Wanwei Huang and Bo Wen and Yunfeng Liu}, 19 | journal={ArXiv}, 20 | year={2022}, 21 | volume={abs/2208.03054} 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /examples/global_pointer/configs/resume.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: resume 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/resume_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | delimiter: ' ' 15 | labels: 16 | type: count_span_labels 17 | 18 | preprocessor: 19 | type: span-extraction-preprocessor 20 | max_length: 200 21 | 22 | data_collator: SpanExtractionDataCollatorWithPadding 23 | 24 | model: 25 | type: global-pointer-model 26 | embedder: 27 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 28 | token_ffn_out_width: 64 29 | word_dropout: 0.1 30 | 31 | train: 32 | max_epochs: 10 33 | dataloader: 34 | batch_size_per_gpu: 32 35 | optimizer: 36 | type: AdamW 37 | lr: 5.0e-5 38 | lr_scheduler: 39 | type: LinearLR 40 | start_factor: 1.0 41 | end_factor: 0.0 42 | total_iters: 20 43 | 44 | evaluation: 45 | dataloader: 46 | batch_size_per_gpu: 64 47 | metrics: span-extraction-metric 48 | -------------------------------------------------------------------------------- /examples/partial_bert_crf/README.md: -------------------------------------------------------------------------------- 1 | # Partial Bert-CRF 2 | In many scenarios, named entity recognition (NER) models severely suffer from unlabeled entity problem, where the entities of a sentence may not be fully annotated. Partial CRF is a parameter estimation method for Conditional Random Fields (CRFs), which enables us to use such incomplete annotations [(Tsuboi et al.)](https://aclanthology.org/C08-1113/). 3 | 4 | ## data preprocessing 5 | Partially annotated entity/span should be marked as B-P. 6 | You can process the trainset and set the path to `dataset: data_files: train` of `configs/msra.yml`. 7 | 8 | ## Training a new model 9 | ``` 10 | python -m scripts.train -c examples/partial_bert_crf/configs/resume.yaml 11 | ``` 12 | 13 | ## Benchmarks 14 | TODO 15 | -------------------------------------------------------------------------------- /examples/partial_bert_crf/configs/msra.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: msra 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra_partial.zip' 10 | data_type: conll 11 | 12 | preprocessor: 13 | type: sequence-labeling-preprocessor 14 | max_length: 150 15 | 16 | data_collator: SequenceLabelingDataCollatorWithPadding 17 | 18 | model: 19 | type: sequence-labeling-model 20 | embedder: 21 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 22 | dropout: 0.1 23 | use_crf: true 24 | partial: true 25 | 26 | train: 27 | max_epochs: 20 28 | dataloader: 29 | batch_size_per_gpu: 32 30 | optimizer: 31 | type: AdamW 32 | lr: 5.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-1 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 20 41 | 42 | evaluation: 43 | dataloader: 44 | batch_size_per_gpu: 128 45 | metrics: 46 | - type: ner-metric 47 | - type: ner-dumper 48 | model_type: sequence_labeling 49 | dump_format: conll 50 | -------------------------------------------------------------------------------- /examples/twostage_ner/configs/weibo.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/twostage_ner 3 | exp_name: weibo 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | data_file: 10 | train: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=train.txt' 11 | valid: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=dev.txt' 12 | test: 'https://www.modelscope.cn/api/v1/datasets/damo/weibo_ner/repo/files?Revision=master&FilePath=test.txt' 13 | data_type: conll 14 | labels: 15 | type: count_span_labels 16 | 17 | preprocessor: 18 | type: twostage-preprocessor 19 | model_dir: bert-base-chinese 20 | max_length: 512 21 | 22 | data_collator: TwostageDataCollatorWithPadding 23 | 24 | model: 25 | type: twostage-ner-model 26 | embedder: 27 | model_name_or_path: bert-base-chinese 28 | #transformer_kwargs: 29 | # revision: v0.0.1 30 | word_dropout: 0.1 31 | 32 | train: 33 | max_epochs: 50 34 | dataloader: 35 | batch_size_per_gpu: 32 36 | optimizer: 37 | type: AdamW 38 | lr: 5.0e-5 39 | param_groups: 40 | - regex: crf 41 | lr: 1.0e-3 42 | lr_scheduler: 43 | type: LinearLR 44 | start_factor: 1.0 45 | end_factor: 0.0 46 | total_iters: 50 47 | options: 48 | by_epoch: False 49 | warmup: 50 | type: LinearWarmup 51 | warmup_iters: 5 52 | 53 | evaluation: 54 | dataloader: 55 | batch_size_per_gpu: 16 56 | metrics: 57 | - type: span-extraction-metric 58 | - type: ner-dumper 59 | model_type: span_based 60 | dump_format: jsonline 61 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 100 3 | include = '\.pyi?$' 4 | extend-exclude = ''' 5 | ( 6 | \docs 7 | | \tests 8 | ) 9 | ''' 10 | skip-string-normalization = true # Avoid black replace all single quotes to the double 11 | 12 | [tool.isort] 13 | profile = "black" 14 | src_paths = ["adaseq", "scripts", "tests"] 15 | skip_gitignore = true 16 | known_first_party = ["adaseq"] 17 | 18 | [build-system] 19 | requires = ["setuptools", "wheel"] 20 | build-backend = "setuptools.build_meta" 21 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | addict 2 | datasets 3 | modelscope>=1.4.0 4 | seqeval 5 | torch>=1.11.0 6 | tqdm>=4.64.0 7 | transformers>=4.21.0 8 | urllib3>=1.26.0 9 | -------------------------------------------------------------------------------- /scripts/pretrain.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import argparse 3 | import os 4 | import sys 5 | import warnings 6 | 7 | parent_folder = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 8 | sys.path.append(parent_folder) 9 | 10 | from adaseq.commands.pretrain import pretrain_model # noqa # isort:skip 11 | 12 | warnings.filterwarnings('ignore') 13 | 14 | 15 | def main(args): 16 | """train a model from args""" 17 | pretrain_model( 18 | config_path_or_dict=args.config_path, 19 | work_dir=args.work_dir, 20 | run_name=args.run_name, 21 | seed=args.seed, 22 | force=args.force, 23 | device=args.device, 24 | local_rank=args.local_rank, 25 | checkpoint_path=args.checkpoint_path, 26 | ) 27 | 28 | 29 | if __name__ == '__main__': 30 | parser = argparse.ArgumentParser('train.py') 31 | parser.add_argument( 32 | '-c', '--config_path', required=True, type=str, help='configuration YAML file' 33 | ) 34 | parser.add_argument( 35 | '-w', 36 | '--work_dir', 37 | type=str, 38 | default=None, 39 | help='directory to save experiment logs and checkpoints', 40 | ) 41 | parser.add_argument('-n', '--run_name', type=str, default=None, help='trial name') 42 | parser.add_argument('-d', '--device', type=str, default='gpu', help='device name') 43 | parser.add_argument( 44 | '-f', '--force', default=None, help='overwrite the output directory if it exists.' 45 | ) 46 | parser.add_argument('-ckpt', '--checkpoint_path', default=None, help='model checkpoint') 47 | parser.add_argument('--seed', type=int, default=None, help='random seed for everything') 48 | parser.add_argument('--local_rank', type=str, default='0') 49 | 50 | args = parser.parse_args() 51 | main(args) 52 | -------------------------------------------------------------------------------- /scripts/test.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import argparse 3 | import os 4 | import sys 5 | import warnings 6 | 7 | parent_folder = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 8 | sys.path.append(parent_folder) 9 | 10 | from adaseq.commands.test import test_model # noqa: E402 isort:skip 11 | 12 | warnings.filterwarnings('ignore') 13 | 14 | 15 | def main(args): 16 | """test a model from args""" 17 | test_model(args.work_dir, args.device, args.checkpoint_path) 18 | 19 | 20 | if __name__ == '__main__': 21 | parser = argparse.ArgumentParser('test with a model checkpoint') 22 | parser.add_argument( 23 | '-w', '--work_dir', required=True, help='directory to load config and checkpoint' 24 | ) 25 | parser.add_argument('-d', '--device', default='gpu', help='device name') 26 | parser.add_argument('-ckpt', '--checkpoint_path', default=None, help='model checkpoint') 27 | args = parser.parse_args() 28 | main(args) 29 | -------------------------------------------------------------------------------- /scripts/train.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alibaba, Inc. and its affiliates. 2 | import argparse 3 | import os 4 | import sys 5 | import warnings 6 | 7 | parent_folder = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 8 | sys.path.append(parent_folder) 9 | 10 | from adaseq.commands.train import train_model_from_args, train_model # noqa # isort:skip 11 | 12 | warnings.filterwarnings('ignore') 13 | 14 | 15 | if __name__ == '__main__': 16 | parser = argparse.ArgumentParser('train.py') 17 | parser.add_argument( 18 | '-c', '--config_path', type=str, required=True, help='configuration YAML file' 19 | ) 20 | parser.add_argument( 21 | '-w', 22 | '--work_dir', 23 | type=str, 24 | default=None, 25 | help='directory to save experiment logs and checkpoints', 26 | ) 27 | parser.add_argument('-n', '--run_name', type=str, default=None, help='trial name') 28 | parser.add_argument( 29 | '-f', '--force', default=None, help='overwrite the output directory if it exists.' 30 | ) 31 | parser.add_argument('-ckpt', '--checkpoint_path', default=None, help='model checkpoint to load') 32 | parser.add_argument('--seed', type=int, default=None, help='random seed for everything') 33 | parser.add_argument('-d', '--device', type=str, default='gpu', help='device name') 34 | parser.add_argument('--use_fp16', action='store_true', help='whether to use mixed precision') 35 | parser.add_argument('--local_rank', type=str, default='0') 36 | 37 | args = parser.parse_args() 38 | train_model_from_args(args) 39 | -------------------------------------------------------------------------------- /tests/citest.sh: -------------------------------------------------------------------------------- 1 | /home/admin/python37/bin/pip3 install -r ./requirements.txt -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html 2 | 3 | echo $PWD 4 | 5 | pre-commit run -c .pre-commit-config_local.yaml --all-files 6 | if [ $? -ne 0 ]; then 7 | echo "linter test failed, please run 'pre-commit run --all-files' to check" 8 | exit -1 9 | fi 10 | 11 | PYTHONPATH=. /home/admin/python37/bin/python3 tests/run_tests.py 12 | -------------------------------------------------------------------------------- /tests/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/models/__init__.py -------------------------------------------------------------------------------- /tests/models/test_base_model.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path as osp 3 | import shutil 4 | import tempfile 5 | import unittest 6 | 7 | import torch 8 | from modelscope.utils.constant import ModelFile 9 | 10 | from adaseq.metainfo import Models, Tasks 11 | from adaseq.models.base import Model 12 | 13 | 14 | class TestBaseModel(unittest.TestCase): 15 | def setUp(self): 16 | print(('Testing %s.%s' % (type(self).__name__, self._testMethodName))) 17 | self.tmp_dir = tempfile.TemporaryDirectory().name 18 | if not osp.exists(self.tmp_dir): 19 | os.makedirs(self.tmp_dir) 20 | 21 | def tearDown(self): 22 | shutil.rmtree(self.tmp_dir) 23 | super().tearDown() 24 | 25 | def test_save_pretrained(self): 26 | model = Model.from_config( 27 | type=Models.sequence_labeling_model, 28 | task=Tasks.named_entity_recognition, 29 | id_to_label={0: 'O', 1: 'B', 2: 'I'}, 30 | embedder={'model_name_or_path': 'damo/nlp_structbert_backbone_base_std'}, 31 | ) 32 | 33 | model.save_pretrained(self.tmp_dir) 34 | 35 | # pytorch_model.bin 36 | model_file = osp.join(self.tmp_dir, ModelFile.TORCH_MODEL_BIN_FILE) 37 | self.assertTrue(osp.isfile(model_file)) 38 | self.assertIn( 39 | 'embedder.transformer_model.embeddings.word_embeddings.weight', torch.load(model_file) 40 | ) 41 | 42 | # configuration.json 43 | configuration_file = osp.join(self.tmp_dir, ModelFile.CONFIGURATION) 44 | self.assertTrue(osp.isfile(configuration_file)) 45 | 46 | # config.json 47 | config_file = osp.join(self.tmp_dir, 'config.json') 48 | self.assertTrue(osp.isfile(config_file)) 49 | 50 | 51 | if __name__ == '__main__': 52 | unittest.main() 53 | -------------------------------------------------------------------------------- /tests/models/test_bert_crf.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from adaseq.exporters.sequence_labeling_model_exporter import ( 8 | SequenceLabelingModelExporter, 9 | ) 10 | from tests.models.base import TestModel, compare_fn 11 | 12 | 13 | class TestBertCRF(TestModel): 14 | def setUp(self): 15 | super().setUp() 16 | cfg_file = osp.join('tests', 'resources', 'configs', 'train_bert_crf.yaml') 17 | self.config = Config.from_file(cfg_file) 18 | 19 | def test_train_bert_crf(self): 20 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir, seed=42) 21 | 22 | with self.regress_tool.monitor_ms_train( 23 | trainer, 24 | 'ut_bert_crf', 25 | level='strict', 26 | compare_fn=compare_fn, 27 | # Ignore the calculation gap of cpu & gpu 28 | atol=1e-3, 29 | ): 30 | trainer.train() 31 | 32 | def test_export_bert_crf(self): 33 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir) 34 | model = trainer.model 35 | preprocessor = trainer.eval_preprocessor 36 | exporter = SequenceLabelingModelExporter(model=model, preprocessor=preprocessor) 37 | with self.subTest(format='onnx'): 38 | print(exporter.export_onnx(output_dir=self.tmp_dir)) 39 | with self.subTest(format='torchscript'): 40 | print(exporter.export_torch_script(output_dir=self.tmp_dir, strict=False)) 41 | 42 | 43 | if __name__ == '__main__': 44 | unittest.main() 45 | -------------------------------------------------------------------------------- /tests/models/test_biaffine_ner.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | 9 | 10 | class TestBiaffineNer(TestModel): 11 | def setUp(self): 12 | super().setUp() 13 | cfg_file = osp.join('tests', 'resources', 'configs', 'train_biaffine_ner.yaml') 14 | self.config = Config.from_file(cfg_file) 15 | 16 | def test_biaffine_ner(self): 17 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir, seed=42) 18 | 19 | with self.regress_tool.monitor_ms_train( 20 | trainer, 21 | 'ut_biaffine_ner', 22 | level='strict', 23 | compare_fn=compare_fn, 24 | # Ignore the calculation gap of cpu & gpu 25 | atol=1e-3, 26 | ): 27 | trainer.train() 28 | 29 | 30 | if __name__ == '__main__': 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /tests/models/test_global_pointer.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | 9 | 10 | class TestGlobalPointer(TestModel): 11 | def setUp(self): 12 | super().setUp() 13 | cfg_file = osp.join('tests', 'resources', 'configs', 'train_global_pointer.yaml') 14 | self.config = Config.from_file(cfg_file) 15 | 16 | def test_global_pointer(self): 17 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir, seed=42) 18 | 19 | with self.regress_tool.monitor_ms_train( 20 | trainer, 21 | 'ut_global_pointer', 22 | level='strict', 23 | compare_fn=compare_fn, 24 | # Ignore the calculation gap of cpu & gpu 25 | atol=1e-3, 26 | ): 27 | trainer.train() 28 | 29 | 30 | if __name__ == '__main__': 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /tests/models/test_lstm_crf.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | from tests.utils import is_huggingface_available 9 | 10 | 11 | class TestLSTMCRF(TestModel): 12 | def setUp(self): 13 | super().setUp() 14 | cfg_file = osp.join('tests', 'resources', 'configs', 'train_lstm_crf.yaml') 15 | self.config = Config.from_file(cfg_file) 16 | 17 | @unittest.skipUnless(is_huggingface_available(), 'Cannot connect to huggingface!') 18 | def test_lstm_crf(self): 19 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir, seed=42) 20 | 21 | with self.regress_tool.monitor_ms_train( 22 | trainer, 23 | 'ut_lstm_crf', 24 | level='strict', 25 | compare_fn=compare_fn, 26 | # Ignore the calculation gap of cpu & gpu 27 | atol=1e-3, 28 | ): 29 | trainer.train() 30 | 31 | 32 | if __name__ == '__main__': 33 | unittest.main() 34 | -------------------------------------------------------------------------------- /tests/models/test_multilabel_entity_typing.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | 9 | 10 | class TestGlobalPointer(TestModel): 11 | def setUp(self): 12 | super().setUp() 13 | config_dir = osp.join('tests', 'resources', 'configs') 14 | self.config_span = Config.from_file(osp.join(config_dir, 'train_entity_typing_span.yaml')) 15 | self.config_concat = Config.from_file( 16 | osp.join(config_dir, 'train_entity_typing_concat.yaml') 17 | ) 18 | 19 | def test_global_pointer(self): 20 | trainer = build_trainer_from_partial_objects( 21 | self.config_span, work_dir=self.tmp_dir, seed=42 22 | ) 23 | with self.regress_tool.monitor_ms_train( 24 | trainer, 25 | 'ut_entity_typing', 26 | level='strict', 27 | compare_fn=compare_fn, 28 | # Ignore the calculation gap of cpu & gpu 29 | atol=1e-3, 30 | ): 31 | trainer.train() 32 | 33 | def test_concat_typing(self): 34 | trainer = build_trainer_from_partial_objects( 35 | self.config_concat, work_dir=self.tmp_dir, seed=42 36 | ) 37 | self.is_baseline = True 38 | with self.regress_tool.monitor_ms_train( 39 | trainer, 40 | 'ut_concat_entity_typing', 41 | level='strict', 42 | compare_fn=compare_fn, 43 | # Ignore the calculation gap of cpu & gpu 44 | atol=1e-3, 45 | ): 46 | trainer.train() 47 | 48 | 49 | if __name__ == '__main__': 50 | unittest.main() 51 | -------------------------------------------------------------------------------- /tests/models/test_partial_bert_crf.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | 9 | """ 10 | class TestPartialBertCRF(TestModel): 11 | def setUp(self): 12 | super().setUp() 13 | cfg_file = osp.join('tests', 'resources', 'configs', 'train_partial_bert_crf.yaml') 14 | self.config = Config.from_file(cfg_file) 15 | 16 | def test_partial_bert_crf(self): 17 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir, seed=42) 18 | 19 | with self.regress_tool.monitor_ms_train( 20 | trainer, 21 | 'ut_partial_bert_crf', 22 | level='strict', 23 | compare_fn=compare_fn, 24 | # Ignore the calculation gap of cpu & gpu 25 | atol=1e-3, 26 | ): 27 | trainer.train() 28 | """ 29 | 30 | if __name__ == '__main__': 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /tests/models/test_twostage_ner.py: -------------------------------------------------------------------------------- 1 | import os.path as osp 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | 9 | 10 | class TestTwoStageNER(TestModel): 11 | def setUp(self): 12 | super().setUp() 13 | cfg_file = osp.join('tests', 'resources', 'configs', 'train_twostage_ner.yaml') 14 | self.config = Config.from_file(cfg_file) 15 | 16 | def test_two_stage_ner(self): 17 | trainer = build_trainer_from_partial_objects(self.config, work_dir=self.tmp_dir, seed=42) 18 | with self.regress_tool.monitor_ms_train( 19 | trainer, 20 | 'ut_two_stage_ner', 21 | level='strict', 22 | compare_fn=compare_fn, 23 | # Ignore the calculation gap of cpu & gpu 24 | atol=1e-3, 25 | ): 26 | trainer.train() 27 | 28 | 29 | if __name__ == '__main__': 30 | unittest.main() 31 | -------------------------------------------------------------------------------- /tests/models/test_w2ner.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | 4 | from modelscope.utils.config import Config 5 | 6 | from adaseq.commands.train import build_trainer_from_partial_objects 7 | from tests.models.base import TestModel, compare_fn 8 | 9 | 10 | class TestW2Ner(TestModel): 11 | def test_w2ner(self): 12 | cfg_file = os.path.join('tests', 'resources', 'configs', 'train_w2ner.yaml') 13 | config = Config.from_file(cfg_file) 14 | trainer = build_trainer_from_partial_objects(config, work_dir=config.work_dir, seed=42) 15 | 16 | with self.regress_tool.monitor_ms_train( 17 | trainer, 18 | 'ut_w2ner', 19 | level='strict', 20 | compare_fn=lambda v1, v2, k, t: True, # skip fw&bw comparison as this model is unstable 21 | # Ignore the calculation gap of cpu & gpu 22 | atol=1e-3, 23 | ): 24 | trainer.train() 25 | 26 | os.remove(config.work_dir + '/config.yaml') 27 | 28 | 29 | if __name__ == '__main__': 30 | unittest.main() 31 | -------------------------------------------------------------------------------- /tests/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/modules/__init__.py -------------------------------------------------------------------------------- /tests/resources/configs/bert.yaml: -------------------------------------------------------------------------------- 1 | task: named-entity-recognition 2 | model: 3 | type: sequence-labeling-model 4 | id_to_label: 5 | 0: O 6 | 1: B 7 | embedder: 8 | model_name_or_path: bert-base-cased 9 | -------------------------------------------------------------------------------- /tests/resources/configs/demo.yaml: -------------------------------------------------------------------------------- 1 | experiment: 2 | exp_dir: experiments/ 3 | exp_name: toy_msra 4 | seed: 42 5 | 6 | task: named-entity-recognition 7 | 8 | dataset: 9 | name: damo/toy_msra 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | max_length: 100 14 | 15 | data_collator: SequenceLabelingDataCollatorWithPadding 16 | 17 | model: 18 | type: sequence-labeling-model 19 | embedder: 20 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-news 21 | dropout: 0.1 22 | use_crf: true 23 | 24 | train: 25 | max_epochs: 5 26 | dataloader: 27 | batch_size_per_gpu: 8 28 | optimizer: 29 | type: AdamW 30 | lr: 5.0e-5 31 | param_groups: 32 | - regex: crf 33 | lr: 5.0e-1 34 | options: 35 | cumulative_iters: 4 36 | 37 | evaluation: 38 | dataloader: 39 | batch_size_per_gpu: 16 40 | metrics: 41 | - type: ner-metric 42 | -------------------------------------------------------------------------------- /tests/resources/configs/finetune_bert_crf_from_trained_model.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | max_length: 150 14 | 15 | data_collator: SequenceLabelingDataCollatorWithPadding 16 | 17 | model: 18 | type: sequence-labeling-model 19 | embedder: 20 | model_name_or_path: damo/nlp_raner_named-entity-recognition_chinese-base-ecom 21 | dropout: 0.0 22 | use_crf: true 23 | 24 | train: 25 | max_epochs: 3 26 | dataloader: 27 | batch_size_per_gpu: 16 28 | optimizer: 29 | type: AdamW 30 | lr: 5.0e-5 31 | param_groups: 32 | - regex: crf 33 | lr: 5.0e-1 34 | lr_scheduler: 35 | type: LinearLR 36 | start_factor: 1.0 37 | end_factor: 0.0 38 | total_iters: 20 39 | 40 | evaluation: 41 | dataloader: 42 | batch_size_per_gpu: 128 43 | metrics: ner-metric 44 | -------------------------------------------------------------------------------- /tests/resources/configs/structbert.yaml: -------------------------------------------------------------------------------- 1 | task: named-entity-recognition 2 | model: 3 | type: sequence-labeling-model 4 | id_to_label: 5 | 0: O 6 | 1: B 7 | embedder: 8 | model_name_or_path: damo/nlp_structbert_backbone_base_std 9 | -------------------------------------------------------------------------------- /tests/resources/configs/train_bert_crf.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: SequenceLabelingDataCollatorWithPadding 17 | 18 | model: 19 | type: sequence-labeling-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | dropout: 0.0 23 | use_crf: true 24 | 25 | train: 26 | max_epochs: 1 27 | dataloader: 28 | batch_size_per_gpu: 16 29 | optimizer: 30 | type: AdamW 31 | lr: 5.0e-5 32 | param_groups: 33 | - regex: crf 34 | lr: 5.0e-1 35 | lr_scheduler: 36 | type: LinearLR 37 | start_factor: 1.0 38 | end_factor: 0.0 39 | total_iters: 20 40 | 41 | evaluation: 42 | dataloader: 43 | batch_size_per_gpu: 128 44 | metrics: ner-metric 45 | -------------------------------------------------------------------------------- /tests/resources/configs/train_biaffine_ner.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: span-extraction-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: SpanExtractionDataCollatorWithPadding 17 | 18 | model: 19 | type: biaffine-ner-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | biaffine_ffnn_size: 150 23 | flat_ner: true 24 | dropout: 0.0 25 | 26 | train: 27 | max_epochs: 1 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 1.0e-3 33 | param_groups: 34 | - regex: transformer_model 35 | lr: 2.0e-5 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 20 41 | 42 | evaluation: 43 | metrics: span-extraction-metric 44 | -------------------------------------------------------------------------------- /tests/resources/configs/train_entity_typing_concat.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: entity-typing 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_wiki.zip' 7 | tokenizer: char 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: multilabel-concat-typing-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: MultiLabelConcatTypingDataCollatorWithPadding 17 | 18 | model: 19 | type: multilabel-concat-typing-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | dropout: 0.0 23 | decoder: 24 | type: linear 25 | loss_function: WBCE 26 | pos_weight: 2 27 | 28 | train: 29 | max_epochs: 1 30 | dataloader: 31 | batch_size_per_gpu: 16 32 | optimizer: 33 | type: AdamW 34 | lr: 5.0e-5 35 | lr_scheduler: 36 | type: cosine 37 | warmup_rate: 0.1 # when choose concat typing model, default to use cosine_linear_with_warmup 38 | options: 39 | by_epoch: false 40 | 41 | evaluation: 42 | metrics: typing-metric 43 | -------------------------------------------------------------------------------- /tests/resources/configs/train_entity_typing_span.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: entity-typing 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_wiki.zip' 7 | tokenizer: char 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: multilabel-span-typing-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: MultiLabelSpanTypingDataCollatorWithPadding 17 | 18 | model: 19 | type: multilabel-span-typing-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | dropout: 0.0 23 | 24 | train: 25 | max_epochs: 1 26 | dataloader: 27 | batch_size_per_gpu: 16 28 | optimizer: 29 | type: AdamW 30 | lr: 5.0e-5 31 | lr_scheduler: 32 | type: LinearLR 33 | start_factor: 1.0 34 | end_factor: 0.0 35 | total_iters: 20 36 | 37 | evaluation: 38 | metrics: span-extraction-metric 39 | -------------------------------------------------------------------------------- /tests/resources/configs/train_global_pointer.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: span-extraction-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: SpanExtractionDataCollatorWithPadding 17 | 18 | model: 19 | type: global-pointer-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | token_ffn_out_width: 64 23 | dropout: 0.0 24 | 25 | train: 26 | max_epochs: 1 27 | dataloader: 28 | batch_size_per_gpu: 16 29 | optimizer: 30 | type: AdamW 31 | lr: 5.0e-5 32 | lr_scheduler: 33 | type: LinearLR 34 | start_factor: 1.0 35 | end_factor: 0.0 36 | total_iters: 20 37 | 38 | evaluation: 39 | metrics: span-extraction-metric 40 | -------------------------------------------------------------------------------- /tests/resources/configs/train_lstm_crf.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | max_length: 150 14 | 15 | data_collator: SequenceLabelingDataCollatorWithPadding 16 | 17 | model: 18 | type: sequence-labeling-model 19 | embedder: 20 | type: embedding 21 | model_name_or_path: pangda/word2vec-skip-gram-mixed-large-chinese 22 | encoder: 23 | type: lstm 24 | input_size: 300 25 | hidden_size: 100 26 | bidirectional: true 27 | dropout: 0.0 28 | use_crf: true 29 | 30 | train: 31 | max_epochs: 1 32 | dataloader: 33 | batch_size_per_gpu: 16 34 | optimizer: 35 | type: AdamW 36 | lr: 5.0e-5 37 | param_groups: 38 | - regex: crf 39 | lr: 5.0e-1 40 | lr_scheduler: 41 | type: LinearLR 42 | start_factor: 1.0 43 | end_factor: 0.0 44 | total_iters: 20 45 | 46 | evaluation: 47 | dataloader: 48 | batch_size_per_gpu: 128 49 | metrics: ner-metric 50 | -------------------------------------------------------------------------------- /tests/resources/configs/train_partial_bert_crf.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra_partial.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: sequence-labeling-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: SequenceLabelingDataCollatorWithPadding 17 | 18 | model: 19 | type: sequence-labeling-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | dropout: 0.0 23 | use_crf: true 24 | partial: true 25 | 26 | train: 27 | max_epochs: 1 28 | dataloader: 29 | batch_size_per_gpu: 16 30 | optimizer: 31 | type: AdamW 32 | lr: 5.0e-5 33 | param_groups: 34 | - regex: crf 35 | lr: 5.0e-1 36 | lr_scheduler: 37 | type: LinearLR 38 | start_factor: 1.0 39 | end_factor: 0.0 40 | total_iters: 20 41 | 42 | evaluation: 43 | metrics: ner-metric 44 | -------------------------------------------------------------------------------- /tests/resources/configs/train_twostage_ner.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | labels: 8 | type: count_span_labels 9 | data_type: conll 10 | 11 | preprocessor: 12 | type: twostage-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 512 15 | 16 | data_collator: TwostageDataCollatorWithPadding 17 | 18 | model: 19 | type: twostage-ner-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | word_dropout: 0.1 23 | 24 | train: 25 | max_epochs: 1 26 | dataloader: 27 | batch_size_per_gpu: 10 28 | optimizer: 29 | type: AdamW 30 | lr: 5.0e-5 31 | param_groups: 32 | - regex: crf 33 | lr: 1.0e-3 34 | lr_scheduler: 35 | type: LinearLR 36 | start_factor: 1.0 37 | end_factor: 0.0 38 | total_iters: 39 | 40 | evaluation: 41 | dataloader: 42 | batch_size_per_gpu: 16 43 | metrics: 44 | - type: span-extraction-metric 45 | - type: ner-dumper 46 | model_type: span_based 47 | dump_format: jsonline 48 | -------------------------------------------------------------------------------- /tests/resources/configs/train_w2ner.yaml: -------------------------------------------------------------------------------- 1 | work_dir: tests/resources/regression 2 | 3 | task: named-entity-recognition 4 | 5 | dataset: 6 | data_file: 'https://www.modelscope.cn/api/v1/datasets/izhx404/toy_msra/repo/files?Revision=master&FilePath=toy_msra.zip' 7 | data_type: conll 8 | labels: 9 | type: count_span_labels 10 | 11 | preprocessor: 12 | type: word-extraction-preprocessor 13 | model_dir: damo/nlp_structbert_backbone_base_std 14 | max_length: 150 15 | 16 | data_collator: WordExtractionDataCollatorWithPadding 17 | 18 | model: 19 | type: w2ner-model 20 | embedder: 21 | model_name_or_path: damo/nlp_structbert_backbone_base_std 22 | lstm_encoder: 23 | hidden_size: 384 24 | bidirectional: true 25 | cnn_encoder: 26 | channels: 96 27 | dropout: 0.0 28 | dilation: [1, 2, 3] 29 | emb_dropout: 0.0 30 | out_dropout: 0.0 31 | 32 | train: 33 | max_epochs: 1 34 | dataloader: 35 | batch_size_per_gpu: 4 36 | optimizer: 37 | type: AdamW 38 | lr: 1.0e-3 39 | param_groups: 40 | - regex: transformer_model 41 | lr: 1.0e-5 42 | options: 43 | grad_clip: 44 | max_norm: 1.0 45 | lr_scheduler: 46 | type: LinearLR 47 | start_factor: 1.0 48 | end_factor: 0.0 49 | total_iters: 20 50 | 51 | evaluation: 52 | dataloader: 53 | batch_size_per_gpu: 16 54 | metrics: span-extraction-metric 55 | -------------------------------------------------------------------------------- /tests/resources/datasets/toy_msra/toy_msra.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/datasets/toy_msra/toy_msra.zip -------------------------------------------------------------------------------- /tests/resources/regression/ut_bert_crf.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_bert_crf.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_biaffine_ner.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_biaffine_ner.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_concat_entity_typing.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_concat_entity_typing.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_entity_typing.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_entity_typing.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_global_pointer.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_global_pointer.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_lstm_crf.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_lstm_crf.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_partial_bert_crf.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_partial_bert_crf.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_two_stage_ner.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_two_stage_ner.bin -------------------------------------------------------------------------------- /tests/resources/regression/ut_w2ner.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/modelscope/AdaSeq/f7dbb926cce1038034bfbe27de101a03a8abd1f1/tests/resources/regression/ut_w2ner.bin -------------------------------------------------------------------------------- /tests/test_commands.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | import tempfile 4 | import unittest 5 | 6 | from adaseq.commands.train import train_model 7 | 8 | 9 | class TestCommands(unittest.TestCase): 10 | def setUp(self): 11 | print(('Testing %s.%s' % (type(self).__name__, self._testMethodName))) 12 | self.tmp_dir = tempfile.TemporaryDirectory().name 13 | if not os.path.exists(self.tmp_dir): 14 | os.makedirs(self.tmp_dir) 15 | self.cfg_file = os.path.join('tests', 'resources', 'configs', 'train_bert_crf.yaml') 16 | 17 | def tearDown(self): 18 | shutil.rmtree(self.tmp_dir) 19 | super().tearDown() 20 | 21 | def test_train_gpu(self): 22 | train_model(self.cfg_file, work_dir=self.tmp_dir, force=True, device='gpu') 23 | 24 | def test_train_cpu(self): 25 | train_model(self.cfg_file, work_dir=self.tmp_dir, force=True, device='cpu') 26 | 27 | 28 | if __name__ == '__main__': 29 | unittest.main() 30 | -------------------------------------------------------------------------------- /tests/utils.py: -------------------------------------------------------------------------------- 1 | from urllib import request 2 | 3 | 4 | def is_huggingface_available(): 5 | try: 6 | request.urlopen('https://huggingface.co/', timeout=5) 7 | return True 8 | except request.URLError as err: 9 | return False 10 | 11 | 12 | if __name__ == '__main__': 13 | print(is_huggingface_availble()) 14 | -------------------------------------------------------------------------------- /tools/gpu/README.md: -------------------------------------------------------------------------------- 1 | # queue.py 2 | A simple script to parallely run shell commands on multiple gpus. Commands will wait util there are free gpus. 3 | 4 | ### Quick Start 5 | ```commandline 6 | python tools/gpu/queue.py command_file 7 | ``` 8 | 9 | ### Usage 10 | ``` 11 | usage: queue.py [-h] [-g GPU] [-p MAX_GPU_POWER] [-m MAX_GPU_MEMORY] 12 | [-t TIME_INTERVAL] [-to LOG_FILE] 13 | commands 14 | 15 | positional arguments: 16 | commands a file in which each line contains a shell command. 17 | 18 | optional arguments: 19 | -h, --help show this help message and exit 20 | -g GPU, --gpu GPU gpu_ids, e.g. -g 0,1, default: all 21 | -p MAX_GPU_POWER, --max_gpu_power MAX_GPU_POWER 22 | maximum gpu power(W) before running command, default: 23 | 100 24 | -m MAX_GPU_MEMORY, --max_gpu_memory MAX_GPU_MEMORY 25 | maximum gpu memory(M) before running command, default: 26 | 1000 27 | -t TIME_INTERVAL, --time_interval TIME_INTERVAL 28 | sleep for seconds between commands, default: 300 29 | -to LOG_FILE, --log_file LOG_FILE 30 | redirect stdout to this log file, default: queue.log 31 | ``` 32 | 33 | ### Command File Example 34 | ```commandline 35 | adaseq train -c examples/SemEval2023_MultiCoNER_II/configs/orig/bn.yaml 36 | adaseq train -c examples/SemEval2023_MultiCoNER_II/configs/orig/en.yaml 37 | adaseq train -c examples/SemEval2023_MultiCoNER_II/configs/wiki128/bn.yaml 38 | adaseq train -c examples/SemEval2023_MultiCoNER_II/configs/wiki128/en.yaml 39 | ``` 40 | --------------------------------------------------------------------------------