赞
踩
简单而强大的NLP框架,在5分钟内为命名实体识别(NER)、词性标注(PoS)和文本分类任务构建最新模型
喀什是:
Task | Language | Dataset | Score | Detail |
---|---|---|---|---|
Named Entity Recognition | Chinese | People's Daily Ner Corpus | 92.20 (F1) | 基于 BERT 的中文命名实体识别 |
下面是一组快速教程,帮助您开始使用库:
还有一些文章和帖子说明了如何使用喀什喀里:
该项目基于Keras 2.2.0+和Python 3.6+,因为现在是2019年,类型提示很酷
pip install kashgari # CPU pip install tensorflow==1.12.0 # GPU pip install tensorflow-gpu==1.12.0
让我们使用cnn模型在SMP 2017 ECDT Task1上运行文本分类。
>>>fromkashgari.corpusimportSMP2017ECDTClassificationCorpus>>>fromkashgari.tasks.classificationimportCNNLSTMModel>>>x_data,y_data=SMP2017ECDTClassificationCorpus.get_classification_data()>>>x_data[0]['你','知','道','我','几','岁']>>>y_data[0]'chat'# provided classification models `CNNModel`, `BLSTMModel`, `CNNLSTMModel` >>>classifier=CNNLSTMModel()>>>classifier.fit(x_data,y_data)_________________________________________________________________Layer(type)OutputShapeParam# =================================================================input_1(InputLayer)(None,10)0_________________________________________________________________embedding_1(Embedding)(None,10,100)87500_________________________________________________________________conv1d_1(Conv1D)(None,10,32)9632_________________________________________________________________max_pooling1d_1(MaxPooling1(None,5,32)0_________________________________________________________________lstm_1(LSTM)(None,100)53200_________________________________________________________________dense_1(Dense)(None,32)3232=================================================================Totalparams:153,564Trainableparams:153,564Non-trainableparams:0_________________________________________________________________Epoch1/51/35[..............................]-ETA:32s-loss:3.4652-acc:0.0469...>>>x_test,y_test=SMP2017ECDTClassificationCorpus.get_classification_data('test')>>>classifier.evaluate(x_test,y_test)precisionrecallf1-scoresupportcalc0.750.750.758chat0.830.860.85154contacts0.540.700.6110cookbook0.970.940.9589datetime0.670.670.676email1.000.880.938epg0.610.560.5836flight1.000.900.9521...
fromkashgari.embeddingsimportGPT2Embeddingfromkashgari.tasks.classificationimportCNNLSTMModelfromkashgari.corpusimportSMP2017ECDTClassificationCorpusgpt2_embedding=GPT2Embedding('<path-to-gpt-model-folder>',sequence_length=30)model=CNNLSTMModel(gpt2_embedding)train_x,train_y=SMP2017ECDTClassificationCorpus.get_classification_data()model.fit(train_x,train_y)
fromkashgari.embeddingsimportBERTEmbeddingfromkashgari.tasks.classificationimportCNNLSTMModelfromkashgari.corpusimportSMP2017ECDTClassificationCorpusbert_embedding=BERTEmbedding('<bert-model-folder>',sequence_length=30)model=CNNLSTMModel(bert_embedding)train_x,train_y=SMP2017ECDTClassificationCorpus.get_classification_data()model.fit(train_x,train_y)
fromkashgari.embeddingsimportWordEmbeddingsfromkashgari.tasks.classificationimportCNNLSTMModelfromkashgari.corpusimportSMP2017ECDTClassificationCorpusbert_embedding=WordEmbeddings('sgns.weibo.bigram',sequence_length=30)model=CNNLSTMModel(bert_embedding)train_x,train_y=SMP2017ECDTClassificationCorpus.get_classification_data()model.fit(train_x,train_y)
fromkashgari.embeddingsimportBERTEmbeddingfromkashgari.tasks.classificationimportCNNLSTMModeltrain_x,train_y=prepare_your_classification_data()# build model with embeddingbert_embedding=BERTEmbedding('bert-large-cased',sequence_length=128)model=CNNLSTMModel(bert_embedding)# or without pre-trained embeddingmodel=CNNLSTMModel()# Build model with your corpusmodel.build_model(train_x,train_y)# Add multi gpu supportmodel.build_multi_gpu_model(gpus=8)# Train, 256 / 8 = 32 samples for every GPU per batchmodel.fit(train_x,train_y,batch_size=256)
感谢您对贡献的兴趣!有很多方法可以参与进来;从contributor guidelines开始,然后检查这些打开的问题以了解具体的任务。
这个图书馆受到以下框架和论文的启发和参考。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。