def fit(self, X, y):
<EOL>word_vector_transformer = WordVectorTransformer(padding='<STR_LIT>')<EOL>X = word_vector_transformer.fit_transform(X)<EOL>X = LongTensor(X)<EOL>self.word_vector_transformer = word_vector_transformer<EOL>y_transformer = LabelEncoder()<EOL>y = y_transformer.fit_transform(y)<EOL>y = torch.from_numpy(y)<EOL>self.y_transformer = y_transformer<EOL>dataset = CategorizedDataset(X, y)<EOL>dataloader = DataLoader(dataset,<EOL>batch_size=self.batch_size,<EOL>shuffle=True,<EOL>num_workers=<NUM_LIT:4>)<EOL>KERNEL_SIZES = self.kernel_sizes<EOL>NUM_KERNEL = self.num_kernel<EOL>EMBEDDING_DIM = self.embedding_dim<EOL>model = TextCNN(<EOL>vocab_size=word_vector_transformer.get_vocab_size(),<EOL>embedding_dim=EMBEDDING_DIM,<EOL>output_size=len(self.y_transformer.classes_),<EOL>kernel_sizes=KERNEL_SIZES,<EOL>num_kernel=NUM_KERNEL)<EOL>if USE_CUDA:<EOL><INDENT>model = model.cuda()<EOL><DEDENT>EPOCH = self.epoch<EOL>LR = self.lr<EOL>loss_function = nn.CrossEntropyLoss()<EOL>optimizer = optim.Adam(model.parameters(), lr=LR)<EOL>for epoch in range(EPOCH):<EOL><INDENT>losses = []<EOL>for i, data in enumerate(dataloader):<EOL><INDENT>X, y = data<EOL>X, y = Variable(X), Variable(y)<EOL>optimizer.zero_grad()<EOL>model.train()<EOL>output = model(X)<EOL>loss = loss_function(output, y)<EOL>losses.append(loss.data.tolist()[<NUM_LIT:0>])<EOL>loss.backward()<EOL>optimizer.step()<EOL>if i % <NUM_LIT:100> == <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>" % (<EOL>epoch, EPOCH, np.mean(losses)))<EOL>losses = []<EOL><DEDENT><DEDENT><DEDENT>self.model = model<EOL>
Fit KimCNNClassifier according to X, y

        Parameters
        ----------
        X : list of string
            each item is a raw text
        y : list of string
            each item is a label