Exemple #1
0
    def test_one_hot_ft(self):
        pipeline = Pipeline(
            DataLoader(text_processor=self.text_processor, n_grams=1),
            TextEncoder(encode_type=LSTMTestCase.EncodingAliases.ONE_HOT),
            LSTMClassifier(num_labels=3,
                           num_epochs=3,
                           bidirectional=False,
                           attention=True))
        pipeline(train=LSTMTestCase.INPUT_FILE, test=LSTMTestCase.OUTPUT_FILE)
        pipeline.save(LSTMTestCase.SAVED_PATH)

        _pipeline = Pipeline.load(LSTMTestCase.SAVED_PATH)
        self.assertIsInstance(_pipeline, Pipeline)

        predict_results = _pipeline.predict([
            'hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi '
            '.cần nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',
            'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên '
            'chuẩn, đẹppppp'
        ])

        self.assertIsInstance(predict_results, np.ndarray)
Exemple #2
0
from sentivi import Pipeline
from sentivi.data import DataLoader, TextEncoder
from sentivi.classifier import LSTMClassifier
from sentivi.text_processor import TextProcessor

if __name__ == '__main__':
    text_processor = TextProcessor(
        methods=['word_segmentation', 'remove_punctuation', 'lower'])

    pipeline = Pipeline(
        DataLoader(text_processor=text_processor, n_grams=2, max_length=100),
        TextEncoder(encode_type='word2vec',
                    model_path='./pretrained/wiki.vi.model.bin.gz'),
        LSTMClassifier(num_labels=2,
                       bidirectional=False,
                       attention=True,
                       device='cuda',
                       hidden_layers=1))

    train_results = pipeline(train='./data/dev.vi',
                             test='./data/dev_test.vi',
                             num_epochs=3,
                             learning_rate=1e-3)
    print(train_results)

    predict_results = pipeline.predict([
        'hàng ok đầu tuýp có một số không vừa ốc siết. chỉ được một số đầu thôi .cần '
        'nhất đầu tuýp 14 mà không có. không đạt yêu cầu của mình sử dụng',
        'Son đẹpppp, mùi hương vali thơm nhưng hơi nồng, chất son mịn, màu lên chuẩn, '
        'đẹppppp', 'Son rất đẹp màu xinh lắm'
    ])