{"id":18594451,"url":"https://github.com/applenob/delta_demo","last_synced_at":"2025-07-28T05:04:48.661Z","repository":{"id":78147849,"uuid":"217233770","full_name":"applenob/delta_demo","owner":"applenob","description":"A demo for delta-nlp usage","archived":false,"fork":false,"pushed_at":"2019-11-01T14:15:00.000Z","size":13452,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T05:37:32.175Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/applenob.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-24T07:04:11.000Z","updated_at":"2019-12-04T08:35:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"a101b702-6acd-4b4c-9130-847746162be8","html_url":"https://github.com/applenob/delta_demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/applenob/delta_demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applenob%2Fdelta_demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applenob%2Fdelta_demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applenob%2Fdelta_demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applenob%2Fdelta_demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/applenob","download_url":"https://codeload.github.com/applenob/delta_demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/applenob%2Fdelta_demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267464522,"owners_count":24091505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T01:15:36.056Z","updated_at":"2025-07-28T05:04:48.626Z","avatar_url":"https://github.com/applenob.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Text Classification Usage Example for pip users\n\n## Intro\n\nIn this tutorial, we demonstrate a text classification task with a\ndemo mock dataset **for users install by pip**.\n\nA complete process contains following steps:\n\n- Prepare the data set.\n- Develop custom modules (optional).\n- Set the config file.\n- Train a model.\n- Export a model\n\nPlease clone our demo repository:\n\n```bash\ngit clone --depth 1 https://github.com/applenob/delta_demo.git\ncd ./delta_demo\n```\n\n## A quick review for installation\n\nIf you haven't install `delta-nlp`, please:\n\n```bash\npip install delta-nlp\n```\n\n**Requirements**: You need `tensorflow==2.0.0` and `python==3.6` in\nMacOS or Linux.\n\n## Prepare the Data Set\n\nrun the script: \n\n```\n./gen_data.sh\n```\n\nThe generated data are in directory: `data`. \n\nThe generated data for text classification should be in the standard format for text classification, which is \"label\\tdocument\".\n\n## Develop custom modules (optional)\n\nPlease make sure we don't have modules you need before you decide to\ndevelop your own modules.\n\n```python\n@registers.model.register\nclass TestHierarchicalAttentionModel(HierarchicalModel):\n  \"\"\"Hierarchical text classification model with attention.\"\"\"\n\n  def __init__(self, config, **kwargs):\n    super().__init__(config, **kwargs)\n\n    logging.info(\"Initialize HierarchicalAttentionModel...\")\n\n    self.vocab_size = config['data']['vocab_size']\n    self.num_classes = config['data']['task']['classes']['num_classes']\n    self.use_true_length = config['model'].get('use_true_length', False)\n    if self.use_true_length:\n      self.split_token = config['data']['split_token']\n    self.padding_token = utils.PAD_IDX\n```\n\nYou need to register this module file path in the config file\n`config/han-cls.yml` (relative to the current work directory).\n\n```yml\ncustom_modules:\n  - \"test_model.py\"\n```\n\n## Set the Config File\n\nThe config file of this example is `config/han-cls.yml`\n\nIn the config file, we set the task to be `TextClsTask` and the model to be `TestHierarchicalAttentionModel`.\n\n### Config Details\n\nThe config is composed by 3 parts: `data`, `model`, `solver`.\n \nData related configs are under `data`. \nYou can set the data path (including training set, dev set and test set). \nThe data process configs can also be found here (mainly under `task`). \nFor example, we set `use_dense: false` since no dense input was used here. \nWe set `language: chinese` since it's a Chinese text. \n\nModel parameters are under `model`. The most important config here is\n`name: TestHierarchicalAttentionModel`, which specifies the model to\nuse. Detail structure configs are under `net-\u003estructure`. Here, the \n`max_sen_len` is 32 and `max_doc_len` is 32.\n\nThe configs under `solver` are used by solver class, including training optimizer, evaluation metrics and checkpoint saver. \nHere the class is `RawSolver`.\n\n## Train a Model\n\nAfter setting the config file, you are ready to train a model.\n\n```\ndelta --cmd train_and_eval --config config/han-cls.yml\n```\n\nThe argument `cmd` tells the platform to train a model and also evaluate\nthe dev set during the training process.\n\nAfter enough steps of training, you would find the model checkpoints have been saved to the directory set by `saver-\u003emodel_path`, which is `exp/han-cls/ckpt` in this case.\n\n## Export a Model\n\nIf you would like to export a specific checkpoint to be exported, please set `infer_model_path` in config file. Otherwise, platform will simply find the newest checkpoint under the directory set by `saver-\u003emodel_path`.\n\n```\ndelta --cmd export_model --config/han-cls.yml\n```\n\nThe exported models are in the directory set by config\n`service-\u003emodel_path`, which is `exp/han-cls/service` here.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplenob%2Fdelta_demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapplenob%2Fdelta_demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapplenob%2Fdelta_demo/lists"}