class_docstr: 使用 **CNN** 进行文本分类的模型。
  论文参考 `Yoon Kim. 2014. Convolution Neural Networks for Sentence Classification <https://arxiv.org/abs/1408.5882>`_ 。
  
  :param embed: 单词词典，支持以下几种输入类型：
  
          - ``tuple(num_embedings, embedding_dim)``，即 embedding 的大小和每个词的维度，此时将随机初始化一个 :class:`torch.nn.Embedding` 实例；
          - :class:`torch.nn.Embedding` 或 **fastNLP** 的 ``Embedding`` 对象，此时就以传入的对象作为 embedding；
          - :class:`numpy.ndarray` ，将使用传入的 ndarray 作为 Embedding 初始化；
          - :class:`torch.Tensor`，此时将使用传入的值作为 Embedding 初始化；
  
  :param num_classes: 一共有多少类
  :param kernel_nums: 输出 channel 的 kernel 数目。
      如果为 :class:`list` 或 :class:`tuple`，则需要与 ``kernel_sizes`` 的大小保持一致。
  :param kernel_sizes: 输出 channel 的 kernel 大小。
  :param dropout: Dropout 的大小
class_docstr_tok: ["\u4f7f\u7528","*","*","CNN","*","*","\u8fdb\u884c\u6587\u672c\u5206\u7c7b\u7684\u6a21\u578b\u3002","\u8bba\u6587\u53c2\u8003","`","Yoon","Kim",".","2014",".","Convolution","Neural","Networks","for","Sentence","Classification","<","https",":","\/\/arxiv.org\/abs\/1408.5882",">","`","_","\u3002",":","param","embed",":","\u5355\u8bcd\u8bcd\u5178\uff0c\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u8f93\u5165\u7c7b\u578b\uff1a","-","``","tuple","(","num_embedings",",","embedding_dim",")","``","\uff0c\u5373","embedding","\u7684\u5927\u5c0f\u548c\u6bcf\u4e2a\u8bcd\u7684\u7ef4\u5ea6\uff0c\u6b64\u65f6\u5c06\u968f\u673a\u521d\u59cb\u5316\u4e00\u4e2a",":","class",":","`","torch.nn.Embedding","`","\u5b9e\u4f8b\uff1b","-",":","class",":","`","torch.nn.Embedding","`","\u6216","*","*","fastNLP","*","*","\u7684","``","Embedding","``","\u5bf9\u8c61\uff0c\u6b64\u65f6\u5c31\u4ee5\u4f20\u5165\u7684\u5bf9\u8c61\u4f5c\u4e3a","embedding\uff1b","-",":","class",":","`","numpy.ndarray","`","\uff0c\u5c06\u4f7f\u7528\u4f20\u5165\u7684","ndarray","\u4f5c\u4e3a","Embedding","\u521d\u59cb\u5316\uff1b","-",":","class",":","`","torch.Tensor","`","\uff0c\u6b64\u65f6\u5c06\u4f7f\u7528\u4f20\u5165\u7684\u503c\u4f5c\u4e3a","Embedding","\u521d\u59cb\u5316\uff1b",":","param","num_classes",":","\u4e00\u5171\u6709\u591a\u5c11\u7c7b",":","param","kernel_nums",":","\u8f93\u51fa","channel","\u7684","kernel","\u6570\u76ee\u3002","\u5982\u679c\u4e3a",":","class",":","`","list","`","\u6216",":","class",":","`","tuple","`","\uff0c\u5219\u9700\u8981\u4e0e","``","kernel_sizes","``","\u7684\u5927\u5c0f\u4fdd\u6301\u4e00\u81f4\u3002",":","param","kernel_sizes",":","\u8f93\u51fa","channel","\u7684","kernel","\u5927\u5c0f\u3002",":","param","dropout",":","Dropout","\u7684\u5927\u5c0f"]
docstr: :param words: 句子中 word 的 index，形状为 ``[batch_size, seq_len]``
  :param target: 每个 sample 的目标值
  :param seq_len: 每个句子的长度，形状为 ``[batch,]`` 
  :return: 类型为字典的结果，仅包含一个键 ``loss``，表示当次训练的 loss
docstr_tok: [":","param","words",":","\u53e5\u5b50\u4e2d","word","\u7684","index\uff0c\u5f62\u72b6\u4e3a","``","[","batch_size",",","seq_len","]","``",":","param","target",":","\u6bcf\u4e2a","sample","\u7684\u76ee\u6807\u503c",":","param","seq_len",":","\u6bcf\u4e2a\u53e5\u5b50\u7684\u957f\u5ea6\uff0c\u5f62\u72b6\u4e3a","``","[","batch",",","]","``",":","return",":","\u7c7b\u578b\u4e3a\u5b57\u5178\u7684\u7ed3\u679c\uff0c\u4ec5\u5305\u542b\u4e00\u4e2a\u952e","``","loss","``","\uff0c\u8868\u793a\u5f53\u6b21\u8bad\u7ec3\u7684","loss"]
code: def train_step(self, words, target, seq_len=None):
      """
  
      :param words: 句子中 word 的 index，形状为 ``[batch_size, seq_len]``
      :param target: 每个 sample 的目标值
      :param seq_len: 每个句子的长度，形状为 ``[batch,]``
      :return: 类型为字典的结果，仅包含一个键 ``loss``，表示当次训练的 loss
      """
      res = self(words, seq_len)
      x = res["pred"]
      loss = F.cross_entropy(x, target)
      return {"loss": loss}
  
file_path: fastNLP/fastNLP/models/torch/cnn_text_classification.py
imports: from typing import Union, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from ...core.utils import seq_len_to_mask
  from ...embeddings.torch import embedding
  from ...modules.torch import encoder
label_desc: Use image node_id 3 for calling the CNNText obj's underlying member method code with example usage: obj.train_step(words, target, seq_len) and returns: dict