├── LICENSE ├── README.md ├── deepclassifier ├── __init__.py ├── layers │ ├── __init__.py │ └── lstm.py ├── models │ ├── __init__.py │ ├── bertdpcnn.py │ ├── berthan.py │ ├── bertrcnn.py │ ├── berttextcnn.py │ ├── dpcnn.py │ ├── han.py │ ├── rcnn.py │ └── textcnn.py └── trainers │ ├── __init__.py │ └── trainer.py ├── docs ├── Makefile ├── build │ ├── doctrees │ │ ├── environment.pickle │ │ └── index.doctree │ └── html │ │ ├── .buildinfo │ │ ├── _sources │ │ └── index.rst.txt │ │ ├── _static │ │ ├── alabaster.css │ │ ├── basic.css │ │ ├── css │ │ │ ├── badge_only.css │ │ │ ├── fonts │ │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ ├── fontawesome-webfont.woff2 │ │ │ │ ├── lato-bold-italic.woff │ │ │ │ ├── lato-bold-italic.woff2 │ │ │ │ ├── lato-bold.woff │ │ │ │ ├── lato-bold.woff2 │ │ │ │ ├── lato-normal-italic.woff │ │ │ │ ├── lato-normal-italic.woff2 │ │ │ │ ├── lato-normal.woff │ │ │ │ └── lato-normal.woff2 │ │ │ └── theme.css │ │ ├── custom.css │ │ ├── doctools.js │ │ ├── documentation_options.js │ │ ├── file.png │ │ ├── fonts │ │ │ ├── FontAwesome.otf │ │ │ ├── Lato │ │ │ │ ├── lato-bold.eot │ │ │ │ ├── lato-bold.ttf │ │ │ │ ├── lato-bold.woff │ │ │ │ ├── lato-bold.woff2 │ │ │ │ ├── lato-bolditalic.eot │ │ │ │ ├── lato-bolditalic.ttf │ │ │ │ ├── lato-bolditalic.woff │ │ │ │ ├── lato-bolditalic.woff2 │ │ │ │ ├── lato-italic.eot │ │ │ │ ├── lato-italic.ttf │ │ │ │ ├── lato-italic.woff │ │ │ │ ├── lato-italic.woff2 │ │ │ │ ├── lato-regular.eot │ │ │ │ ├── lato-regular.ttf │ │ │ │ ├── lato-regular.woff │ │ │ │ └── lato-regular.woff2 │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ ├── Roboto-Slab-Light.woff │ │ │ ├── Roboto-Slab-Light.woff2 │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ ├── Roboto-Slab-Thin.woff │ │ │ ├── Roboto-Slab-Thin.woff2 │ │ │ ├── RobotoSlab │ │ │ │ ├── roboto-slab-v7-bold.eot │ │ │ │ ├── roboto-slab-v7-bold.ttf │ │ │ │ ├── roboto-slab-v7-bold.woff │ │ │ │ ├── roboto-slab-v7-bold.woff2 │ │ │ │ ├── roboto-slab-v7-regular.eot │ │ │ │ ├── roboto-slab-v7-regular.ttf │ │ │ │ ├── roboto-slab-v7-regular.woff │ │ │ │ └── roboto-slab-v7-regular.woff2 │ │ │ ├── fontawesome-webfont.eot │ │ │ ├── fontawesome-webfont.svg │ │ │ ├── fontawesome-webfont.ttf │ │ │ ├── fontawesome-webfont.woff │ │ │ ├── fontawesome-webfont.woff2 │ │ │ ├── lato-bold-italic.woff │ │ │ ├── lato-bold-italic.woff2 │ │ │ ├── lato-bold.woff │ │ │ ├── lato-bold.woff2 │ │ │ ├── lato-normal-italic.woff │ │ │ ├── lato-normal-italic.woff2 │ │ │ ├── lato-normal.woff │ │ │ └── lato-normal.woff2 │ │ ├── jquery-3.5.1.js │ │ ├── jquery.js │ │ ├── js │ │ │ ├── badge_only.js │ │ │ ├── html5shiv-printshiv.min.js │ │ │ ├── html5shiv.min.js │ │ │ ├── modernizr.min.js │ │ │ └── theme.js │ │ ├── language_data.js │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── underscore-1.3.1.js │ │ └── underscore.js │ │ ├── genindex.html │ │ ├── index.html │ │ ├── objects.inv │ │ ├── search.html │ │ └── searchindex.js ├── make.bat └── source │ ├── Models │ ├── 01_TextCNN.rst │ ├── 02_RCNN.rst │ ├── 03_DPCNN.rst │ ├── 04_HAN.rst │ ├── 05_BertTextCNN.rst │ ├── 06_BertRCNN.rst │ ├── 07_BertDPCNN.rst │ ├── 08_BertHAN.rst │ └── index.rst │ ├── QuickStart │ └── index.rst │ ├── conf.py │ └── index.rst ├── examples ├── README.md ├── __init__.py ├── example_berttextcnn.py ├── example_textcnn.py ├── label.png ├── len.png └── preprocessing.py ├── setup.py └── tests ├── __init__.py ├── test_bertdpcnn.py ├── test_berthan.py ├── test_bertrcnn.py ├── test_berttextcnn.py ├── test_dpcnn.py ├── test_han.py ├── test_rcnn.py └── test_textcnn.py /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **DeepClassifier** 2 | DeepClassifier is a python package based on pytorch, which is easy-use and general for text classification task. You can install DeepClassifier by `pip install -U deepclassifier`。 3 | If you want to know more information about DeepClassifier, please see the [**documentation**](https://deepclassifier.readthedocs.io/en/latest/). So let's start!🤩 4 | > If you think DeepClassifier is good, please star and fork it to give me motivation to continue maintenance!🤩 And it's my pleasure that if Deepclassifier is helpful to you!🥰 5 | 6 | ## **Installation** 7 | Just like other Python packages, DeepClassifier also can be installed through pip.The command of installation is `pip install -U deepclassifier`. 8 | 9 | ## **Models** 10 | Here is a list of models that have been integrated into DeepClassifier. In the future, we will integrate more models into DeepClassifier. Welcome to join us!🤩 11 | 1. **TextCNN:** [Convolutional Neural Networks for Sentence Classification](https://www.aclweb.org/anthology/D14-1181.pdf) ,2014 EMNLP 12 | 2. **RCNN:** [Recurrent Convolutional Neural Networks for Text Classification](https://www.deeplearningitalia.com/wp-content/uploads/2018/03/Recurrent-Convolutional-Neural-Networks-for-Text-Classification.pdf),2015,IJCAI 13 | 3. **DPCNN:** [Deep Pyramid Convolutional Neural Networks for Text Categorization](https://ai.tencent.com/ailab/media/publications/ACL3-Brady.pdf) ,2017,ACL 14 | 4. **HAN:** [Hierarchical Attention Networks for Document Classification](https://www.aclweb.org/anthology/N16-1174.pdf), 2016,ACL 15 | 5. **BERT:** [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://arxiv.org/pdf/1810.04805.pdf),2018, ACL 16 | 6. **BertTextCNN:** BERT+TextCNN 17 | 7. **BertRCNN:** BERT+RCNN 18 | 8. **BertDPCNN:** BERT+DPCNN 19 | 9. **BertHAN:** BERT+HAN 20 | ... 21 | 22 | ## Quick start 23 | I wiil show you that how to use DeepClassifier below.🥰 Click [**[here]**](https://github.com/codewithzichao/DeepClassifier/blob/master/examples) to display the complete code. 24 | 25 | you can define model like that(take BertTextCNN model as example):👇 26 | 27 | ```python 28 | from deepclassifier.models import BertTextCNN 29 | 30 | # parameters of model 31 | embedding_dim = 768 # if you use bert, the default is 768. 32 | dropout_rate = 0.2 33 | num_class = 2 34 | bert_path = "/Users/codewithzichao/Desktop/bert-base-uncased/" 35 | 36 | my_model = BertTextCNN(embedding_dim=embedding_dim, 37 | dropout_rate=dropout_rate, 38 | num_class=num_class, 39 | bert_path=bert_path) 40 | 41 | optimizer = optim.Adam(my_model.parameters()) 42 | loss_fn = nn.CrossEntropyLoss() 43 | ``` 44 | After defining model, you can train/test/predict model like that:👇 45 | 46 | ```python 47 | from deepclassifier.trainers import Trainer 48 | 49 | model_name = "berttextcnn" 50 | save_path = "best.ckpt" 51 | writer = SummaryWriter("logfie/1") 52 | max_norm = 0.25 53 | eval_step_interval = 20 54 | 55 | my_trainer =Trainer(model_name=model_name,model=my_model, 56 | train_loader=train_loader,dev_loader=dev_loader, 57 | test_loader=test_loader, optimizer=optimizer, 58 | loss_fn=loss_fn,save_path=save_path, epochs=1, 59 | writer=writer, max_norm=max_norm, 60 | eval_step_interval=eval_step_interval) 61 | 62 | # training 63 | my_trainer.train() 64 | # print the best F1 value on dev set 65 | print(my_trainer.best_f1) 66 | 67 | # testing 68 | p, r, f1 = my_trainer.test() 69 | print(p, r, f1) 70 | 71 | # predict 72 | pred_data = DataLoader(pred_data, batch_size=1) 73 | pred_label = my_trainer.predict(pred_data) 74 | print(pred_label) 75 | 76 | ``` 77 | 78 | ## **Contact me** 79 | If you want any questions about DeepClassifier, welcome to submit issue or pull requests! And welcome to communicate with me through 2843656167@qq.com.🥳 80 | 81 | ## Citation 82 | ```tex 83 | @misc{zichao2020deepclassifier, 84 | author = {Zichao Li}, 85 | title = {DeepClassifier: use-friendly and flexiable package of NLP based text classification models}, 86 | year = {2020}, 87 | publisher = {GitHub}, 88 | journal = {GitHub Repository}, 89 | howpublished = {\url{https://github.com/codewithzichao/DeepClassifier}}, 90 | } 91 | ``` 92 | 93 | -------------------------------------------------------------------------------- /deepclassifier/__init__.py: -------------------------------------------------------------------------------- 1 | name = "deepclassifier" 2 | __version__="0.0.6" -------------------------------------------------------------------------------- /deepclassifier/layers/__init__.py: -------------------------------------------------------------------------------- 1 | from .lstm import LSTM 2 | -------------------------------------------------------------------------------- /deepclassifier/layers/lstm.py: -------------------------------------------------------------------------------- 1 | ''' 2 | source:https://github.com/songyingxin/TextClassification/blob/master/models/LSTM.py 3 | ''' 4 | 5 | import torch.nn as nn 6 | import torch.nn.functional as F 7 | import torch 8 | 9 | class LSTM(nn.Module): 10 | 11 | def __init__(self, input_size, hidden_size, num_layers, bidirectional, dropout, batch_first): 12 | """ 13 | Args: 14 | input_size: x 的特征维度 15 | hidden_size: 隐层的特征维度 16 | num_layers: LSTM 层数 17 | """ 18 | super(LSTM, self).__init__() 19 | 20 | self.rnn = nn.LSTM( 21 | input_size=input_size, hidden_size=hidden_size, num_layers=num_layers, bidirectional=bidirectional, 22 | dropout=dropout, batch_first=batch_first) 23 | 24 | def forward(self, x, lengths): 25 | # x: [seq_len, batch_size, input_size] 26 | # lengths: [batch_size] 27 | packed_x = nn.utils.rnn.pack_padded_sequence(x, lengths) 28 | 29 | # packed_x, packed_output: PackedSequence 对象 30 | # hidden: [num_layers * bidirectional, batch_size, hidden_size] 31 | # cell: [num_layers * bidirectional, batch_size, hidden_size] 32 | packed_output, (hidden, cell) = self.rnn(packed_x) 33 | 34 | # output: [real_seq_len, batch_size, hidden_size * 2] 35 | # output_lengths: [batch_size] 36 | output, output_lengths = nn.utils.rnn.pad_packed_sequence(packed_output) 37 | 38 | return hidden, output 39 | 40 | 41 | class GRU(nn.Module): 42 | 43 | def __init__(self, input_size, hidden_size, num_layers, bidirectional, dropout, batch_first): 44 | """ 45 | Args: 46 | input_size: x 的特征维度 47 | hidden_size: 隐层的特征维度 48 | num_layers: LSTM 层数 49 | """ 50 | super(GRU, self).__init__() 51 | 52 | self.rnn = nn.GRU( 53 | input_size=input_size, hidden_size=hidden_size, num_layers=num_layers, bidirectional=bidirectional, 54 | dropout=dropout, batch_first=batch_first) 55 | 56 | self.init_params() 57 | 58 | def init_params(self): 59 | for i in range(self.rnn.num_layers): 60 | nn.init.orthogonal_(getattr(self.rnn, f'weight_hh_l{i}')) 61 | nn.init.kaiming_normal_(getattr(self.rnn, f'weight_ih_l{i}')) 62 | nn.init.constant_(getattr(self.rnn, f'bias_hh_l{i}'), val=0) 63 | nn.init.constant_(getattr(self.rnn, f'bias_ih_l{i}'), val=0) 64 | getattr(self.rnn, f'bias_hh_l{i}').chunk(4)[1].fill_(1) 65 | 66 | if self.rnn.bidirectional: 67 | nn.init.orthogonal_( 68 | getattr(self.rnn, f'weight_hh_l{i}_reverse')) 69 | nn.init.kaiming_normal_( 70 | getattr(self.rnn, f'weight_ih_l{i}_reverse')) 71 | nn.init.constant_( 72 | getattr(self.rnn, f'bias_hh_l{i}_reverse'), val=0) 73 | nn.init.constant_( 74 | getattr(self.rnn, f'bias_ih_l{i}_reverse'), val=0) 75 | getattr(self.rnn, f'bias_hh_l{i}_reverse').chunk(4)[1].fill_(1) 76 | 77 | def forward(self, x, lengths): 78 | # x: [seq_len, batch_size, input_size] 79 | # lengths: [batch_size] 80 | packed_x = nn.utils.rnn.pack_padded_sequence(x, lengths) 81 | 82 | # packed_x, packed_output: PackedSequence 对象 83 | # hidden: [num_layers * bidirectional, batch_size, hidden_size] 84 | # cell: [num_layers * bidirectional, batch_size, hidden_size] 85 | packed_output, (hidden, cell) = self.rnn(packed_x) 86 | 87 | # output: [real_seq_len, batch_size, hidden_size * 2] 88 | # output_lengths: [batch_size] 89 | output, output_lengths = nn.utils.rnn.pad_packed_sequence(packed_output) 90 | 91 | return hidden, output 92 | -------------------------------------------------------------------------------- /deepclassifier/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .textcnn import TextCNN 2 | from .rcnn import RCNN 3 | from .dpcnn import DPCNN 4 | from .han import HAN 5 | from .berttextcnn import BertTextCNN 6 | from .bertrcnn import BertRCNN 7 | from .bertdpcnn import BertDPCNN 8 | from .berthan import BertHAN -------------------------------------------------------------------------------- /deepclassifier/models/bertdpcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | import torch.nn.functional as F 13 | from transformers import * 14 | import numpy as np 15 | 16 | class BertDPCNN(nn.Module): 17 | def __init__(self, 18 | embedding_dim, 19 | dropout_rate, 20 | num_class, 21 | bert_path, 22 | num_blocks=3, 23 | kernel_sizes=3, 24 | num_filters=250, 25 | requires_grads=False): 26 | ''' 27 | initialization 28 | :param embedding_dim: embedding dim 29 | :param dropout_rate: dropout rate 30 | :param num_class: the number of label 31 | :param bert_path: bert path 32 | :param num_blocks: the number of block ,default:3 33 | :param kernel_sizes: kernel size 34 | :param num_filters: the number of filter 35 | :param requires_grads: whether to update gradient of Bert in training 36 | ''' 37 | super(BertDPCNN, self).__init__() 38 | 39 | self.embedding_dim = embedding_dim 40 | self.num_blocks = num_blocks 41 | self.kernel_sizes = kernel_sizes 42 | self.num_filters = num_filters 43 | self.dropout_rate = dropout_rate 44 | self.num_class = num_class 45 | self.bert_path=bert_path 46 | self.requires_grads=requires_grads 47 | 48 | self.bert = BertModel.from_pretrained(self.bert_path) 49 | if self.requires_grads is False: 50 | for p in self.bert.parameters(): 51 | p.requires_grads=False 52 | 53 | # text region embedding 54 | self.region_embedding = nn.Conv2d(in_channels=1, out_channels=self.num_filters, 55 | stride=1, kernel_size=(self.kernel_sizes, self.embedding_dim)) 56 | 57 | # two conv 58 | self.conv2d1 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 59 | stride=2, kernel_size=(self.kernel_sizes, 1), padding=0) 60 | self.conv2d2 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 61 | stride=2, kernel_size=(self.kernel_sizes, 1), padding=0) 62 | self.padding1 = nn.ZeroPad2d((0, 0,(self.kernel_sizes-1)//2, (self.kernel_sizes-1)-((self.kernel_sizes-1)//2))) # top bottom 63 | self.padding2 = nn.ZeroPad2d((0, 0, 0, self.kernel_sizes-2)) # bottom 64 | 65 | # one block 66 | self.block_max_pool = nn.MaxPool2d(kernel_size=(self.kernel_sizes, 1), stride=2) 67 | self.conv2d3 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 68 | stride=1, kernel_size=(self.kernel_sizes, 1), padding=0) 69 | self.conv2d4 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 70 | stride=1, kernel_size=(self.kernel_sizes, 1), padding=0) 71 | 72 | # final pool and softmax 73 | 74 | self.flatten = nn.Flatten() 75 | self.dropout=nn.Dropout(p=self.dropout_rate) 76 | self.classifier = nn.Linear(in_features=self.num_filters, out_features=self.num_class) 77 | 78 | def forward(self, input_ids, attention_mask=None): 79 | ''' 80 | forard propagation 81 | :param params: input_ids:[batch_size,max_length] 82 | :param params: attention_mask:[batch_size,max_length] 83 | :return: logits:[batch_size,num_class] 84 | ''' 85 | 86 | bert_output = self.bert(input_ids=input_ids, attention_mask=attention_mask) 87 | embedding = bert_output.last_hidden_state.unsqueeze(dim=1) 88 | 89 | x = self.region_embedding(embedding) 90 | 91 | x = self.padding1(x) 92 | x = torch.relu(self.conv2d1(x)) 93 | x = self.padding1(x) 94 | x = torch.relu(self.conv2d2(x)) 95 | for i in range(self.num_blocks): 96 | x = self._block(x) 97 | 98 | x = self.flatten(x) 99 | x=self.dropout(x) 100 | outputs = self.classifier(x) 101 | 102 | return outputs 103 | 104 | def _block(self, x): 105 | 106 | x = self.padding2(x) 107 | pool_x = self.block_max_pool(x) 108 | 109 | x = self.padding1(pool_x) 110 | x = F.relu(self.conv2d3(x)) 111 | x = self.padding1(x) 112 | x = F.relu(self.conv2d4(x)) 113 | 114 | return x + pool_x 115 | -------------------------------------------------------------------------------- /deepclassifier/models/berthan.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | import torch.nn.functional as F 13 | import numpy as np 14 | from transformers import * 15 | 16 | class BertHAN(nn.Module): 17 | def __init__(self, 18 | embedding_dim, 19 | word_hidden_size, 20 | seq_hidden_size, 21 | dropout_rate, 22 | num_class, 23 | bert_path, 24 | rnn_type="lstm", 25 | requires_grads=False): 26 | ''' 27 | initialization 28 | :param embedding_dim: embedding dim 29 | :param word_hidden_size: word hidden size 30 | :param seq_hidden_size: sequence hidden size 31 | :param dropout_rate: dropout rate 32 | :param num_class: the number of label 33 | :param bert_path: bert path 34 | :param rnn_type: rnn type. default:lstm 35 | :param requires_grads: whether to update gradient of Bert in training 36 | ''' 37 | super(BertHAN,self).__init__() 38 | self.embedding_dim = embedding_dim 39 | self.word_hidden_size = word_hidden_size 40 | self.seq_hidden_size = seq_hidden_size 41 | self.rnn_type = rnn_type 42 | self.dropout_rate = dropout_rate 43 | self.num_class = num_class 44 | self.bert_path=bert_path 45 | self.requires_grads=requires_grads 46 | 47 | self.bert=BertModel.from_pretrained(self.bert_path) 48 | if self.requires_grads is False: 49 | for p in self.bert.parameters(): 50 | p.requires_grads=False 51 | 52 | if self.rnn_type == "lstm": 53 | self.word_rnn = nn.LSTM(input_size=self.embedding_dim, hidden_size=self.word_hidden_size, 54 | batch_first=True, num_layers=1, bidirectional=True) 55 | self.seq_rnn = nn.LSTM(input_size=self.word_hidden_size * 2, hidden_size=self.seq_hidden_size, 56 | batch_first=True, num_layers=1, bidirectional=True) 57 | elif self.rnn_type=="gru": 58 | self.word_rnn = nn.GRU(input_size=self.embedding_dim, hidden_size=self.word_hidden_size, 59 | batch_first=True, num_layers=1, bidirectional=True) 60 | self.seq_rnn = nn.GRU(input_size=self.word_hidden_size * 2, hidden_size=self.seq_hidden_size, 61 | batch_first=True, num_layers=1, bidirectional=True) 62 | else: 63 | raise Exception("wrong rnn type,must be one of [lstm,gru].") 64 | 65 | self.fc1=nn.Linear(in_features=self.word_hidden_size * 2, out_features=self.word_hidden_size * 2) 66 | self.U_w=nn.Parameter(torch.Tensor(self.word_hidden_size * 2, self.word_hidden_size * 2)) 67 | self.fc2=nn.Linear(in_features=self.word_hidden_size * 2, out_features=self.word_hidden_size * 2) 68 | self.U_s=nn.Parameter(torch.Tensor(self.word_hidden_size*2,self.word_hidden_size*2)) 69 | 70 | self.dropout=nn.Dropout(p=self.dropout_rate) 71 | self.classifer=nn.Linear(in_features=self.word_hidden_size*2,out_features=self.num_class) 72 | 73 | def forward(self, input_ids, attention_mask=None): 74 | ''' 75 | forard propagation 76 | :param params: input_ids:[batch_size,max_seq_length,max_word_length] 77 | :param params: attention_mask:[batch_size,max_seq_length,max_word_length] 78 | :return: logits:[batch_size,num_class] 79 | ''' 80 | 81 | seq_length=input_ids.size()[1] 82 | word_length=input_ids.size()[2] 83 | input_ids=input_ids.view(-1,word_length) 84 | if attention_mask is not None: 85 | attention_mask=attention_mask.view(-1,word_length) 86 | 87 | # bert encoding 88 | bert_output=self.bert(input_ids=input_ids,attention_mask=attention_mask) 89 | x=bert_output.last_hidden_state 90 | x,_=self.word_rnn(x) 91 | 92 | # char attention 93 | temp=torch.tanh(self.fc1(x)) 94 | char_score=torch.matmul(temp,self.U_w) 95 | char_weights=F.softmax(char_score,dim=1) 96 | x=torch.mul(char_weights,x) 97 | x=torch.sum(x,dim=1) 98 | 99 | x=x.view(-1,seq_length,x.shape[-1]) 100 | x,_=self.seq_rnn(x) 101 | 102 | # word attention 103 | temp=torch.tanh(x) 104 | word_score=torch.matmul(temp,self.U_s) 105 | word_weights=F.softmax(word_score,dim=1) 106 | x=torch.mul(word_weights,x) 107 | x=torch.sum(x,dim=1) 108 | 109 | x=self.dropout(x) 110 | outputs=self.classifer(x) 111 | 112 | return outputs 113 | -------------------------------------------------------------------------------- /deepclassifier/models/bertrcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | from transformers import * 13 | import numpy as np 14 | 15 | class BertRCNN(nn.Module): 16 | def __init__(self, 17 | embedding_dim, 18 | hidden_size, 19 | dropout_rate, 20 | num_class, 21 | bert_path, 22 | rnn_type="lstm", 23 | num_layers=1, 24 | requires_grads=False): 25 | ''' 26 | initialization 27 | :param embedding_dim:embedding dim 28 | :param hidden_size: rnn hidden size 29 | :param dropout_rate: dropout rate 30 | :param num_class: the number of label 31 | :param bert_path: bert path 32 | :param rnn_type: rnn type. Default:lstm 33 | :param num_layers: the number of rnn layer 34 | :param requires_grads: whether to update gradient of Bert in training stage 35 | ''' 36 | super(BertRCNN, self).__init__() 37 | self.embedding_dim = embedding_dim 38 | self.num_layers = num_layers 39 | self.hidden_size = hidden_size 40 | self.rnn_type = rnn_type 41 | self.dropout_rate = dropout_rate 42 | self.num_class = num_class 43 | self.bert_path=bert_path 44 | self.requires_grads=requires_grads 45 | 46 | self.bert = AutoModel.from_pretrained(self.bert_path) 47 | if self.requires_grads is False: 48 | for p in self.bert.parameters(): 49 | p.requires_grads = False 50 | 51 | if self.rnn_type == "lstm": 52 | self.birnn = nn.LSTM(input_size=self.embedding_dim, hidden_size=self.hidden_size, 53 | num_layers=self.num_layers, batch_first=True, bidirectional=True) 54 | elif self.rnn_type == "gru": 55 | self.birnn = nn.GRU(input_size=self.embedding_dim, hidden_size=self.hidden_size, 56 | num_layers=self.num_layers, batch_first=True, bidirectional=True) 57 | else: 58 | raise ValueError("rnn type must be one of {lstm,gru}.") 59 | 60 | self.W = nn.Linear(in_features=self.embedding_dim + self.hidden_size * 2 * self.num_layers, 61 | out_features=self.hidden_size * 2) 62 | 63 | self.global_max_pool1d = nn.AdaptiveMaxPool1d(output_size=1) 64 | self.classifier = nn.Linear(in_features=self.hidden_size * 2, out_features=self.num_class) 65 | 66 | def forward(self, input_ids, attention_mask=None): 67 | ''' 68 | forard propagation 69 | :param params: input_ids:[batch_size,max_length] 70 | :param params: attention_mask:[batch_size,max_length] 71 | :return: logits:[batch_size,num_class] 72 | ''' 73 | 74 | bert_output = self.bert(input_ids=input_ids, attention_mask=attention_mask) 75 | x = bert_output.last_hidden_state 76 | 77 | rnn_output, _ = self.birnn(x) 78 | x = torch.cat((x, rnn_output), dim=-1) 79 | x = torch.tanh(self.W(x)) 80 | x = x.permute(0, 2, 1) 81 | x = self.global_max_pool1d(x).squeeze(dim=-1) 82 | outputs = self.classifier(x) 83 | 84 | return outputs 85 | -------------------------------------------------------------------------------- /deepclassifier/models/berttextcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | from transformers import * 13 | 14 | class BertTextCNN(nn.Module): 15 | def __init__(self, 16 | embedding_dim, 17 | dropout_rate, 18 | num_class, 19 | bert_path, 20 | num_layers=3, 21 | kernel_sizes=[3, 4, 5], 22 | num_filters=[100, 100, 100], 23 | strides=[1, 1, 1], 24 | paddings=[0, 0, 0], 25 | requires_grads=False): 26 | ''' 27 | initialization 28 | ⚠⚠️In default,the way to initialize embedding is loading pretrained embedding look-up table! 29 | :param dropout_rate: dropout rate 30 | :param num_class: the number of label 31 | :param bert_path: bert config path 32 | :param embedding_dim: embedding dim 33 | :param num_layers: the number of cnn layer 34 | :param kernel_sizes: list of conv kernel size 35 | :param num_filters: list of conv filters 36 | :param strides: list of conv strides 37 | :param paddings: list of conv padding 38 | :param requires_grads: whther to update gradient of Bert in training stage 39 | ''' 40 | super(BertTextCNN, self).__init__() 41 | self.embedding_dim = embedding_dim 42 | self.num_layers = num_layers 43 | self.kernel_sizes = kernel_sizes 44 | self.num_filters = num_filters 45 | self.strides = strides 46 | self.paddings = paddings 47 | self.dropout_rate = dropout_rate 48 | self.num_class = num_class 49 | self.bert_path=bert_path 50 | self.requires_grads=requires_grads 51 | 52 | self.bert = AutoModel.from_pretrained(self.bert_path) 53 | if self.requires_grads is False: 54 | for p in self.bert.parameters(): 55 | p.requires_grads = False 56 | 57 | if self.num_layers != len(self.kernel_sizes) or self.num_layers != len(self.num_filters): 58 | raise Exception("The number of num_layers and num_filters must be equal to the number of kernel_sizes!") 59 | 60 | self.conv1ds = [] 61 | self.global_max_pool1ds = [] 62 | final_hidden_size = sum(self.num_filters) 63 | for i in range(self.num_layers): 64 | conv1d = nn.Conv1d(in_channels=self.embedding_dim, out_channels=self.num_filters[i], 65 | kernel_size=self.kernel_sizes[i], 66 | stride=self.strides[i], padding=self.paddings[i]) 67 | global_max_pool1d = nn.AdaptiveMaxPool1d(output_size=1) 68 | self.conv1ds.append(conv1d) 69 | self.global_max_pool1ds.append(global_max_pool1d) 70 | 71 | self.dropout = nn.Dropout(p=self.dropout_rate) 72 | self.classifier = nn.Linear(in_features=final_hidden_size, out_features=self.num_class) 73 | 74 | def forward(self, input_ids, attention_mask=None): 75 | ''' 76 | forard propagation 77 | :param params: input_ids:[batch_size,max_length] 78 | :param params: attention_mask:[batch_size,max_length] 79 | :return: logits:[batch_size,num_class] 80 | ''' 81 | 82 | bert_output = self.bert(input_ids=input_ids, attention_mask=attention_mask) 83 | x = bert_output.last_hidden_state 84 | 85 | x = x.permute(0, 2, 1) 86 | cnn_pool_result = [] 87 | for i in range(self.num_layers): 88 | temp = torch.relu(self.conv1ds[i](x)) 89 | temp = self.global_max_pool1ds[i](temp).squeeze(dim=-1) 90 | cnn_pool_result.append(temp) 91 | 92 | x = torch.cat(cnn_pool_result, dim=-1) 93 | x = self.dropout(x) 94 | outputs = self.classifier(x) 95 | 96 | return outputs 97 | 98 | 99 | -------------------------------------------------------------------------------- /deepclassifier/models/dpcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | import torch.nn.functional as F 13 | 14 | 15 | class DPCNN(nn.Module): 16 | def __init__(self, 17 | embedding_dim, 18 | dropout_rate, 19 | num_class, 20 | vocab_size=0, 21 | seq_length=0, 22 | num_blocks=3, 23 | num_filters=250, 24 | kernel_sizes=3, 25 | embedding_matrix=None, 26 | requires_grads=False): 27 | ''' 28 | initialization 29 | ⚠️In default,the way to initialize embedding is loading pretrained embedding look-up table! 30 | :param embedding_dim: embedding dim 31 | :param num_class: the number of label 32 | :param dropout_rate: dropout rate 33 | :param vocab_size: vocabulary size 34 | :param seq_length: max length of sequence after padding 35 | :param num_blocks: the number of block in DPCNN model 36 | :param num_filters: the number of filters of conv kernel 37 | :param kernel_sizes: conv kernel size 38 | :param embedding_matrix: pretrained embedding look up table 39 | :param requires_grads: whether to update gradient of embedding in training stage 40 | ''' 41 | super(DPCNN, self).__init__() 42 | 43 | self.vocab_size = vocab_size 44 | self.seq_length = seq_length 45 | self.embedding_dim = embedding_dim 46 | self.num_filters = num_filters 47 | self.dropout_rate=dropout_rate 48 | self.num_blocks = num_blocks 49 | self.num_class = num_class 50 | self.kernel_sizes = kernel_sizes 51 | self.embedding_matrix = embedding_matrix 52 | self.requires_grads = requires_grads 53 | 54 | # embedding 55 | if self.embedding_matrix is None: 56 | self.embedding = nn.Embedding(num_embeddings=self.vocab_size, 57 | embedding_dim=self.embedding_dim, 58 | padding_idx=0) 59 | else: 60 | self.embedding = nn.Embedding.from_pretrained(self.embedding_matrix, freeze=self.requires_grads) 61 | self.vocab_size = self.embedding_matrix.shape[0] 62 | 63 | # text region embedding 64 | self.region_embedding = nn.Conv2d(in_channels=1, out_channels=self.num_filters, 65 | stride=1, kernel_size=(self.kernel_sizes, self.embedding_dim)) 66 | 67 | # two conv 68 | self.conv2d1 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 69 | stride=2, kernel_size=(self.kernel_sizes, 1), padding=0) 70 | self.conv2d2 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 71 | stride=2, kernel_size=(self.kernel_sizes, 1), padding=0) 72 | self.padding1 = nn.ZeroPad2d((0, 0, (self.kernel_sizes-1)//2, (self.kernel_sizes-1)-((self.kernel_sizes-1)//2))) # top bottom 73 | self.padding2 = nn.ZeroPad2d((0, 0, 0, self.kernel_sizes-2)) # bottom 74 | 75 | # one block 76 | self.block_max_pool = nn.MaxPool2d(kernel_size=(self.kernel_sizes, 1), stride=2) 77 | self.conv2d3 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 78 | stride=1, kernel_size=(self.kernel_sizes, 1), padding=0) 79 | self.conv2d4 = nn.Conv2d(in_channels=self.num_filters, out_channels=self.num_filters, 80 | stride=1, kernel_size=(self.kernel_sizes, 1), padding=0) 81 | 82 | # final pool and softmax 83 | self.flatten = nn.Flatten() 84 | self.dropout=nn.Dropout(p=self.dropout_rate) 85 | self.classifier = nn.Linear(in_features=self.num_filters, out_features=self.num_class) 86 | 87 | def forward(self, inputs): 88 | ''' 89 | forward propagation 90 | :param inputs: [batch_size,seq_length] 91 | :return: [batch_size,num_class] 92 | ''' 93 | 94 | embedding=self.embedding(inputs).unsqueeze(dim=1) 95 | x = self.region_embedding(embedding) 96 | 97 | x = self.padding1(x) 98 | x = torch.relu(self.conv2d1(x)) 99 | x = self.padding1(x) 100 | x = torch.relu(self.conv2d2(x)) 101 | for i in range(self.num_blocks): 102 | x = self._block(x) 103 | 104 | x = self.flatten(x) 105 | x=self.dropout(x) 106 | outputs = self.classifier(x) 107 | 108 | return outputs 109 | 110 | def _block(self, x): 111 | 112 | x = self.padding2(x) 113 | pool_x = self.block_max_pool(x) 114 | 115 | x = self.padding1(pool_x) 116 | x = F.relu(self.conv2d3(x)) 117 | x = self.padding1(x) 118 | x = F.relu(self.conv2d4(x)) 119 | 120 | return x + pool_x 121 | 122 | 123 | -------------------------------------------------------------------------------- /deepclassifier/models/han.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | import torch.nn.functional as F 13 | import numpy as np 14 | import torch.optim as optim 15 | 16 | class HAN(nn.Module): 17 | def __init__(self, 18 | embedding_dim, 19 | word_hidden_size, 20 | seq_hidden_size, 21 | dropout_rate, 22 | num_class, 23 | vocab_size=0, 24 | seq_length=0, 25 | rnn_type="lstm", 26 | embedding_matrix=None, 27 | requires_grads=False): 28 | ''' 29 | initialization 30 | ⚠️In default,the way to initialize embedding is loading pretrained embedding look-up table! 31 | :param embedding_dim: embedding dim 32 | :param word_hidden_size: word hidden size 33 | :param seq_hidden_size: seq hidden size 34 | :param dropout_rate: dropout rate 35 | :param num_class: the number of label 36 | :param vocab_size: vocabulary size 37 | :param seq_length: sequence length 38 | :param rnn_type: rnn type,which must be lstm or gru. 39 | :param embedding_matrix: pretrained embedding lookup table,shape is [vocab_size,embedidng_dim] 40 | :param requires_grads: whether to update gradient of embedding in training stage 41 | ''' 42 | super(HAN,self).__init__() 43 | self.vocab_size = vocab_size 44 | self.seq_length = seq_length 45 | self.embedding_dim = embedding_dim 46 | self.word_hidden_size = word_hidden_size 47 | self.seq_hidden_size=seq_hidden_size 48 | self.dropout_rate=dropout_rate 49 | self.num_class=num_class 50 | self.rnn_type = rnn_type 51 | self.embedding_matrix = embedding_matrix 52 | self.requires_grads=requires_grads 53 | 54 | if self.embedding_matrix is None: 55 | self.embedding = nn.Embedding(num_embeddings=self.vocab_size, 56 | embedding_dim=self.embedding_dim, 57 | padding_idx=0) 58 | else: 59 | self.embedding = nn.Embedding.from_pretrained(self.embedding_matrix, freeze=self.requires_grads) 60 | self.vocab_size = self.embedding_matrix.shape[0] 61 | 62 | if self.rnn_type == "lstm": 63 | self.word_rnn = nn.LSTM(input_size=self.embedding_dim, hidden_size=self.word_hidden_size, 64 | batch_first=True, num_layers=1, bidirectional=True) 65 | self.seq_rnn = nn.LSTM(input_size=self.word_hidden_size * 2, hidden_size=self.seq_hidden_size, 66 | batch_first=True, num_layers=1, bidirectional=True) 67 | elif self.rnn_type == "gru": 68 | self.word_rnn = nn.GRU(input_size=self.embedding_dim, hidden_size=self.word_hidden_size, 69 | batch_first=True, num_layers=1, bidirectional=True) 70 | self.seq_rnn = nn.GRU(input_size=self.word_hidden_size * 2, hidden_size=self.seq_hidden_size, 71 | batch_first=True, num_layers=1, bidirectional=True) 72 | else: 73 | raise Exception("wrong rnn type,must be one of [lstm,gru].") 74 | 75 | self.fc1 = nn.Linear(in_features=self.word_hidden_size * 2, out_features=self.word_hidden_size * 2) 76 | self.U_w = nn.Parameter(torch.Tensor(self.word_hidden_size * 2, self.word_hidden_size * 2)) 77 | self.fc2 = nn.Linear(in_features=self.word_hidden_size * 2, out_features=self.word_hidden_size * 2) 78 | self.U_s = nn.Parameter(torch.Tensor(self.word_hidden_size * 2, self.word_hidden_size * 2)) 79 | 80 | self.dropout=nn.Dropout(p=self.dropout_rate) 81 | self.classifer = nn.Linear(in_features=self.word_hidden_size * 2, out_features=self.num_class) 82 | 83 | def forward(self,inputs): 84 | 85 | word_length=inputs.size()[-1] 86 | seq_length=inputs.size()[1] 87 | inputs=inputs.view(-1,word_length) 88 | x=self.embedding(inputs) 89 | x, _ = self.word_rnn(x) 90 | 91 | # char attention 92 | temp = torch.tanh(self.fc1(x)) 93 | char_score = torch.matmul(temp, self.U_w) 94 | char_weights = F.softmax(char_score, dim=1) 95 | x = torch.mul(char_weights, x) 96 | x = torch.sum(x, dim=1) 97 | 98 | x = x.view(-1, seq_length, x.shape[-1]) 99 | x, _ = self.seq_rnn(x) 100 | 101 | # word attention 102 | temp = torch.tanh(x) 103 | word_score = torch.matmul(temp, self.U_s) 104 | word_weights = F.softmax(word_score, dim=1) 105 | x = torch.mul(word_weights, x) 106 | x = torch.sum(x, dim=1) 107 | 108 | x=self.dropout(x) 109 | outputs = self.classifer(x) 110 | 111 | return outputs 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /deepclassifier/models/rcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | import numpy as np 13 | from deepclassifier.layers import LSTM 14 | 15 | class RCNN(nn.Module): 16 | def __init__(self, 17 | embedding_dim, 18 | hidden_size, 19 | dropout_rate, 20 | num_class, 21 | vocab_size=0, 22 | seq_length=0, 23 | rnn_type="lstm", 24 | num_layers=1, 25 | embedding_matrix=None, 26 | requires_grads=False): 27 | ''' 28 | initialization 29 | ⚠️In default,the way to initialize embedding is loading pretrained embedding look-up table! 30 | :param embedding_dim: embedding dim 31 | :param hidden_size: hidden size of rnn 32 | :param dropout_rate: dropout rate 33 | :param num_class: the number of label 34 | :param vocab_size: vocabulary size 35 | :param seq_length: max length of sequence after padding 36 | :param rnn_type: the type of rnn, which must be lstm or gru. Default: lstm. 37 | :param num_layers: the number of rnn layer.Default: 1. 38 | :param embedding_matrix: pretrained embedding look-up table,shape is [vocab_size,embedding_dim] 39 | :param requires_grads: whether to update gradient of embedding look up table in training stage 40 | ''' 41 | super(RCNN, self).__init__() 42 | 43 | self.vocab_size = vocab_size 44 | self.seq_length = seq_length 45 | self.embedding_dim = embedding_dim 46 | self.hidden_size = hidden_size 47 | self.num_class = num_class 48 | self.rnn_type = rnn_type 49 | self.dropout_rate=dropout_rate 50 | self.num_layers = num_layers 51 | self.embedding_matrix = embedding_matrix 52 | self.requires_grads = requires_grads 53 | 54 | if self.embedding_matrix is None: 55 | self.embedding = nn.Embedding(num_embeddings=self.vocab_size, 56 | embedding_dim=self.embedding_dim, 57 | padding_idx=0) 58 | else: 59 | self.embedding = nn.Embedding.from_pretrained(self.embedding_matrix, freeze=self.requires_grads) 60 | self.vocab_size = self.embedding_matrix.shape[0] 61 | 62 | if self.rnn_type == "lstm": 63 | self.birnn = nn.LSTM(input_size=self.embedding_dim, hidden_size=self.hidden_size, 64 | num_layers=self.num_layers, batch_first=True, bidirectional=True) 65 | elif self.rnn_type == "gru": 66 | self.birnn = nn.GRU(input_size=self.embedding_dim, hidden_size=self.hidden_size, 67 | num_layers=self.num_layers, batch_first=True, bidirectional=True) 68 | 69 | self.W = nn.Linear(in_features=self.embedding_dim + self.hidden_size * 2 * self.num_layers, 70 | out_features=self.hidden_size * 2) 71 | 72 | self.global_max_pool1d = nn.AdaptiveMaxPool1d(output_size=1) 73 | self.dropout=nn.Dropout(p=self.dropout_rate) 74 | self.classifier = nn.Linear(in_features=self.hidden_size * 2, out_features=self.num_class) 75 | 76 | def forward(self, input_ids,input_len=None): 77 | ''' 78 | forward propagation 79 | :param inputs: [batch_size,seq_length] 80 | :return: [batch_size,num_class] 81 | ''' 82 | 83 | x = self.embedding(input_ids) 84 | temp, _ = self.birnn(x) 85 | x = torch.cat((x, temp), dim=-1) 86 | x = torch.tanh(self.W(x)) 87 | x = x.permute(0, 2, 1) 88 | x = self.global_max_pool1d(x).squeeze(dim=-1) 89 | x=self.dropout(x) 90 | outputs = self.classifier(x) 91 | 92 | return outputs -------------------------------------------------------------------------------- /deepclassifier/models/textcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import torch 11 | import torch.nn as nn 12 | import numpy as np 13 | 14 | class TextCNN(nn.Module): 15 | def __init__(self, 16 | embedding_dim, 17 | dropout_rate, 18 | num_class, 19 | vocab_size=0, 20 | seq_length=0, 21 | num_layers=3, 22 | kernel_sizes=[3, 4, 5], 23 | strides=[1, 1, 1], 24 | paddings=[0, 0, 0], 25 | num_filters=[100, 100, 100], 26 | embedding_matrix=None, 27 | requires_grads=False): 28 | ''' 29 | initialization 30 | ⚠️In default,the way to initialize embedding is loading pretrained embedding look-up table! 31 | :param embedding_dim: embedding dim 32 | :param dropout_rate: drouput rate 33 | :param num_class: the number of label 34 | :param vocab_size: vocabulary size 35 | :param seq_length: max length of sequence after padding 36 | :param num_layers: the number of cnn 37 | :param kernel_sizes: list of conv kernel size 38 | :param strides: list of conv strides 39 | :param paddings: list of padding 40 | :param num_filters: list of num filters 41 | :param embedding_matrix: pretrained embedding look-up table,shape is:[vocab_size,embedding_dim] 42 | :param requires_grads: whether to update gradient of embedding in training 43 | ''' 44 | super(TextCNN, self).__init__() 45 | 46 | self.vocab_size = vocab_size 47 | self.seq_length = seq_length 48 | self.embedding_dim = embedding_dim 49 | self.num_layers = num_layers 50 | self.kernel_sizes = kernel_sizes 51 | self.strides = strides 52 | self.paddings = paddings 53 | self.num_filters = num_filters 54 | self.dropout_rate = dropout_rate 55 | self.num_class = num_class 56 | self.embedding_matrix = embedding_matrix 57 | self.requires_grads = requires_grads 58 | 59 | if self.num_layers != len(self.kernel_sizes) or self.num_layers != len(self.num_filters): 60 | raise ValueError("The number of num_layers and num_filters must be equal to the number of kernel_sizes!") 61 | 62 | # embedding 63 | if self.embedding_matrix is None: 64 | self.embedding = nn.Embedding(num_embeddings=self.vocab_size, 65 | embedding_dim=self.embedding_dim, 66 | padding_idx=0) 67 | else: 68 | self.embedding = nn.Embedding.from_pretrained(self.embedding_matrix, freeze=self.requires_grads) 69 | self.vocab_size = self.embedding_matrix.shape[0] 70 | 71 | # conv layers 72 | self.conv1ds = [] 73 | self.global_max_pool1ds = [] 74 | final_hidden_size = sum(self.num_filters) 75 | for i in range(self.num_layers): 76 | conv1d = nn.Conv1d(in_channels=self.embedding_dim, out_channels=self.num_filters[i], 77 | kernel_size=self.kernel_sizes[i], 78 | stride=self.strides[i], padding=self.paddings[i]) 79 | global_max_pool1d = nn.AdaptiveMaxPool1d(output_size=1) 80 | self.conv1ds.append(conv1d) 81 | self.global_max_pool1ds.append(global_max_pool1d) 82 | 83 | # dropout 84 | self.dropout = nn.Dropout(p=self.dropout_rate) 85 | self.classifier = nn.Linear(in_features=final_hidden_size, out_features=self.num_class) 86 | 87 | def forward(self, input_ids): 88 | ''' 89 | forward propagation 90 | :param inputs: [batch_size,seq_length] 91 | :return: [batch_size,num_class] 92 | ''' 93 | 94 | x = self.embedding(input_ids) 95 | x = x.permute(0, 2, 1) 96 | cnn_pool_result = [] 97 | for i in range(self.num_layers): 98 | temp = torch.relu(self.conv1ds[i](x)) 99 | temp = self.global_max_pool1ds[i](temp).squeeze(dim=-1) 100 | cnn_pool_result.append(temp) 101 | 102 | x = torch.cat(cnn_pool_result, dim=-1) 103 | x = self.dropout(x) 104 | outputs = self.classifier(x) 105 | 106 | return outputs 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /deepclassifier/trainers/__init__.py: -------------------------------------------------------------------------------- 1 | from .trainer import Trainer -------------------------------------------------------------------------------- /deepclassifier/trainers/trainer.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | Author: 4 | Zichao Li,2843656167@qq.com 5 | ''' 6 | from __future__ import print_function 7 | 8 | import torch 9 | import torch.nn as nn 10 | import torch.nn.functional as F 11 | from sklearn.metrics import * 12 | import numpy as np 13 | 14 | 15 | class Trainer(object): 16 | def __init__(self, 17 | model_name, 18 | model, 19 | train_loader, 20 | dev_loader, 21 | test_loader, 22 | optimizer, 23 | loss_fn, 24 | save_path, 25 | epochs, 26 | writer, 27 | max_norm, 28 | eval_step_interval, 29 | device="cpu"): 30 | super(Trainer, self).__init__() 31 | 32 | self.model_name = model_name.lower() 33 | self.model = model 34 | self.train_loader = train_loader 35 | self.dev_loader = dev_loader 36 | self.test_loader = test_loader 37 | self.optimizer = optimizer 38 | self.loss_fn = loss_fn 39 | self.save_path = save_path 40 | self.epochs = epochs 41 | self.writer = writer 42 | self.max_norm = max_norm 43 | self.step_interval = eval_step_interval 44 | self.device = torch.device(device) 45 | 46 | self.model.to(self.device) 47 | 48 | def train(self): 49 | self.model.train() 50 | self.best_f1 = 0.0 51 | global_steps = 1 52 | 53 | for epoch in range(1, self.epochs + 1): 54 | for idx, batch_data in enumerate(self.train_loader, start=1): 55 | 56 | if self.model_name in ["textcnn", "rcnn", "han", "dpcnn"]: 57 | input_ids, y_true = batch_data[0], batch_data[-1] 58 | if y_true.shape !=1: 59 | y_true=y_true.squeeze(dim=-1) 60 | logits = self.model(input_ids.to(self.device)) 61 | elif self.model_name in ["berttextcnn", "bertrcnn", "berthan", "bertdpcnn"]: 62 | if len(batch_data) == 3: 63 | input_ids, attention_mask, y_true = batch_data[0], batch_data[1], batch_data[-1] 64 | if y_true.shape !=1: 65 | y_true=y_true.squeeze(dim=-1) 66 | logits = self.model(input_ids.to(self.device), attention_mask.to(self.device)) 67 | else: 68 | input_ids, y_true = batch_data[0], batch_data[-1] 69 | if y_true.shape !=1: 70 | y_true=y_true.squeeze(dim=-1) 71 | logits = self.model(input_ids.to(self.device)) 72 | else: 73 | raise ValueError("the number of batch_data is wrong!") 74 | 75 | loss = self.loss_fn(logits, y_true) 76 | if self.writer is not None: 77 | self.writer.add_scalar("train/loss", loss.cpu().item(), global_step=global_steps) 78 | print( 79 | "epoch:{epoch},step:{step},train_loss:{loss}.".format(epoch=epoch, step=idx, 80 | loss=loss.cpu().item())) 81 | 82 | self.optimizer.zero_grad() 83 | loss.backward() 84 | torch.nn.utils.clip_grad_norm_(self.model.parameters(), max_norm=self.max_norm) 85 | self.optimizer.step() 86 | 87 | global_steps += 1 88 | 89 | if global_steps % self.step_interval == 0: 90 | p, r, f1 = self.eval() 91 | if self.writer is not None: 92 | self.writer.add_scalar("valid/p", p, global_steps) 93 | self.writer.add_scalar("valid/r", r, global_steps) 94 | self.writer.add_scalar("valid/f1", f1, global_steps) 95 | print("------start evaluating model in dev data------") 96 | print( 97 | "epoch:{epoch},step:{idx},precision:{p},recall:{r},F1-score:{f1}".format(epoch=epoch, 98 | idx=idx, p=p, 99 | r=r, f1=f1)) 100 | if self.best_f1 < f1: 101 | self.best_f1 = f1 102 | torch.save(self.model.state_dict(), f=self.save_path) 103 | 104 | print("epoch:{epoch},step:{idx},best_f1:{best_f1}".format(epoch=epoch, idx=idx, 105 | best_f1=self.best_f1)) 106 | print("------finish evaluating model in dev data------") 107 | self.model.train() 108 | 109 | if self.writer is not None: 110 | self.writer.flush() 111 | self.writer.close() 112 | 113 | def eval(self): 114 | self.model.eval() 115 | y_preds = [] 116 | y_trues = [] 117 | 118 | with torch.no_grad(): 119 | for idx, batch_data in enumerate(self.dev_loader, start=1): 120 | 121 | if self.model_name in ["textcnn", "rcnn", "han", "dpcnn"]: 122 | input_ids, y_true = batch_data[0], batch_data[-1] 123 | if y_true.shape !=1: 124 | y_true=y_true.squeeze(dim=-1) 125 | logits = self.model(input_ids.to(self.device)) 126 | elif self.model_name in ["berttextcnn", "bertrcnn", "berthan", "bertdpcnn"]: 127 | if len(batch_data) == 3: 128 | input_ids, attention_mask, y_true = batch_data[0], batch_data[1], batch_data[-1] 129 | if y_true.shape !=1: 130 | y_true=y_true.squeeze(dim=-1) 131 | logits = self.model(input_ids.to(self.device), attention_mask.to(self.device)) 132 | else: 133 | input_ids, y_true = batch_data[0], batch_data[-1] 134 | if y_true.shape !=1: 135 | y_true=y_true.squeeze(dim=-1) 136 | logits = self.model(input_ids.to(self.device)) 137 | else: 138 | raise ValueError("the number of batch_data is wrong!") 139 | 140 | y_true = list(y_true.cpu().numpy()) 141 | y_trues.extend(y_true) 142 | 143 | logits = logits.cpu().numpy() 144 | for item in logits: 145 | pred = np.argmax(item) 146 | y_preds.append(pred) 147 | 148 | y_preds = np.array(y_preds) 149 | y_trues = np.array(y_trues) 150 | 151 | p = precision_score(y_trues, y_preds, average="macro") 152 | r = recall_score(y_trues, y_preds, average="macro") 153 | f1 = f1_score(y_trues, y_preds, average="weighted") 154 | 155 | return p, r, f1 156 | 157 | def test(self): 158 | self.model.eval() 159 | y_preds = [] 160 | y_trues = [] 161 | 162 | with torch.no_grad(): 163 | for idx, batch_data in enumerate(self.test_loader, start=1): 164 | 165 | if self.model_name in ["textcnn", "rcnn", "han", "dpcnn"]: 166 | input_ids, y_true = batch_data[0], batch_data[-1] 167 | if y_true.shape !=1: 168 | y_true=y_true.squeeze(dim=-1) 169 | logits = self.model(input_ids.to(self.device)) 170 | elif self.model_name in ["berttextcnn", "bertrcnn", "berthan", "bertdpcnn"]: 171 | if len(batch_data) == 3: 172 | input_ids, attention_mask, y_true = batch_data[0], batch_data[1], batch_data[-1] 173 | if y_true.shape !=1: 174 | y_true=y_true.squeeze(dim=-1) 175 | logits = self.model(input_ids.to(self.device), attention_mask.to(self.device)) 176 | else: 177 | input_ids, y_true = batch_data[0], batch_data[-1] 178 | if y_true.shape !=1: 179 | y_true=y_true.squeeze(dim=-1) 180 | logits = self.model(input_ids.to(self.device)) 181 | else: 182 | raise ValueError("the number of batch_data is wrong!") 183 | 184 | y_true = list(y_true.cpu().numpy()) 185 | y_trues.extend(y_true) 186 | 187 | logits = logits.cpu().numpy() 188 | for item in logits: 189 | pred = np.argmax(item) 190 | y_preds.append(pred) 191 | 192 | y_preds = np.array(y_preds) 193 | y_trues = np.array(y_trues) 194 | 195 | p = precision_score(y_trues, y_preds, average="macro") 196 | r = recall_score(y_trues, y_preds, average="macro") 197 | f1 = f1_score(y_trues, y_preds, average="weighted") 198 | 199 | return p, r, f1 200 | 201 | def predict(self, x): 202 | self.model.eval() 203 | y_preds = [] 204 | with torch.no_grad(): 205 | for idx, batch_data in enumerate(x, start=1): 206 | if self.model_name in ["textcnn", "rcnn", "han", "dpcnn"]: 207 | input_ids = batch_data 208 | logits = self.model(input_ids.to(self.device)) 209 | elif self.model_name in ["berttextcnn", "bertrcnn", "berthan", "bertdpcnn"]: 210 | if len(batch_data) == 2: 211 | input_ids, attention_mask = batch_data[0], batch_data[1] 212 | logits = self.model(input_ids.to(self.device), attention_mask.to(self.device)) 213 | else: 214 | input_ids=batch_data 215 | logits = self.model(input_ids.to(self.device)) 216 | else: 217 | raise ValueError("the number of batch_data is wrong!") 218 | 219 | logits = logits.cpu() 220 | prob = F.softmax(logits, dim=-1) 221 | y_preds.extend(prob) 222 | 223 | y_preds = torch.stack(y_preds, dim=0).numpy() 224 | return y_preds -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: f9bc921cff24ced2183db2aea1cdfb41 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. DeepClassifier documentation master file, created by 2 | sphinx-quickstart on Fri Dec 11 18:43:18 2020. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to DeepClassifier's documentation! 7 | ========================================== 8 | DeepClassifier is a python package based on pytorch, which is easy-use and general for text classification task.🤩 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | :caption: Contents: 13 | 14 | 15 | QuickStart/index.rst 16 | Models/index.rst 17 | -------------------------------------------------------------------------------- /docs/build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:after,.clearfix:before{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-style:normal;font-weight:400;src:url(fonts/fontawesome-webfont.eot?674f50d287a8c48dc19ba404d20fe713?#iefix) format("embedded-opentype"),url(fonts/fontawesome-webfont.woff2?af7ae505a9eed503f8b8e6982036873e) format("woff2"),url(fonts/fontawesome-webfont.woff?fee66e712a8a08eef5805a46892932ad) format("woff"),url(fonts/fontawesome-webfont.ttf?b06871f281fee6b241d60582ae9369b9) format("truetype"),url(fonts/fontawesome-webfont.svg?912ec66d7572ff821749319396470bde#FontAwesome) format("svg")}.fa:before{font-family:FontAwesome;font-style:normal;font-weight:400;line-height:1}.fa:before,a .fa{text-decoration:inherit}.fa:before,a .fa,li .fa{display:inline-block}li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before,.icon-book:before{content:"\f02d"}.fa-caret-down:before,.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before,.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before,.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before,.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:Lato,proxima-nova,Helvetica Neue,Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60}.rst-versions .rst-current-version:after{clear:both;content:"";display:block}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book,.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:grey;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:1px solid #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .fa-book,.rst-versions.rst-badge .icon-book{float:none;line-height:30px}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book,.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge>.rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width:768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /docs/build/html/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /docs/build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s === 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node, addItems) { 70 | if (node.nodeType === 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && 74 | !jQuery(node.parentNode).hasClass(className) && 75 | !jQuery(node.parentNode).hasClass("nohighlight")) { 76 | var span; 77 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 78 | if (isInSVG) { 79 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 80 | } else { 81 | span = document.createElement("span"); 82 | span.className = className; 83 | } 84 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 85 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 86 | document.createTextNode(val.substr(pos + text.length)), 87 | node.nextSibling)); 88 | node.nodeValue = val.substr(0, pos); 89 | if (isInSVG) { 90 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 91 | var bbox = node.parentElement.getBBox(); 92 | rect.x.baseVal.value = bbox.x; 93 | rect.y.baseVal.value = bbox.y; 94 | rect.width.baseVal.value = bbox.width; 95 | rect.height.baseVal.value = bbox.height; 96 | rect.setAttribute('class', className); 97 | addItems.push({ 98 | "parent": node.parentNode, 99 | "target": rect}); 100 | } 101 | } 102 | } 103 | else if (!jQuery(node).is("button, select, textarea")) { 104 | jQuery.each(node.childNodes, function() { 105 | highlight(this, addItems); 106 | }); 107 | } 108 | } 109 | var addItems = []; 110 | var result = this.each(function() { 111 | highlight(this, addItems); 112 | }); 113 | for (var i = 0; i < addItems.length; ++i) { 114 | jQuery(addItems[i].parent).before(addItems[i].target); 115 | } 116 | return result; 117 | }; 118 | 119 | /* 120 | * backward compatibility for jQuery.browser 121 | * This will be supported until firefox bug is fixed. 122 | */ 123 | if (!jQuery.browser) { 124 | jQuery.uaMatch = function(ua) { 125 | ua = ua.toLowerCase(); 126 | 127 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 128 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 129 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 130 | /(msie) ([\w.]+)/.exec(ua) || 131 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 132 | []; 133 | 134 | return { 135 | browser: match[ 1 ] || "", 136 | version: match[ 2 ] || "0" 137 | }; 138 | }; 139 | jQuery.browser = {}; 140 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 141 | } 142 | 143 | /** 144 | * Small JavaScript module for the documentation. 145 | */ 146 | var Documentation = { 147 | 148 | init : function() { 149 | this.fixFirefoxAnchorBug(); 150 | this.highlightSearchWords(); 151 | this.initIndexTable(); 152 | if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) { 153 | this.initOnKeyListeners(); 154 | } 155 | }, 156 | 157 | /** 158 | * i18n support 159 | */ 160 | TRANSLATIONS : {}, 161 | PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; }, 162 | LOCALE : 'unknown', 163 | 164 | // gettext and ngettext don't access this so that the functions 165 | // can safely bound to a different name (_ = Documentation.gettext) 166 | gettext : function(string) { 167 | var translated = Documentation.TRANSLATIONS[string]; 168 | if (typeof translated === 'undefined') 169 | return string; 170 | return (typeof translated === 'string') ? translated : translated[0]; 171 | }, 172 | 173 | ngettext : function(singular, plural, n) { 174 | var translated = Documentation.TRANSLATIONS[singular]; 175 | if (typeof translated === 'undefined') 176 | return (n == 1) ? singular : plural; 177 | return translated[Documentation.PLURALEXPR(n)]; 178 | }, 179 | 180 | addTranslations : function(catalog) { 181 | for (var key in catalog.messages) 182 | this.TRANSLATIONS[key] = catalog.messages[key]; 183 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 184 | this.LOCALE = catalog.locale; 185 | }, 186 | 187 | /** 188 | * add context elements like header anchor links 189 | */ 190 | addContextElements : function() { 191 | $('div[id] > :header:first').each(function() { 192 | $('\u00B6'). 193 | attr('href', '#' + this.id). 194 | attr('title', _('Permalink to this headline')). 195 | appendTo(this); 196 | }); 197 | $('dt[id]').each(function() { 198 | $('\u00B6'). 199 | attr('href', '#' + this.id). 200 | attr('title', _('Permalink to this definition')). 201 | appendTo(this); 202 | }); 203 | }, 204 | 205 | /** 206 | * workaround a firefox stupidity 207 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 208 | */ 209 | fixFirefoxAnchorBug : function() { 210 | if (document.location.hash && $.browser.mozilla) 211 | window.setTimeout(function() { 212 | document.location.href += ''; 213 | }, 10); 214 | }, 215 | 216 | /** 217 | * highlight the search words provided in the url in the text 218 | */ 219 | highlightSearchWords : function() { 220 | var params = $.getQueryParameters(); 221 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 222 | if (terms.length) { 223 | var body = $('div.body'); 224 | if (!body.length) { 225 | body = $('body'); 226 | } 227 | window.setTimeout(function() { 228 | $.each(terms, function() { 229 | body.highlightText(this.toLowerCase(), 'highlighted'); 230 | }); 231 | }, 10); 232 | $('') 234 | .appendTo($('#searchbox')); 235 | } 236 | }, 237 | 238 | /** 239 | * init the domain index toggle buttons 240 | */ 241 | initIndexTable : function() { 242 | var togglers = $('img.toggler').click(function() { 243 | var src = $(this).attr('src'); 244 | var idnum = $(this).attr('id').substr(7); 245 | $('tr.cg-' + idnum).toggle(); 246 | if (src.substr(-9) === 'minus.png') 247 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 248 | else 249 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 250 | }).css('display', ''); 251 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 252 | togglers.click(); 253 | } 254 | }, 255 | 256 | /** 257 | * helper function to hide the search marks again 258 | */ 259 | hideSearchWords : function() { 260 | $('#searchbox .highlight-link').fadeOut(300); 261 | $('span.highlighted').removeClass('highlighted'); 262 | }, 263 | 264 | /** 265 | * make the url absolute 266 | */ 267 | makeURL : function(relativeURL) { 268 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 269 | }, 270 | 271 | /** 272 | * get the current relative url 273 | */ 274 | getCurrentURL : function() { 275 | var path = document.location.pathname; 276 | var parts = path.split(/\//); 277 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 278 | if (this === '..') 279 | parts.pop(); 280 | }); 281 | var url = parts.join('/'); 282 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 283 | }, 284 | 285 | initOnKeyListeners: function() { 286 | $(document).keydown(function(event) { 287 | var activeElementType = document.activeElement.tagName; 288 | // don't navigate when in search box, textarea, dropdown or button 289 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT' 290 | && activeElementType !== 'BUTTON' && !event.altKey && !event.ctrlKey && !event.metaKey 291 | && !event.shiftKey) { 292 | switch (event.keyCode) { 293 | case 37: // left 294 | var prevHref = $('link[rel="prev"]').prop('href'); 295 | if (prevHref) { 296 | window.location.href = prevHref; 297 | return false; 298 | } 299 | case 39: // right 300 | var nextHref = $('link[rel="next"]').prop('href'); 301 | if (nextHref) { 302 | window.location.href = nextHref; 303 | return false; 304 | } 305 | } 306 | } 307 | }); 308 | } 309 | }; 310 | 311 | // quick alias for translations 312 | _ = Documentation.gettext; 313 | 314 | $(document).ready(function() { 315 | Documentation.init(); 316 | }); 317 | -------------------------------------------------------------------------------- /docs/build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.0.1', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: true, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false 12 | }; -------------------------------------------------------------------------------- /docs/build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/file.png -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/FontAwesome.otf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bold.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bold.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bolditalic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bolditalic.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bolditalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bolditalic.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bolditalic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bolditalic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-bolditalic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-bolditalic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-italic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-italic.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-italic.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-regular.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-regular.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-regular.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Lato/lato-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Lato/lato-regular.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Light.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Light.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Light.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Light.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Thin.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Thin.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/Roboto-Slab-Thin.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/Roboto-Slab-Thin.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/RobotoSlab/roboto-slab-v7-regular.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-bold.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-normal.woff -------------------------------------------------------------------------------- /docs/build/html/_static/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /docs/build/html/_static/js/badge_only.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}}); -------------------------------------------------------------------------------- /docs/build/html/_static/js/html5shiv-printshiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /docs/build/html/_static/js/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /docs/build/html/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | !function(n){var e={};function t(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,i){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:i})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(i,o,function(e){return n[e]}.bind(null,o));return i},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){t(1),n.exports=t(3)},function(n,e,t){(function(){var e="undefined"!=typeof window?window.jQuery:t(2);n.exports.ThemeNav={navBar:null,win:null,winScroll:!1,winResize:!1,linkScroll:!1,winPosition:0,winHeight:null,docHeight:null,isRunning:!1,enable:function(n){var t=this;void 0===n&&(n=!0),t.isRunning||(t.isRunning=!0,e((function(e){t.init(e),t.reset(),t.win.on("hashchange",t.reset),n&&t.win.on("scroll",(function(){t.linkScroll||t.winScroll||(t.winScroll=!0,requestAnimationFrame((function(){t.onScroll()})))})),t.win.on("resize",(function(){t.winResize||(t.winResize=!0,requestAnimationFrame((function(){t.onResize()})))})),t.onResize()})))},enableSticky:function(){this.enable(!0)},init:function(n){n(document);var e=this;this.navBar=n("div.wy-side-scroll:first"),this.win=n(window),n(document).on("click","[data-toggle='wy-nav-top']",(function(){n("[data-toggle='wy-nav-shift']").toggleClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift")})).on("click",".wy-menu-vertical .current ul li a",(function(){var t=n(this);n("[data-toggle='wy-nav-shift']").removeClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift"),e.toggleCurrent(t),e.hashChange()})).on("click","[data-toggle='rst-current-version']",(function(){n("[data-toggle='rst-versions']").toggleClass("shift-up")})),n("table.docutils:not(.field-list,.footnote,.citation)").wrap("
"),n("table.docutils.footnote").wrap("
"),n("table.docutils.citation").wrap("
"),n(".wy-menu-vertical ul").not(".simple").siblings("a").each((function(){var t=n(this);expand=n(''),expand.on("click",(function(n){return e.toggleCurrent(t),n.stopPropagation(),!1})),t.prepend(expand)}))},reset:function(){var n=encodeURI(window.location.hash)||"#";try{var e=$(".wy-menu-vertical"),t=e.find('[href="'+n+'"]');if(0===t.length){var i=$('.document [id="'+n.substring(1)+'"]').closest("div.section");0===(t=e.find('[href="#'+i.attr("id")+'"]')).length&&(t=e.find('[href="#"]'))}t.length>0&&($(".wy-menu-vertical .current").removeClass("current"),t.addClass("current"),t.closest("li.toctree-l1").addClass("current"),t.closest("li.toctree-l1").parent().addClass("current"),t.closest("li.toctree-l1").addClass("current"),t.closest("li.toctree-l2").addClass("current"),t.closest("li.toctree-l3").addClass("current"),t.closest("li.toctree-l4").addClass("current"),t.closest("li.toctree-l5").addClass("current"),t[0].scrollIntoView())}catch(n){console.log("Error expanding nav for anchor",n)}},onScroll:function(){this.winScroll=!1;var n=this.win.scrollTop(),e=n+this.winHeight,t=this.navBar.scrollTop()+(n-this.winPosition);n<0||e>this.docHeight||(this.navBar.scrollTop(t),this.winPosition=n)},onResize:function(){this.winResize=!1,this.winHeight=this.win.height(),this.docHeight=$(document).height()},hashChange:function(){this.linkScroll=!0,this.win.one("hashchange",(function(){this.linkScroll=!1}))},toggleCurrent:function(n){var e=n.closest("li");e.siblings("li.current").removeClass("current"),e.siblings().find("li.current").removeClass("current"),e.find("> ul li.current").removeClass("current"),e.toggleClass("current")}},"undefined"!=typeof window&&(window.SphinxRtdTheme={Navigation:n.exports.ThemeNav,StickyNav:n.exports.ThemeNav}),function(){for(var n=0,e=["ms","moz","webkit","o"],t=0;t0 62 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 63 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 64 | var s_v = "^(" + C + ")?" + v; // vowel in stem 65 | 66 | this.stemWord = function (w) { 67 | var stem; 68 | var suffix; 69 | var firstch; 70 | var origword = w; 71 | 72 | if (w.length < 3) 73 | return w; 74 | 75 | var re; 76 | var re2; 77 | var re3; 78 | var re4; 79 | 80 | firstch = w.substr(0,1); 81 | if (firstch == "y") 82 | w = firstch.toUpperCase() + w.substr(1); 83 | 84 | // Step 1a 85 | re = /^(.+?)(ss|i)es$/; 86 | re2 = /^(.+?)([^s])s$/; 87 | 88 | if (re.test(w)) 89 | w = w.replace(re,"$1$2"); 90 | else if (re2.test(w)) 91 | w = w.replace(re2,"$1$2"); 92 | 93 | // Step 1b 94 | re = /^(.+?)eed$/; 95 | re2 = /^(.+?)(ed|ing)$/; 96 | if (re.test(w)) { 97 | var fp = re.exec(w); 98 | re = new RegExp(mgr0); 99 | if (re.test(fp[1])) { 100 | re = /.$/; 101 | w = w.replace(re,""); 102 | } 103 | } 104 | else if (re2.test(w)) { 105 | var fp = re2.exec(w); 106 | stem = fp[1]; 107 | re2 = new RegExp(s_v); 108 | if (re2.test(stem)) { 109 | w = stem; 110 | re2 = /(at|bl|iz)$/; 111 | re3 = new RegExp("([^aeiouylsz])\\1$"); 112 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 113 | if (re2.test(w)) 114 | w = w + "e"; 115 | else if (re3.test(w)) { 116 | re = /.$/; 117 | w = w.replace(re,""); 118 | } 119 | else if (re4.test(w)) 120 | w = w + "e"; 121 | } 122 | } 123 | 124 | // Step 1c 125 | re = /^(.+?)y$/; 126 | if (re.test(w)) { 127 | var fp = re.exec(w); 128 | stem = fp[1]; 129 | re = new RegExp(s_v); 130 | if (re.test(stem)) 131 | w = stem + "i"; 132 | } 133 | 134 | // Step 2 135 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 136 | if (re.test(w)) { 137 | var fp = re.exec(w); 138 | stem = fp[1]; 139 | suffix = fp[2]; 140 | re = new RegExp(mgr0); 141 | if (re.test(stem)) 142 | w = stem + step2list[suffix]; 143 | } 144 | 145 | // Step 3 146 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 147 | if (re.test(w)) { 148 | var fp = re.exec(w); 149 | stem = fp[1]; 150 | suffix = fp[2]; 151 | re = new RegExp(mgr0); 152 | if (re.test(stem)) 153 | w = stem + step3list[suffix]; 154 | } 155 | 156 | // Step 4 157 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 158 | re2 = /^(.+?)(s|t)(ion)$/; 159 | if (re.test(w)) { 160 | var fp = re.exec(w); 161 | stem = fp[1]; 162 | re = new RegExp(mgr1); 163 | if (re.test(stem)) 164 | w = stem; 165 | } 166 | else if (re2.test(w)) { 167 | var fp = re2.exec(w); 168 | stem = fp[1] + fp[2]; 169 | re2 = new RegExp(mgr1); 170 | if (re2.test(stem)) 171 | w = stem; 172 | } 173 | 174 | // Step 5 175 | re = /^(.+?)e$/; 176 | if (re.test(w)) { 177 | var fp = re.exec(w); 178 | stem = fp[1]; 179 | re = new RegExp(mgr1); 180 | re2 = new RegExp(meq1); 181 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 182 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 183 | w = stem; 184 | } 185 | re = /ll$/; 186 | re2 = new RegExp(mgr1); 187 | if (re.test(w) && re2.test(w)) { 188 | re = /.$/; 189 | w = w.replace(re,""); 190 | } 191 | 192 | // and turn initial Y back to y 193 | if (firstch == "y") 194 | w = firstch.toLowerCase() + w.substr(1); 195 | return w; 196 | } 197 | } 198 | 199 | 200 | 201 | 202 | 203 | var splitChars = (function() { 204 | var result = {}; 205 | var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648, 206 | 1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702, 207 | 2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971, 208 | 2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345, 209 | 3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761, 210 | 3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823, 211 | 4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125, 212 | 8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695, 213 | 11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587, 214 | 43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141]; 215 | var i, j, start, end; 216 | for (i = 0; i < singles.length; i++) { 217 | result[singles[i]] = true; 218 | } 219 | var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709], 220 | [722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161], 221 | [1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568], 222 | [1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807], 223 | [1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047], 224 | [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383], 225 | [2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450], 226 | [2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547], 227 | [2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673], 228 | [2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820], 229 | [2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946], 230 | [2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023], 231 | [3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173], 232 | [3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332], 233 | [3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481], 234 | [3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718], 235 | [3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791], 236 | [3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095], 237 | [4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205], 238 | [4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687], 239 | [4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968], 240 | [4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869], 241 | [5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102], 242 | [6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271], 243 | [6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592], 244 | [6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822], 245 | [6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167], 246 | [7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959], 247 | [7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143], 248 | [8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318], 249 | [8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483], 250 | [8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101], 251 | [10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567], 252 | [11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292], 253 | [12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444], 254 | [12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783], 255 | [12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311], 256 | [19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511], 257 | [42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774], 258 | [42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071], 259 | [43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263], 260 | [43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519], 261 | [43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647], 262 | [43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967], 263 | [44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295], 264 | [57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274], 265 | [64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007], 266 | [65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381], 267 | [65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]]; 268 | for (i = 0; i < ranges.length; i++) { 269 | start = ranges[i][0]; 270 | end = ranges[i][1]; 271 | for (j = start; j <= end; j++) { 272 | result[j] = true; 273 | } 274 | } 275 | return result; 276 | })(); 277 | 278 | function splitQuery(query) { 279 | var result = []; 280 | var start = -1; 281 | for (var i = 0; i < query.length; i++) { 282 | if (splitChars[query.charCodeAt(i)]) { 283 | if (start !== -1) { 284 | result.push(query.slice(start, i)); 285 | start = -1; 286 | } 287 | } else if (start === -1) { 288 | start = i; 289 | } 290 | } 291 | if (start !== -1) { 292 | result.push(query.slice(start)); 293 | } 294 | return result; 295 | } 296 | 297 | 298 | -------------------------------------------------------------------------------- /docs/build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #f8f8f8; } 3 | .highlight .c { color: #408080; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #008000; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #408080; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #408080; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #BC7A00 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #408080; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #408080; font-style: italic } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #888888 } /* Generic.Output */ 19 | .highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #008000; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #008000 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #B00040 } /* Keyword.Type */ 29 | .highlight .m { color: #666666 } /* Literal.Number */ 30 | .highlight .s { color: #BA2121 } /* Literal.String */ 31 | .highlight .na { color: #7D9029 } /* Name.Attribute */ 32 | .highlight .nb { color: #008000 } /* Name.Builtin */ 33 | .highlight .nc { color: #0000FF; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #880000 } /* Name.Constant */ 35 | .highlight .nd { color: #AA22FF } /* Name.Decorator */ 36 | .highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ 38 | .highlight .nf { color: #0000FF } /* Name.Function */ 39 | .highlight .nl { color: #A0A000 } /* Name.Label */ 40 | .highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #19177C } /* Name.Variable */ 43 | .highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #666666 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #666666 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #666666 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #666666 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #666666 } /* Literal.Number.Oct */ 50 | .highlight .sa { color: #BA2121 } /* Literal.String.Affix */ 51 | .highlight .sb { color: #BA2121 } /* Literal.String.Backtick */ 52 | .highlight .sc { color: #BA2121 } /* Literal.String.Char */ 53 | .highlight .dl { color: #BA2121 } /* Literal.String.Delimiter */ 54 | .highlight .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */ 55 | .highlight .s2 { color: #BA2121 } /* Literal.String.Double */ 56 | .highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ 57 | .highlight .sh { color: #BA2121 } /* Literal.String.Heredoc */ 58 | .highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ 59 | .highlight .sx { color: #008000 } /* Literal.String.Other */ 60 | .highlight .sr { color: #BB6688 } /* Literal.String.Regex */ 61 | .highlight .s1 { color: #BA2121 } /* Literal.String.Single */ 62 | .highlight .ss { color: #19177C } /* Literal.String.Symbol */ 63 | .highlight .bp { color: #008000 } /* Name.Builtin.Pseudo */ 64 | .highlight .fm { color: #0000FF } /* Name.Function.Magic */ 65 | .highlight .vc { color: #19177C } /* Name.Variable.Class */ 66 | .highlight .vg { color: #19177C } /* Name.Variable.Global */ 67 | .highlight .vi { color: #19177C } /* Name.Variable.Instance */ 68 | .highlight .vm { color: #19177C } /* Name.Variable.Magic */ 69 | .highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/build/html/_static/underscore.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.3.1 2 | // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= 11 | b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | -------------------------------------------------------------------------------- /docs/build/html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Index — DeepClassifier 0.0.1 documentation 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
45 | 46 | 95 | 96 |
97 | 98 | 99 | 105 | 106 | 107 |
108 | 109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
128 | 129 |
    130 | 131 |
  • »
  • 132 | 133 |
  • Index
  • 134 | 135 | 136 |
  • 137 | 138 | 139 | 140 |
  • 141 | 142 |
143 | 144 | 145 |
146 |
147 |
148 |
149 | 150 | 151 |

Index

152 | 153 |
154 | 155 |
156 | 157 | 158 |
159 | 160 |
161 |
162 | 163 | 164 |
165 | 166 |
167 |

168 | 169 | © Copyright 2020, Zichao Li 170 | 171 |

172 |
173 | 174 | 175 | 176 | Built with Sphinx using a 177 | 178 | theme 179 | 180 | provided by Read the Docs. 181 | 182 |
183 | 184 |
185 |
186 | 187 |
188 | 189 |
190 | 191 | 192 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | -------------------------------------------------------------------------------- /docs/build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Welcome to DeepClassifier’s documentation! — DeepClassifier 0.0.1 documentation 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 | 47 | 96 | 97 |
98 | 99 | 100 | 106 | 107 | 108 |
109 | 110 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |
129 | 130 |
    131 | 132 |
  • »
  • 133 | 134 |
  • Welcome to DeepClassifier’s documentation!
  • 135 | 136 | 137 |
  • 138 | 139 | 140 | View page source 141 | 142 | 143 |
  • 144 | 145 |
146 | 147 | 148 |
149 |
150 |
151 |
152 | 153 |
154 |

Welcome to DeepClassifier’s documentation!

155 |

DeepClassifier is a python package based on pytorch, which is easy-use and general for text classification task.🤩

156 | 173 |
174 | 175 | 176 |
177 | 178 |
179 |
180 | 181 | 187 | 188 | 189 |
190 | 191 |
192 |

193 | 194 | © Copyright 2020, Zichao Li 195 | 196 |

197 |
198 | 199 | 200 | 201 | Built with Sphinx using a 202 | 203 | theme 204 | 205 | provided by Read the Docs. 206 | 207 |
208 | 209 |
210 |
211 | 212 |
213 | 214 |
215 | 216 | 217 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /docs/build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/docs/build/html/objects.inv -------------------------------------------------------------------------------- /docs/build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Search — DeepClassifier 0.0.1 documentation 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
47 | 48 | 97 | 98 |
99 | 100 | 101 | 107 | 108 | 109 |
110 | 111 |
112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 |
130 | 131 |
    132 | 133 |
  • »
  • 134 | 135 |
  • Search
  • 136 | 137 | 138 |
  • 139 | 140 | 141 | 142 |
  • 143 | 144 |
145 | 146 | 147 |
148 |
149 |
150 |
151 | 152 | 159 | 160 | 161 |
162 | 163 |
164 | 165 |
166 | 167 |
168 |
169 | 170 | 171 |
172 | 173 |
174 |

175 | 176 | © Copyright 2020, Zichao Li 177 | 178 |

179 |
180 | 181 | 182 | 183 | Built with Sphinx using a 184 | 185 | theme 186 | 187 | provided by Read the Docs. 188 | 189 |
190 | 191 |
192 |
193 | 194 |
195 | 196 |
197 | 198 | 199 | 204 | 205 | 206 | 207 | 208 | 209 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | -------------------------------------------------------------------------------- /docs/build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["Models/01_TextCNN","Models/02_RCNN","Models/03_DPCNN","Models/04_HAN","Models/05_BertTextCNN","Models/06_BertRCNN","Models/07_BertDPCNN","Models/08_BertHAN","Models/index","QuickStart/index","index"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":3,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":1,sphinx:56},filenames:["Models/01_TextCNN.rst","Models/02_RCNN.rst","Models/03_DPCNN.rst","Models/04_HAN.rst","Models/05_BertTextCNN.rst","Models/06_BertRCNN.rst","Models/07_BertDPCNN.rst","Models/08_BertHAN.rst","Models/index.rst","QuickStart/index.rst","index.rst"],objects:{},objnames:{},objtypes:{},terms:{"100":0,"1181":0,"1746":0,"1751":0,"2014":0,"3115":0,"\u4ee5\u53ca":[],"\u5165\u95e8\u7bc7":[],"\u5305\u542b\u6570\u636e\u79d1\u5b66\u7684\u57fa\u7840\u5de5\u5177":[],"\u57fa\u672c\u7684\u6570\u636e\u79d1\u5b66\u5305":[],"\u5982":[],"\u753b\u56fe\u5305":[],"\u8fd9\u4e00\u90e8\u5206\u4e3b\u8981\u4ecb\u7ecd\u6570\u636e\u79d1\u5b66\u7684\u5165\u95e8\u5185\u5bb9":[],"class":0,"default":[],The:9,__init__:[],aclweb:0,address:0,after:0,antholog:0,associ:0,author:0,base:10,batch_siz:0,below:9,bertdpcnn:[8,10],berthan:[8,10],bertrcnn:[8,10],berttextcnn:[8,10],booktitl:0,classif:[0,10],cnn:0,command:9,comput:0,confer:0,content:10,conv:0,convolut:0,d14:0,deepclassifi:[8,9],def:[],defkrsaef:[],dim:0,dksjjeksnec:[],doha:0,doi:0,dpcnn:[8,10],dropout_r:0,drouput:0,dxwaheslh1:[],easi:10,embed:0,embedding_dim:0,embedding_matrix:0,emnlp:0,empir:0,fals:0,filter:0,forward:0,gener:10,glove:0,gradient:0,han:[8,10],how:9,http:0,index:[],initi:0,inproceed:0,input_id:0,instal:9,jdeiwjiaa:[],jupyt:[],kernel:0,kernel_s:0,kim:0,label:0,languag:0,length:0,let:9,librari:[],linguist:0,linux:[],list:0,load:[],look:0,matplotlib:[],max:0,maxdepth:[],method:0,model:10,modul:[],month:0,natur:0,network:0,neural:0,none:0,num:0,num_class:0,num_filt:0,num_lay:0,number:0,numpi:[],oct:0,org:0,packag:10,pad:0,page:0,param:[],paramet:[0,1,2,3,4,5,6,7],pip:9,pramamt:8,pre:0,pretrain:0,proceed:0,process:0,publish:0,python:10,pytorch:10,qatar:0,quickstart:10,rate:0,rcnn:[8,10],recommand:0,refer:0,requires_grad:0,rsbdae:[],search:[],self:0,sentenc:0,seq_length:0,sequenc:0,shape:0,show:[0,1,2,3,4,5,6,7,8,9],size:0,start:9,stride:0,strongli:0,tabl:0,task:10,text:10,textcnn:[8,10],titl:0,toctre:[],train:0,updat:0,url:0,use:[0,10],vocab_s:0,vocabulari:0,wai:[],whether:0,which:10,www:0,year:0,yoon:0,you:[0,1,2,3,4,5,6,7,8,9]},titles:["1. deepclassifier.models.TextCNN","2. deepclassifier.models.RCNN","3. deepclassifier.models.DPCNN","4. deepclassifier.models.HAN","5. deepclassifier.models.BertTextCNN","6. deepclassifier.models.BertRCNN","7. deepclassifier.models.BertDPCNN","8. deepclassifier.models.BertHAN","Models","QuickStart","Welcome to DeepClassifier\u2019s documentation!"],titleterms:{"\u5165\u95e8\u7bc7":[],bertdpcnn:6,berthan:7,bertrcnn:5,berttextcnn:4,deepclassifi:[0,1,2,3,4,5,6,7,10],document:10,dpcnn:2,han:3,indic:[],initi:[],model:[0,1,2,3,4,5,6,7,8],quickstart:9,rcnn:1,tabl:[],textcnn:0,welcom:10}}) -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/Models/01_TextCNN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.TextCNN 2 | ========== 3 | 4 | I will show you that the parameters of TextCNN model. 5 | 6 | .. code-block:: python 7 | 8 | 9 | class TextCNN(self,embedding_dim,dropout_rate, 10 | num_class,vocab_size=0,seq_length=0, 11 | num_layers=3,kernel_sizes=[3, 4, 5], 12 | strides=[1, 1, 1],paddings=[0, 0, 0], 13 | num_filters=[100, 100, 100], 14 | embedding_matrix=None, 15 | requires_grads=False): 16 | 17 | Initialize TextCNN model. 18 | 19 | 20 | .. important:: We strongly recommand you to use pre-trained embedding such as GloVe. 21 | 22 | Parameters: 23 | - embedding_dim: embedding dim 24 | - dropout_rate: drouput rate 25 | - num_class: the number of label 26 | - vocab_size: vocabulary size 27 | - seq_length: max length of sequence after padding 28 | - num_layers: the number of cnn 29 | - kernel_sizes: list of conv kernel size 30 | - strides: list of conv strides 31 | - paddings: list of padding 32 | - num_filters: list of num filters 33 | - embedding_matrix: pretrained embedding look-up table,shape is:[vocab_size,embedding_dim] 34 | - requires_grads: whether to update gradient of embedding in training 35 | 36 | .. code-block:: python 37 | 38 | forward(self, input_ids) 39 | Parameters: 40 | - input_ids: [batch_size,seq_length] 41 | 42 | **Reference** 43 | 44 | .. code-block:: 45 | 46 | @inproceedings{kim-2014-convolutional, 47 | title = "Convolutional Neural Networks for Sentence Classification", 48 | author = "Kim, Yoon", 49 | booktitle = "Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing ({EMNLP})", 50 | month = oct, 51 | year = "2014", 52 | address = "Doha, Qatar", 53 | publisher = "Association for Computational Linguistics", 54 | url = "https://www.aclweb.org/anthology/D14-1181", 55 | doi = "10.3115/v1/D14-1181", 56 | pages = "1746--1751", 57 | } 58 | 59 | -------------------------------------------------------------------------------- /docs/source/Models/02_RCNN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.RCNN 2 | ========== 3 | 4 | I will show you that the parameters of RCNN model. 5 | -------------------------------------------------------------------------------- /docs/source/Models/03_DPCNN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.DPCNN 2 | ========== 3 | 4 | I will show you that the parameters of DPCNN model. 5 | 6 | -------------------------------------------------------------------------------- /docs/source/Models/04_HAN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.HAN 2 | ========== 3 | 4 | I will show you that the parameters of HAN model. 5 | -------------------------------------------------------------------------------- /docs/source/Models/05_BertTextCNN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.BertTextCNN 2 | ========== 3 | 4 | I will show you that the parameters of BertTextCNN model. 5 | 6 | -------------------------------------------------------------------------------- /docs/source/Models/06_BertRCNN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.BertRCNN 2 | ========== 3 | 4 | I will show you that the parameters of BertRCNN model. 5 | 6 | -------------------------------------------------------------------------------- /docs/source/Models/07_BertDPCNN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.BertDPCNN 2 | ========== 3 | 4 | I will show you that the parameters of BertDPCNN model. 5 | 6 | -------------------------------------------------------------------------------- /docs/source/Models/08_BertHAN.rst: -------------------------------------------------------------------------------- 1 | deepclassifier.models.BertHAN 2 | ========== 3 | 4 | I will show you that the parameters of BertHAN model. 5 | 6 | -------------------------------------------------------------------------------- /docs/source/Models/index.rst: -------------------------------------------------------------------------------- 1 | Models 2 | ========== 3 | 4 | I will show you that the pramamters of models.🤩 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | :numbered: 2 9 | 10 | 01_TextCNN 11 | 02_RCNN 12 | 03_DPCNN 13 | 04_HAN 14 | 05_BertTextCNN 15 | 06_BertRCNN 16 | 07_BertDPCNN 17 | 08_BertHAN 18 | -------------------------------------------------------------------------------- /docs/source/QuickStart/index.rst: -------------------------------------------------------------------------------- 1 | QuickStart 2 | ========== 3 | 4 | I will show you that how to install DeepClassifier.🤩 5 | 6 | **installation** 7 | 8 | The command of installation is below:👇 9 | 10 | .. code-block:: sh 11 | 12 | pip install -u deepclassifier 13 | 14 | 15 | So let's start!🥳 -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | # import os 14 | # import sys 15 | # sys.path.insert(0, os.path.abspath('.')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'DeepClassifier' 21 | copyright = '2020, Zichao Li' 22 | author = 'Zichao Li' 23 | 24 | # The full version, including alpha/beta/rc tags 25 | release = '0.0.1' 26 | 27 | 28 | # -- General configuration --------------------------------------------------- 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = [ 34 | ] 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ['_templates'] 38 | 39 | # List of patterns, relative to source directory, that match files and 40 | # directories to ignore when looking for source files. 41 | # This pattern also affects html_static_path and html_extra_path. 42 | exclude_patterns = [] 43 | 44 | 45 | # -- Options for HTML output ------------------------------------------------- 46 | 47 | # The theme to use for HTML and HTML Help pages. See the documentation for 48 | # a list of builtin themes. 49 | # 50 | html_theme = 'sphinx_rtd_theme' 51 | 52 | # Add any paths that contain custom static files (such as style sheets) here, 53 | # relative to this directory. They are copied after the builtin static files, 54 | # so a file named "default.css" will overwrite the builtin "default.css". 55 | html_static_path = ['_static'] 56 | 57 | from recommonmark.parser import CommonMarkParser 58 | source_parsers = { 59 | '.md': CommonMarkParser, 60 | } 61 | source_suffix = ['.rst', '.md'] 62 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. DeepClassifier documentation master file, created by 2 | sphinx-quickstart on Fri Dec 11 18:43:18 2020. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to DeepClassifier's documentation! 7 | ========================================== 8 | DeepClassifier is a python package based on pytorch, which is easy-use and general for text classification task.🤩 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | :caption: Contents: 13 | 14 | 15 | QuickStart/index.rst 16 | Models/index.rst 17 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | In this part, I will show you how to use DeepClassifier to carry text classification task.🥰 3 | 4 | ## Dataset 5 | **kaggle dataset:** [sentiment-analysis-on-movie-reviews](https://www.kaggle.com/c/sentiment-analysis-on-movie-reviews) 6 | 7 | **Pretrained embedding:** GloVe [download](https://apache-mxnet.s3.cn-north-1.amazonaws.com.cn/gluon/embeddings/glove/glove.6B.zip) 8 | 9 | **BERT pretrained weights:** [download](https://huggingface.co/bert-base-uncased) 10 | 11 | ## EDA 12 | 13 | Before processing the data,you can do data analysis: 14 | 15 | ![image](https://github.com/codewithzichao/DeepClassifier/blob/master/examples/len.png) 16 | 17 | ![image](https://github.com/codewithzichao/DeepClassifier/blob/master/examples/label.png) 18 | 19 | ## Preprocessing 20 | 21 | This step is mainly divided into two steps: 22 | 23 | * load_pretrained_embedding 24 | * texts_convert_to_ids 25 | 26 | 27 | Details can be seen **proprecessing.py**. 28 | 29 | ## Training 30 | The core code is below:🥰 31 | 32 | **TextCNN** 33 | 34 | Details can be seen **example_textcnn.py**. 35 | 36 | ```python 37 | from deepclassifier.models import TextCNN 38 | from deepclassifier.trainers import Trainer 39 | # 定义模型 40 | my_model = TextCNN(embedding_dim=embedding_matrix.shape[1], dropout_rate=0.2, num_class=5, 41 | embedding_matrix=embedding_matrix, requires_grads=False) 42 | optimizer = optim.Adam(my_model.parameters()) 43 | loss_fn = nn.CrossEntropyLoss() 44 | save_path = "best.ckpt" 45 | 46 | writer = SummaryWriter("logfie/1") 47 | my_trainer = Trainer(model_name="textcnn", model=my_model, train_loader=train_loader, dev_loader=dev_loader, 48 | test_loader=None, optimizer=optimizer, loss_fn=loss_fn, save_path=save_path, epochs=100, 49 | writer=writer, max_norm=0.25, eval_step_interval=10, device='cpu') 50 | 51 | # 训练 52 | my_trainer.train() 53 | # 测试 54 | p, r, f1 = my_trainer.test() 55 | print(p, r, f1) 56 | # 打印在验证集上最好的f1值 57 | print(my_trainer.best_f1) 58 | 59 | # 预测 60 | pred_label = my_trainer.predict(pred_data) 61 | print(pred_label.shape) 62 | ``` 63 | 64 | **BertTextCNN** 65 | 66 | Details can be seen **example_berttextcnn.py**. 67 | ```python 68 | from deepclassifier.models import BertTextCNN 69 | from deepclassifier.trainers import Trainer 70 | # 定义模型 71 | my_model = BertTextCNN(embedding_dim=768, dropout_rate=0.2, num_class=5, 72 | bert_path=bert_path) 73 | 74 | optimizer = optim.Adam(my_model.parameters()) 75 | loss_fn = nn.CrossEntropyLoss() 76 | save_path = "best.ckpt" 77 | 78 | writer = SummaryWriter("logfie/1") 79 | my_trainer = Trainer(model_name="berttextcnn", model=my_model, train_loader=train_loader, dev_loader=dev_loader, 80 | test_loader=None, optimizer=optimizer, loss_fn=loss_fn, save_path=save_path, epochs=100, 81 | writer=writer, max_norm=0.25, eval_step_interval=10, device='cpu') 82 | 83 | # 训练 84 | my_trainer.train() 85 | # 测试 86 | p, r, f1 = my_trainer.test() 87 | print(p, r, f1) 88 | # 打印在验证集上最好的f1值 89 | print(my_trainer.best_f1) 90 | 91 | # 预测 92 | pred_label = my_trainer.predict(pred_data) 93 | print(pred_label.shape) 94 | 95 | ``` 96 | 97 | if you want to run **example_textcnn.py** or **example_berttextcnn.py**, please **download datasets and glove, and replace the data dir.** Have fun!🥰 98 | 99 | > Your file dir must be like that:👇 100 | ```shell 101 | 102 | ├── bert-base-uncased 103 | │   ├── config.json 104 | │   ├── pytorch_model.bin 105 | │   ├── rust_model.ot 106 | │   ├── tf_model.h5 107 | │   ├── tokenizer.json 108 | │   ├── tokenizer_config.json 109 | │   └── vocab.txt 110 | ├── example_berttextcnn.py 111 | ├── example_textcnn.py 112 | ├── glove 113 | │   ├── glove.6B.100d.txt 114 | │   ├── glove.6B.200d.txt 115 | │   ├── glove.6B.300d.txt 116 | │   ├── glove.6B.300d.txt.pt 117 | │   ├── glove.6B.50d.txt 118 | │   └── glove.6B.zip 119 | ├── preprocessing.py 120 | └── sentiment-analysis-on-movie-reviews 121 | ├── sampleSubmission.csv 122 | ├── test.tsv 123 | └── train.tsv 124 | ``` 125 | 126 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/examples/__init__.py -------------------------------------------------------------------------------- /examples/example_berttextcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import numpy as np 12 | import pandas as pd 13 | import torch 14 | import torch.nn as nn 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import BertTextCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | from transformers import BertTokenizer 21 | from sklearn.model_selection import train_test_split 22 | 23 | # 数据路径 24 | base_path = os.getcwd() 25 | train_data_path = base_path + "/sentiment-analysis-on-movie-reviews/train.tsv" 26 | test_data_path = base_path + "/sentiment-analysis-on-movie-reviews/test.tsv" 27 | bert_path = base_path + "/bert-base-uncased" 28 | 29 | # 获取数据 30 | train_data_df = pd.read_csv(train_data_path, sep="\t") 31 | train_data_df, dev_data_df = train_test_split(train_data_df, test_size=0.2) 32 | test_data_df = pd.read_csv(test_data_path, sep="\t") 33 | 34 | train_data = train_data_df.iloc[:, -2].values 35 | train_label = train_data_df.iloc[:, -1].values 36 | dev_data = dev_data_df.iloc[:, -2].values 37 | dev_label = dev_data_df.iloc[:, -1].values 38 | test_data = test_data_df.iloc[:, -1].values 39 | 40 | 41 | # 产生batch data 42 | class my_dataset(Dataset): 43 | def __init__(self, data, label, max_length, tokenizer=None): 44 | self.data = data 45 | self.label = label 46 | self.max_length = max_length 47 | self.tokenizer = tokenizer 48 | 49 | def __len__(self): 50 | return len(self.data) 51 | 52 | def __getitem__(self, item): 53 | item_data = self.data[item] 54 | item_label = [self.label[item]] 55 | 56 | item_data = item_data.strip().split() 57 | c = ["[CLS]"] + item_data + ["SEP"] 58 | input_ids = self.tokenizer.convert_tokens_to_ids(c) 59 | if len(input_ids) >= self.max_length: 60 | input_ids = input_ids[:self.max_length] 61 | attention_mask = [1.0] * len(input_ids) 62 | extra = self.max_length - len(input_ids) 63 | if extra > 0: 64 | input_ids += [0] * extra 65 | attention_mask += [0.0] * extra 66 | 67 | return torch.LongTensor(input_ids), torch.FloatTensor(attention_mask), torch.LongTensor(item_label) 68 | 69 | 70 | class my_dataset1(Dataset): 71 | def __init__(self, data, max_length, tokenizer=None): 72 | self.data = data 73 | 74 | self.max_length = max_length 75 | self.tokenizer = tokenizer 76 | 77 | def __len__(self): 78 | return len(self.data) 79 | 80 | def __getitem__(self, item): 81 | item_data = self.data[item] 82 | 83 | item_data = item_data.strip().split() 84 | c = ["[CLS]"] + item_data + ["SEP"] 85 | input_ids = self.tokenizer.convert_tokens_to_ids(c) 86 | if len(input_ids) >= self.max_length: 87 | input_ids = input_ids[:self.max_length] 88 | attention_mask = [1.0] * len(input_ids) 89 | extra = self.max_length - len(input_ids) 90 | if extra > 0: 91 | input_ids += [0] * extra 92 | attention_mask += [0.0] * extra 93 | 94 | return torch.LongTensor(input_ids), torch.FloatTensor(attention_mask) 95 | 96 | 97 | tokenizer = BertTokenizer(vocab_file=bert_path+"/vocab.txt") 98 | # 训练集 99 | batch_size = 20 100 | my_train_data = my_dataset(train_data, train_label, 200, tokenizer) 101 | train_loader = DataLoader(my_train_data, batch_size=batch_size, shuffle=True, drop_last=True) 102 | # 验证集 103 | my_dev_data = my_dataset(dev_data, dev_label, 200, tokenizer) 104 | dev_loader = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True, drop_last=True) 105 | # 测试集 106 | pred_data = my_dataset1(test_data, 200, tokenizer) 107 | pred_data = DataLoader(pred_data, batch_size=1) 108 | 109 | # 定义模型 110 | my_model = BertTextCNN(embedding_dim=768, dropout_rate=0.2, num_class=5, 111 | bert_path=bert_path) 112 | 113 | optimizer = optim.Adam(my_model.parameters()) 114 | loss_fn = nn.CrossEntropyLoss() 115 | save_path = "best.ckpt" 116 | 117 | writer = SummaryWriter("logfie/1") 118 | my_trainer = Trainer(model_name="berttextcnn", model=my_model, train_loader=train_loader, dev_loader=dev_loader, 119 | test_loader=None, optimizer=optimizer, loss_fn=loss_fn, save_path=save_path, epochs=100, 120 | writer=writer, max_norm=0.25, eval_step_interval=10, device='cpu') 121 | 122 | # 训练 123 | my_trainer.train() 124 | # 测试 125 | p, r, f1 = my_trainer.test() 126 | print(p, r, f1) 127 | # 打印在验证集上最好的f1值 128 | print(my_trainer.best_f1) 129 | 130 | # 预测 131 | prd_label = my_trainer.predict(pred_data) 132 | print(prd_label.shape) 133 | -------------------------------------------------------------------------------- /examples/example_textcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import numpy as np 12 | import pandas as pd 13 | import torch 14 | import torch.nn as nn 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import TextCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | from preprocessing import load_pretrained_embedding, texts_convert_to_ids,pad_sequences 21 | from sklearn.model_selection import train_test_split 22 | 23 | # 数据路径 24 | base_path = os.getcwd() 25 | train_data_path = base_path + "/sentiment-analysis-on-movie-reviews/train.tsv" 26 | test_data_path = base_path + "/sentiment-analysis-on-movie-reviews/test.tsv" 27 | 28 | # 获取数据 29 | train_data_df = pd.read_csv(train_data_path, sep="\t") 30 | train_data_df, dev_data_df = train_test_split(train_data_df, test_size=0.2) 31 | test_data_df = pd.read_csv(test_data_path, sep="\t") 32 | 33 | train_data = train_data_df.iloc[:, -2].values 34 | train_label = train_data_df.iloc[:, -1].values 35 | dev_data = dev_data_df.iloc[:, -2].values 36 | dev_label = dev_data_df.iloc[:, -1].values 37 | test_data = test_data_df.iloc[:, -1].values 38 | 39 | # 获取词典与词向量 40 | pretrained_embedding_file_path = base_path+"/glove/glove.6B.50d.txt" 41 | word2idx, embedding_matrix = load_pretrained_embedding(pretrained_embedding_file_path=pretrained_embedding_file_path) 42 | 43 | # 文本向量化 44 | train_data = texts_convert_to_ids(train_data, word2idx) 45 | dev_data = texts_convert_to_ids(dev_data, word2idx) 46 | test_data = texts_convert_to_ids(test_data, word2idx) 47 | 48 | train_data=torch.from_numpy(pad_sequences(train_data)) 49 | dev_data=torch.from_numpy(pad_sequences(dev_data)) 50 | test_data=torch.from_numpy(pad_sequences(test_data)) 51 | 52 | # 产生batch data 53 | class my_dataset(Dataset): 54 | def __init__(self, data, label): 55 | self.data = data 56 | self.label = label 57 | 58 | def __len__(self): 59 | return len(self.data) 60 | 61 | def __getitem__(self, item): 62 | item_data = self.data[item] 63 | item_label = self.label[item] 64 | 65 | return item_data, item_label 66 | 67 | 68 | class my_dataset1(Dataset): 69 | def __init__(self, data): 70 | self.data = data 71 | 72 | def __len__(self): 73 | return len(self.data) 74 | 75 | def __getitem__(self, item): 76 | item_data = self.data[item] 77 | 78 | return item_data 79 | 80 | 81 | # 训练集 82 | batch_size = 20 83 | my_train_data = my_dataset(train_data, train_label) 84 | train_loader = DataLoader(my_train_data, batch_size=batch_size, shuffle=True,drop_last=True) 85 | # 验证集 86 | my_dev_data = my_dataset(dev_data, dev_label) 87 | dev_loader = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True,drop_last=True) 88 | # 测试集 89 | pred_data = my_dataset1(test_data) 90 | pred_data = DataLoader(pred_data, batch_size=1) 91 | 92 | # 定义模型 93 | my_model = TextCNN(embedding_dim=embedding_matrix.shape[1], dropout_rate=0.2, num_class=5, 94 | embedding_matrix=embedding_matrix, requires_grads=False) 95 | optimizer = optim.Adam(my_model.parameters()) 96 | loss_fn = nn.CrossEntropyLoss() 97 | save_path = "best.ckpt" 98 | 99 | writer = SummaryWriter("logfie/1") 100 | my_trainer = Trainer(model_name="textcnn", model=my_model, train_loader=train_loader, dev_loader=dev_loader, 101 | test_loader=None, optimizer=optimizer, loss_fn=loss_fn, save_path=save_path, epochs=100, 102 | writer=writer, max_norm=0.25, eval_step_interval=10, device='cpu') 103 | 104 | # 训练 105 | my_trainer.train() 106 | # 测试 107 | p, r, f1 = my_trainer.test() 108 | print(p, r, f1) 109 | # 打印在验证集上最好的f1值 110 | print(my_trainer.best_f1) 111 | 112 | # 预测 113 | prd_label = my_trainer.predict(pred_data) 114 | print(prd_label.shape) 115 | -------------------------------------------------------------------------------- /examples/label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/examples/label.png -------------------------------------------------------------------------------- /examples/len.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/examples/len.png -------------------------------------------------------------------------------- /examples/preprocessing.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import numpy as np 3 | import codecs 4 | 5 | 6 | def load_pretrained_embedding(pretrained_embedding_file_path): 7 | ''' 8 | # 加载预训练的词向量,这里使用GloVe 9 | :param pretrained_embedding_file_path: 预训练词向量文件存放的路径 10 | :return: 11 | ''' 12 | embedding_matrix = [] 13 | word2idx = dict() 14 | word2idx["__PAD__"] = 0 15 | word2idx["__UNK__"] = 1 16 | index = 2 17 | 18 | with codecs.open(pretrained_embedding_file_path, "r", encoding="utf-8") as f: 19 | temp = f.readline().strip().split(" ") 20 | embedding_dim = len(temp) - 1 21 | 22 | embedding_matrix.append(np.zeros(shape=(embedding_dim,))) 23 | embedding_matrix.append(np.random.randn(embedding_dim)) 24 | 25 | f.seek(0) 26 | for line in f: 27 | line = line.strip().split(" ") 28 | word, emd = line[0], line[1:] 29 | emd = [float(x) for x in emd] 30 | 31 | word2idx[word] = index 32 | index += 1 33 | embedding_matrix.append(np.array(emd)) 34 | 35 | assert word2idx.__len__() == embedding_matrix.__len__() 36 | embedding_matrix = torch.from_numpy(np.array(embedding_matrix)).float() 37 | 38 | return word2idx, embedding_matrix 39 | 40 | 41 | 42 | def text_convert_to_ids(text, word2idx): 43 | ''' 44 | # 将一个样本向量化 45 | :param text: text 46 | :param word2idx: 词典 47 | :return: 向量化的文本 48 | ''' 49 | input_ids = [] 50 | tokenizered_text = text.strip().split(" ") 51 | for item in tokenizered_text: 52 | id = word2idx.get(item, 1) 53 | input_ids.append(id) 54 | 55 | return np.array(input_ids) 56 | 57 | 58 | def texts_convert_to_ids(texts, word2idx): 59 | ''' 60 | # 将样本的list向量化 61 | :param texts: list of text,[text1,text2,...] 62 | :param word2idx: 词典 63 | :return: 向量化的文本 64 | ''' 65 | input_ids = [] 66 | for text in texts: 67 | temp = text_convert_to_ids(text, word2idx) 68 | input_ids.append(temp) 69 | 70 | return np.array(input_ids) 71 | 72 | 73 | def pad_sequences(input_id, max_length=200): 74 | ''' 75 | padding 76 | :param input_id: 向量化的文本 77 | :param max_length: 最大长度 78 | :return: 向量化的文本 79 | ''' 80 | input_ids = [] 81 | for i in range(input_id.shape[0]): 82 | if input_id[i].__len__() >= max_length: 83 | input_ids.append(input_id[i][:max_length]) 84 | else: 85 | extra = max_length - input_id[i].__len__() 86 | input_ids.append(np.append(input_id[i], [0] * extra)) 87 | 88 | return np.array(input_ids) 89 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import find_packages, setup 2 | import codecs 3 | 4 | with codecs.open("README.md", "r", encoding="utf-8") as fh: 5 | long_description = fh.read() 6 | 7 | REQUIRED_PACKAGES = [ 8 | "torch>=1.1.0", 9 | "transformers>=4.0.0", 10 | "scikit-learn", 11 | "tensorboardX" 12 | ] 13 | 14 | setup( 15 | name="deepclassifier", 16 | version="0.0.6", 17 | author="Zichao Li", 18 | author_email="2843656167@qq.com", 19 | description="DeepClassifier is aimed at building general text classification model library.It's easy and user-friendly to build any text classification task.", 20 | long_description=long_description, 21 | long_description_content_type="text/markdown", 22 | url="https://github.com/codewithzichao/DeepClassifier", 23 | download_url='https://github.com/codewithzichao/DeepClassifier/tags', 24 | packages=find_packages( 25 | exclude=["tests"] 26 | ), 27 | python_requires=">=3.6.0", 28 | install_requires=REQUIRED_PACKAGES, 29 | # extra_require={}, 30 | entry_points={}, 31 | classifiers=[ 32 | "License :: OSI Approved :: Apache Software License", 33 | "Operating System :: OS Independent", 34 | 'Intended Audience :: Developers', 35 | 'Intended Audience :: Education', 36 | 'Intended Audience :: Science/Research', 37 | 'Programming Language :: Python :: 3', 38 | 'Programming Language :: Python :: 3.6', 39 | 'Programming Language :: Python :: 3.7', 40 | 'Topic :: Scientific/Engineering', 41 | 'Topic :: Scientific/Engineering :: Artificial Intelligence', 42 | 'Topic :: Software Development', 43 | 'Topic :: Software Development :: Libraries', 44 | 'Topic :: Software Development :: Libraries :: Python Modules', 45 | ], 46 | license="Apache-2.0", 47 | keywords=[ 48 | "text classification", "pytorch", "torch", "NLP", "deep learning", "deepclassifier" 49 | ] 50 | 51 | ) 52 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithzichao/DeepClassifier/c07e8041a2aca855fed9bf69fd571f1cbd5ec032/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_bertdpcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import BertDPCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | 22 | class my_dataset(Dataset): 23 | def __init__(self, data, mask, label): 24 | self.data = data 25 | self.label = label 26 | self.mask = mask 27 | 28 | def __len__(self): 29 | return len(self.data) 30 | 31 | def __getitem__(self, item): 32 | item_data = self.data[item] 33 | item_mask = self.mask[item] 34 | item_label = self.label[item] 35 | 36 | return item_data, item_mask, item_label 37 | 38 | class my_dataset1(Dataset): 39 | def __init__(self, data): 40 | self.data = data 41 | 42 | 43 | def __len__(self): 44 | return len(self.data) 45 | 46 | def __getitem__(self, item): 47 | item_data = self.data[item] 48 | 49 | return item_data 50 | 51 | 52 | # 训练集 53 | batch_size = 20 54 | train_data = np.random.randint(0, 100, (100, 60)) 55 | train_mask = np.random.randint(0, 1, (100, 60)) 56 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 57 | my_train_data = my_dataset(train_data,train_mask, train_label) 58 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 59 | 60 | # 验证集 61 | dev_data = np.random.randint(0, 100, (100, 60)) 62 | dev_mask = np.random.randint(0, 1, (100, 60)) 63 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 64 | my_dev_data = my_dataset(dev_data, dev_mask,dev_label) 65 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 66 | 67 | # 测试集 68 | test_data = np.random.randint(0, 100, (100, 60)) 69 | test_mask= np.random.randint(0, 1, (100, 60)) 70 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 71 | my_test_data = my_dataset(test_data,test_mask ,dev_label) 72 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 73 | 74 | my_model = BertDPCNN(768,0.2,2,"/Users/codewithzichao/Desktop/开源的库/DeepClassifier/bert-base-uncased/") 75 | 76 | optimizer = optim.Adam(my_model.parameters()) 77 | loss_fn = nn.CrossEntropyLoss() 78 | save_path = "best.ckpt" 79 | 80 | writer = SummaryWriter("logfie/1") 81 | my_trainer = Trainer(model_name="bertdpcnn", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 82 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 83 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 84 | 85 | # 训练 86 | my_trainer.train() 87 | # 测试 88 | p, r, f1 = my_trainer.test() 89 | print(p, r, f1) 90 | # 打印在验证集上最好的f1值 91 | print(my_trainer.best_f1) 92 | 93 | # 预测 94 | pred_data = np.random.randint(0, 100, (100, 60)) 95 | pred_data=my_dataset1(pred_data) 96 | pred_data=DataLoader(pred_data,batch_size=1) 97 | prd_label=my_trainer.predict(pred_data) 98 | print(prd_label.shape) 99 | -------------------------------------------------------------------------------- /tests/test_berthan.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import BertHAN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | 22 | class my_dataset(Dataset): 23 | def __init__(self, data, mask, label): 24 | self.data = data 25 | self.label = label 26 | self.mask = mask 27 | 28 | def __len__(self): 29 | return len(self.data) 30 | 31 | def __getitem__(self, item): 32 | item_data = self.data[item] 33 | item_mask = self.mask[item] 34 | item_label = self.label[item] 35 | 36 | return item_data, item_mask, item_label 37 | 38 | class my_dataset1(Dataset): 39 | def __init__(self, data): 40 | self.data = data 41 | 42 | 43 | def __len__(self): 44 | return len(self.data) 45 | 46 | def __getitem__(self, item): 47 | item_data = self.data[item] 48 | 49 | 50 | return item_data 51 | 52 | 53 | # 训练集 54 | batch_size = 20 55 | train_data = np.random.randint(0, 100, (100, 60,10)) 56 | train_mask = np.random.randint(0, 1, (100, 60,10)) 57 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 58 | my_train_data = my_dataset(train_data,train_mask, train_label) 59 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 60 | 61 | # 验证集 62 | dev_data = np.random.randint(0, 100, (100, 60,10)) 63 | dev_mask = np.random.randint(0, 1, (100, 60,10)) 64 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 65 | my_dev_data = my_dataset(dev_data, dev_mask,dev_label) 66 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 67 | 68 | # 测试集 69 | test_data = np.random.randint(0, 100, (100, 60,10)) 70 | test_mask= np.random.randint(0, 1, (100, 60,10)) 71 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 72 | my_test_data = my_dataset(test_data,test_mask ,dev_label) 73 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 74 | 75 | my_model = BertHAN(768,100,100,0.2,2,"/Users/codewithzichao/Desktop/开源的库/DeepClassifier/bert-base-uncased/") 76 | optimizer = optim.Adam(my_model.parameters()) 77 | loss_fn = nn.CrossEntropyLoss() 78 | save_path = "best.ckpt" 79 | 80 | writer = SummaryWriter("logfie/1") 81 | my_trainer = Trainer(model_name="berthan", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 82 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 83 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 84 | 85 | # 训练 86 | my_trainer.train() 87 | # 测试 88 | p, r, f1 = my_trainer.test() 89 | print(p, r, f1) 90 | # 打印在验证集上最好的f1值 91 | print(my_trainer.best_f1) 92 | 93 | # 预测 94 | pred_data = np.random.randint(0, 100, (100, 60)) 95 | pred_data=my_dataset1(pred_data) 96 | pred_data=DataLoader(pred_data,batch_size=1) 97 | prd_label=my_trainer.predict(pred_data) 98 | print(prd_label.shape) 99 | -------------------------------------------------------------------------------- /tests/test_bertrcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import BertRCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | class my_dataset(Dataset): 22 | def __init__(self, data, mask, label): 23 | self.data = data 24 | self.label = label 25 | self.mask = mask 26 | 27 | def __len__(self): 28 | return len(self.data) 29 | 30 | def __getitem__(self, item): 31 | item_data = self.data[item] 32 | item_mask = self.mask[item] 33 | item_label = self.label[item] 34 | 35 | return item_data, item_mask, item_label 36 | 37 | class my_dataset1(Dataset): 38 | def __init__(self, data): 39 | self.data = data 40 | 41 | 42 | def __len__(self): 43 | return len(self.data) 44 | 45 | def __getitem__(self, item): 46 | item_data = self.data[item] 47 | 48 | 49 | return item_data 50 | 51 | 52 | # 训练集 53 | batch_size = 20 54 | train_data = np.random.randint(0, 100, (100, 60)) 55 | train_mask = np.random.randint(0, 1, (100, 60)) 56 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 57 | my_train_data = my_dataset(train_data,train_mask, train_label) 58 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 59 | 60 | # 验证集 61 | dev_data = np.random.randint(0, 100, (100, 60)) 62 | dev_mask = np.random.randint(0, 1, (100, 60)) 63 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 64 | my_dev_data = my_dataset(dev_data, dev_mask,dev_label) 65 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 66 | 67 | # 测试集 68 | test_data = np.random.randint(0, 100, (100, 60)) 69 | test_mask= np.random.randint(0, 1, (100, 60)) 70 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 71 | my_test_data = my_dataset(test_data,test_mask ,dev_label) 72 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 73 | 74 | my_model=BertRCNN(768,100,0.2,2,"/Users/codewithzichao/Desktop/开源的库/DeepClassifier/bert-base-uncased/") 75 | optimizer = optim.Adam(my_model.parameters()) 76 | loss_fn = nn.CrossEntropyLoss() 77 | save_path = "best.ckpt" 78 | 79 | writer = SummaryWriter("logfie/1") 80 | my_trainer = Trainer(model_name="bertrcnn", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 81 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 82 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 83 | 84 | # 训练 85 | my_trainer.train() 86 | # 测试 87 | p, r, f1 = my_trainer.test() 88 | print(p, r, f1) 89 | # 打印在验证集上最好的f1值 90 | print(my_trainer.best_f1) 91 | 92 | # 预测 93 | pred_data = np.random.randint(0, 100, (100, 60)) 94 | pred_data=my_dataset1(pred_data) 95 | pred_data=DataLoader(pred_data,batch_size=1) 96 | prd_label=my_trainer.predict(pred_data) 97 | print(prd_label.shape) 98 | -------------------------------------------------------------------------------- /tests/test_berttextcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import BertTextCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | 22 | class my_dataset(Dataset): 23 | def __init__(self, data, mask, label): 24 | self.data = data 25 | self.label = label 26 | self.mask = mask 27 | 28 | def __len__(self): 29 | return len(self.data) 30 | 31 | def __getitem__(self, item): 32 | item_data = self.data[item] 33 | item_mask = self.mask[item] 34 | item_label = self.label[item] 35 | 36 | return item_data, item_mask, item_label 37 | 38 | class my_dataset1(Dataset): 39 | def __init__(self, data): 40 | self.data = data 41 | 42 | 43 | def __len__(self): 44 | return len(self.data) 45 | 46 | def __getitem__(self, item): 47 | item_data = self.data[item] 48 | 49 | return item_data 50 | 51 | 52 | # 训练集 53 | batch_size = 20 54 | train_data = np.random.randint(0, 100, (100, 60)) 55 | train_mask = np.random.randint(0, 1, (100, 60)) 56 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 57 | my_train_data = my_dataset(train_data,train_mask, train_label) 58 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 59 | 60 | # 验证集 61 | dev_data = np.random.randint(0, 100, (100, 60)) 62 | dev_mask = np.random.randint(0, 1, (100, 60)) 63 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 64 | my_dev_data = my_dataset(dev_data, dev_mask,dev_label) 65 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 66 | 67 | # 测试集 68 | test_data = np.random.randint(0, 100, (100, 60)) 69 | test_mask= np.random.randint(0, 1, (100, 60)) 70 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 71 | my_test_data = my_dataset(test_data,test_mask ,dev_label) 72 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 73 | 74 | my_model = BertTextCNN(768,0.2,2,"/Users/codewithzichao/Desktop/DeepClassifier/bert-base-uncased/") 75 | 76 | optimizer = optim.Adam(my_model.parameters()) 77 | loss_fn = nn.CrossEntropyLoss() 78 | save_path = "best.ckpt" 79 | 80 | writer = SummaryWriter("logfie/1") 81 | my_trainer = Trainer(model_name="berttextcnn", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 82 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 83 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 84 | 85 | # 训练 86 | my_trainer.train() 87 | # 测试 88 | p, r, f1 = my_trainer.test() 89 | print(p, r, f1) 90 | # 打印在验证集上最好的f1值 91 | print(my_trainer.best_f1) 92 | 93 | # 预测 94 | pred_data = np.random.randint(0, 100, (100, 60)) 95 | pred_data=my_dataset1(pred_data) 96 | pred_data=DataLoader(pred_data,batch_size=1) 97 | prd_label=my_trainer.predict(pred_data) 98 | print(prd_label.shape) 99 | -------------------------------------------------------------------------------- /tests/test_dpcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | 11 | import os 12 | import torch 13 | import torch.nn as nn 14 | import numpy as np 15 | import torch.nn.functional as F 16 | from torch.utils.data import Dataset, DataLoader 17 | import torch.optim as optim 18 | from deepclassifier.models import DPCNN 19 | from deepclassifier.trainers import Trainer 20 | from tensorboardX import SummaryWriter 21 | 22 | 23 | class my_dataset(Dataset): 24 | def __init__(self, data, label): 25 | self.data = data 26 | self.label = label 27 | 28 | def __len__(self): 29 | return len(self.data) 30 | 31 | def __getitem__(self, item): 32 | item_data = self.data[item] 33 | item_label = self.label[item] 34 | 35 | return item_data, item_label 36 | 37 | 38 | class my_dataset1(Dataset): 39 | def __init__(self, data): 40 | self.data = data 41 | 42 | def __len__(self): 43 | return len(self.data) 44 | 45 | def __getitem__(self, item): 46 | item_data = self.data[item] 47 | 48 | return item_data 49 | 50 | 51 | # 训练集 52 | batch_size = 20 53 | train_data = np.random.randint(0, 100, (100, 60)) 54 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 55 | my_train_data = my_dataset(train_data, train_label) 56 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 57 | 58 | # 验证集 59 | dev_data = np.random.randint(0, 100, (100, 60)) 60 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 61 | my_dev_data = my_dataset(dev_data, dev_label) 62 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 63 | 64 | # 测试集 65 | test_data = np.random.randint(0, 100, (100, 60)) 66 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 67 | my_test_data = my_dataset(test_data, dev_label) 68 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 69 | print(dev_data.dtype) 70 | 71 | my_model = DPCNN(100, 0.2,2, 100, 60) 72 | optimizer = optim.Adam(my_model.parameters()) 73 | loss_fn = nn.CrossEntropyLoss() 74 | save_path = "best.ckpt" 75 | 76 | writer = SummaryWriter("logfie/1") 77 | my_trainer = Trainer(model_name="dpcnn", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 78 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 79 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 80 | 81 | # 训练 82 | my_trainer.train() 83 | # 测试 84 | p, r, f1 = my_trainer.test() 85 | print(p, r, f1) 86 | # 打印在验证集上最好的f1值 87 | print(my_trainer.best_f1) 88 | 89 | # 预测 90 | pred_data = np.random.randint(0, 100, (100, 60)) 91 | pred_data = my_dataset1(pred_data) 92 | pred_data = DataLoader(pred_data, batch_size=1) 93 | prd_label = my_trainer.predict(pred_data) 94 | print(prd_label.shape) 95 | -------------------------------------------------------------------------------- /tests/test_han.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import HAN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | 22 | class my_dataset(Dataset): 23 | def __init__(self, data, label): 24 | self.data = data 25 | self.label = label 26 | 27 | def __len__(self): 28 | return len(self.data) 29 | 30 | def __getitem__(self, item): 31 | item_data = self.data[item] 32 | item_label = self.label[item] 33 | 34 | return item_data, item_label 35 | 36 | class my_dataset1(Dataset): 37 | def __init__(self, data): 38 | self.data = data 39 | 40 | 41 | def __len__(self): 42 | return len(self.data) 43 | 44 | def __getitem__(self, item): 45 | item_data = self.data[item] 46 | 47 | 48 | return item_data 49 | 50 | 51 | # 训练集 52 | batch_size = 20 53 | train_data = np.random.randint(0, 100, (100, 60,10)) 54 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 55 | my_train_data = my_dataset(train_data, train_label) 56 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 57 | 58 | # 验证集 59 | dev_data = np.random.randint(0, 100, (100, 60,10)) 60 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 61 | my_dev_data = my_dataset(dev_data, dev_label) 62 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 63 | 64 | # 测试集 65 | test_data = np.random.randint(0, 100, (100, 60,10)) 66 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 67 | my_test_data = my_dataset(test_data, dev_label) 68 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 69 | 70 | my_model = HAN(10,100,100,0.2,2,100,60) 71 | optimizer = optim.Adam(my_model.parameters()) 72 | loss_fn = nn.CrossEntropyLoss() 73 | save_path = "best.ckpt" 74 | 75 | writer = SummaryWriter("logfie/1") 76 | my_trainer = Trainer(model_name="han", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 77 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 78 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 79 | 80 | # 训练 81 | my_trainer.train() 82 | # 测试 83 | p, r, f1 = my_trainer.test() 84 | print(p, r, f1) 85 | # 打印在验证集上最好的f1值 86 | print(my_trainer.best_f1) 87 | 88 | # 预测 89 | pred_data = np.random.randint(0, 100, (100, 60)) 90 | pred_data=my_dataset1(pred_data) 91 | pred_data=DataLoader(pred_data,batch_size=1) 92 | prd_label=my_trainer.predict(pred_data) 93 | print(prd_label.shape) 94 | -------------------------------------------------------------------------------- /tests/test_rcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import RCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | 22 | class my_dataset(Dataset): 23 | def __init__(self, data, label): 24 | self.data = data 25 | self.label = label 26 | 27 | def __len__(self): 28 | return len(self.data) 29 | 30 | def __getitem__(self, item): 31 | item_data = self.data[item] 32 | item_label = self.label[item] 33 | 34 | return item_data, item_label 35 | 36 | class my_dataset1(Dataset): 37 | def __init__(self, data): 38 | self.data = data 39 | 40 | 41 | def __len__(self): 42 | return len(self.data) 43 | 44 | def __getitem__(self, item): 45 | item_data = self.data[item] 46 | 47 | 48 | return item_data 49 | 50 | 51 | # 训练集 52 | batch_size = 20 53 | train_data = np.random.randint(0, 100, (100, 60)) 54 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 55 | my_train_data = my_dataset(train_data, train_label) 56 | final_train_data = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 57 | 58 | # 验证集 59 | dev_data = np.random.randint(0, 100, (100, 60)) 60 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 61 | my_dev_data = my_dataset(dev_data, dev_label) 62 | final_dev_data = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 63 | 64 | # 测试集 65 | test_data = np.random.randint(0, 100, (100, 60)) 66 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 67 | my_test_data = my_dataset(test_data, dev_label) 68 | final_test_data = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 69 | 70 | my_model = RCNN(100,100,0.2,2,100,60) 71 | optimizer = optim.Adam(my_model.parameters()) 72 | loss_fn = nn.CrossEntropyLoss() 73 | save_path = "best.ckpt" 74 | 75 | writer = SummaryWriter("logfie/1") 76 | my_trainer = Trainer(model_name="rcnn", model=my_model, train_loader=final_train_data, dev_loader=final_dev_data, 77 | test_loader=final_test_data, optimizer=optimizer, loss_fn=loss_fn, 78 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10) 79 | 80 | # 训练 81 | my_trainer.train() 82 | # 测试 83 | p, r, f1 = my_trainer.test() 84 | print(p, r, f1) 85 | # 打印在验证集上最好的f1值 86 | print(my_trainer.best_f1) 87 | 88 | # 预测 89 | pred_data = np.random.randint(0, 100, (100, 60)) 90 | pred_data=my_dataset1(pred_data) 91 | pred_data=DataLoader(pred_data,batch_size=1) 92 | prd_label=my_trainer.predict(pred_data) 93 | print(prd_label.shape) 94 | -------------------------------------------------------------------------------- /tests/test_textcnn.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | ''' 3 | 4 | Author: 5 | Zichao Li,2843656167@qq.com 6 | 7 | ''' 8 | from __future__ import print_function 9 | 10 | import os 11 | import torch 12 | import torch.nn as nn 13 | import numpy as np 14 | import torch.nn.functional as F 15 | from torch.utils.data import Dataset, DataLoader 16 | import torch.optim as optim 17 | from deepclassifier.models import TextCNN 18 | from deepclassifier.trainers import Trainer 19 | from tensorboardX import SummaryWriter 20 | 21 | 22 | class my_dataset(Dataset): 23 | def __init__(self, data, label): 24 | self.data = data 25 | self.label = label 26 | 27 | def __len__(self): 28 | return len(self.data) 29 | 30 | def __getitem__(self, item): 31 | item_data = self.data[item] 32 | item_label = self.label[item] 33 | 34 | return item_data, item_label 35 | 36 | class my_dataset1(Dataset): 37 | def __init__(self, data): 38 | self.data = data 39 | 40 | 41 | def __len__(self): 42 | return len(self.data) 43 | 44 | def __getitem__(self, item): 45 | item_data = self.data[item] 46 | 47 | 48 | return item_data 49 | 50 | 51 | # 训练集 52 | batch_size = 20 53 | train_data = np.random.randint(0, 100, (100, 60)) 54 | train_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 55 | my_train_data = my_dataset(train_data, train_label) 56 | train_loader = DataLoader(my_train_data, batch_size=batch_size, shuffle=True) 57 | 58 | # 验证集 59 | dev_data = np.random.randint(0, 100, (100, 60)) 60 | dev_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 61 | my_dev_data = my_dataset(dev_data, dev_label) 62 | dev_loader = DataLoader(my_dev_data, batch_size=batch_size, shuffle=True) 63 | 64 | # 测试集 65 | test_data = np.random.randint(0, 100, (100, 60)) 66 | test_label = torch.from_numpy(np.array([int(x > 0.5) for x in np.random.randn(100)])) 67 | my_test_data = my_dataset(test_data, dev_label) 68 | test_loader = DataLoader(my_test_data, batch_size=batch_size, shuffle=True) 69 | 70 | my_model = TextCNN(5, 0.2, 2, 100, 60) 71 | optimizer = optim.Adam(my_model.parameters()) 72 | loss_fn = nn.CrossEntropyLoss() 73 | save_path = "best.ckpt" 74 | 75 | writer = SummaryWriter("logfie/1") 76 | my_trainer = Trainer(model_name="textcnn", model=my_model, train_loader=train_loader, dev_loader=dev_loader, 77 | test_loader=test_loader, optimizer=optimizer, loss_fn=loss_fn, 78 | save_path=save_path, epochs=100, writer=writer, max_norm=0.25, eval_step_interval=10, device='cpu') 79 | 80 | print(my_trainer.device) 81 | # 训练 82 | my_trainer.train() 83 | # 测试 84 | p, r, f1 = my_trainer.test() 85 | print(p, r, f1) 86 | # 打印在验证集上最好的f1值 87 | print(my_trainer.best_f1) 88 | 89 | # 预测 90 | pred_data = np.random.randint(0, 100, (100, 60)) 91 | pred_data=my_dataset1(pred_data) 92 | pred_data=DataLoader(pred_data,batch_size=1) 93 | prd_label=my_trainer.predict(pred_data) 94 | print(prd_label.shape) 95 | --------------------------------------------------------------------------------