• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Efficient Chinese Text Classifier

THUCTC: 一个高效的中文文本分类工具

目录

项目介绍

THUCTC(THU Chinese Text Classification)是由清华大学自然语言处理实验室推出的中文文本分类工具包,能够自动高效地实现用户自定义的文本分类语料的训练、评测、分类功能。文本分类通常包括特征选取、特征降维、分类模型学习三个步骤。如何选取合适的文本特征并进行降维,是中文文本分类的挑战性问题。我组根据多年在中文文本分类的研究经验,在THUCTC中选取二字串bigram作为特征单元,特征降维方法为Chi-square,权重计算方法为tfidf,分类模型使用的是LibSVM或LibLinear。THUCTC对于开放领域的长文本具有良好的普适性,不依赖于任何中文分词工具的性能,具有准确率高、测试速度快的优点。

使用方法

我们提供了两种方式运行工具包:

  1. 使用java开发工具,例如eclipse,将包括lib\THUCTC_java_v1.jar在内的lib文件夹下的包导入自己的工程中,仿照Demo.java程序调用函数即可。

  2. 使用根目录下的THUCTC_java_v1_run.jar运行工具包。

    使用命令 java -jar THUCTC_java_v1.jar + 程序参数

运行参数

  • [-c CATEGORY_LIST_FILE_PATH] 从文件中读入类别信息。该文件中每行包含且仅包含一个类别名称。
  • [-train TRAIN_PATH] 进行训练,并设置训练语料文件夹路径。该文件夹下每个子文件夹的名称都对应一个类别名称,内含属于该类别的训练语料。若不设置,则不进行训练。
  • [-test EVAL_PATH] 进行评测,并设置评测语料文件夹路径。该文件夹下每个子文件夹的名称都对应一个类别名称,内含属于该类别的评测语料。若不设置,则不进行评测。也可以使用-eval。
  • [-classify FILE_PATH] 对一个文件进行分类。
  • [-n topN] 设置返回候选分类数,按得分大小排序。默认为1,即只返回最可能的分类。
  • [-svm libsvm or liblinear] 选择使用libsvm还是liblinear进行训练和测试,默认使用liblinear。
  • [-l LOAD_MODEL_PATH] 设置读取模型路径。
  • [-s SAVE_MODEL_PATH] 设置保存模型路径。
  • [-f FEATURE_SIZE] 设置保留特征数目,默认为5000。
  • [-d1 RATIO] 设置训练集占总文件数比例,默认为0.8。
  • [-d2 RATIO] 设置测试集占总文件数比例,默认为0.2。
  • [-e ENCODING] 设置训练及测试文件编码,默认为UTF-8。
  • [-filter SUFFIX] 设置文件后缀过滤。例如设置“-filter .txt”,则训练和测试时仅考虑文件名后缀为.txt的文件。

样例程序

我们随工具包提供了一个调用THUCTC的样例代码Demo.java,其中实现了三种功能:

  1. 对文本进行训练并测试(runTrainAndTest);
  2. 读取已经训练好的模型,对文件进行分类(runLoadModelAndUse);
  3. 按照自己的想法添加训练文件,训练模型(AddFilesManuallyAndTrain);

BasicTextClassifier类接口说明

BasicTextClassifier 是系统的入口类,提供多种设置接口供使用者调用。利用此入口类可以从文件中读入别信息、设置训练语料路径、设置训练参数以及模型保存路径等。

其中常用的类成员函数包括:

  • public void Init(String[] args)

    功能:输入运行参数,初始化系统。

  • public void runAsBigramChineseTextClassifier()

    功能:根据参数,运行系统。

  • public boolean loadCategoryListFromFile(String filePath)

    功能:从文件中获取分类列表,等同于参数-c filePath

  • public boolean loadCategoryListFromFolder(String folder)

    功能:从文件夹中获取分类列表

  • public void addTrainingText(String category, String filename)

    功能:给定类别,添加训练文本

  • public void addfiles(String filename)

    功能:根据训练文件所在的文件夹名称,自动判别类别并加入训练,等同于参数-train filename

  • public ClassifyResult[] classifyFile(String filepath, int topN)

    功能:对一个文件进行分类,返回前 topN 个分类结果。如果输入的 filepath 是文件夹,则只会在 Console 中打印每个子文件的分类结果,返回值是空数组,等同于参数-classify filepath -n topN

  • public ClassifyResult[] classifyText(String text, int topN)

    功能:对一个文本进行分类,返回前 topN 个分类结果

  • public void testfiles(String filename)

    功能:对文件进行自动分类测试,等同于参数-test filename

  • public double getPrecision()

    功能:获得测试准确率

中文文本分类数据集THUCNews

THUCNews是根据新浪新闻RSS订阅频道2005~2011年间的历史数据筛选过滤生成,包含74万篇新闻文档(2.19 GB),均为UTF-8纯文本格式。我们在原始新浪新闻分类体系的基础上,重新整合划分出14个候选分类类别:财经、彩票、房产、股票、家居、教育、科技、社会、时尚、时政、体育、星座、游戏、娱乐。使用THUCTC工具包在此数据集上进行评测,准确率可以达到88.6%。

数据集请登录thuctc.thunlp.org网站填写个人信息进行下载。

测试结果

文本分类的性能评价有多种指标,其中主流的文本分类评价指标包括准确率、召回率、F-measure、微平均与宏平均等。其中,微平均指所有样本的测试结果的算数平均值,宏平均指所有类别的测试结果的算数平均值。我们的测试也主要对这些指标进行测试。 我们选取上节介绍的数据集进行测试,测试时使用以下参数组合(-d1 -d2),(-f):

  • -d1 0.7 -d2 0.3 -f 5000 微平均为最优

    类别 正确率 召回率 F-measure
    体育 0.979 0.990 0.985
    娱乐 0.946 0.958 0.952
    家具 0.864 0.832 0.848
    彩票 0.813 0.757 0.779
    房产 0.973 0.972 0.973
    教育 0.911 0.879 0.895
    时尚 0.746 0.874 0.805
    时政 0.780 0.901 0.836
    星座 0.816 0.516 0.632
    游戏 0.922 0.594 0.707
    社会 0.836 0.820 0.828
    科技 0.850 0.921 0.884
    股票 0.895 0.833 0.863
    财经 0.772 0.685 0.726
    宏平均 0.861 0.823 0.842
    微平均 0.884
  • -d1 0.8 -d2 0.2 -f 20000 宏平均为最优

    类别 正确率 召回率 F-measure
    体育 0.979 0.986 0.983
    娱乐 0.936 0.966 0.951
    家具 0.871 0.883 0.877
    彩票 0.967 0.862 0.911
    房产 0.957 0.953 0.955
    教育 0.887 0.850 0.868
    时尚 0.868 0.881 0.875
    时政 0.764 0.868 0.813
    星座 0.974 0.618 0.756
    游戏 0.922 0.536 0.678
    社会 0.796 0.802 0.799
    科技 0.845 0.882 0.863
    股票 0.858 0.854 0.856
    财经 0.779 0.656 0.713
    宏平均 0.886 0.829 0.856
    微平均 0.875

注意事项

  1. 使用工具进行训练和测试时,训练语料和测试语料请严格按照如下格式放置:

    Train(Test)\
    	类别1\
    		1.txt
    		2.txt
    		3.txt
    		...
    		n.txt
    	类别2\
    		...
    	...
    	类别n\
    		...
    
  2. 该工具是通用的中文文本分类工具包,在针对中文文本进行分类时,选取二字串bigram作为特征单元是经过全面的实验分析和比较的。但在针对英文文本进行分类时,我们不保证选取二字串bigram作为特征单元的效果是最优的。

  3. 在进行训练模型时,请注意根据自己的语料大小设置相应的使用内存上限。例如语料大小为2GB的时候,至少设置使用内存大小为4GB(-Xmx4096m)。如若程序执行缓慢,请调大使用内存上限。

  4. 由于window系统上java使用内存的限制(大约在1GB),请避免在window系统上使用较大的语料进行训练。

开源协议

  1. THUCTC面向国内外大学、研究所、企业以及个人研究者免费开放源。

  2. 如有机构或个人拟将THUCTC用于商业目的,请发邮件至[email protected]洽谈技术许可协议。

  3. 欢迎对该工具包的任何宝贵意见和建议,请发邮件至[email protected]

  4. 如果您在THUCTC基础上发表论文或取得科研成果,请您在发表论文和申报成果时声明“使用了清华大学THUCTC”,并按如下格式引用:

    • 中文:郭志芃,赵宇,郑亚斌,司宪策,刘知远,孙茂松. THUCTC:一个高效的中文文本分类工具包. 2016.

    • 英文: Zhipeng Guo, Yu Zhao, Yabin Zheng, Xiance Si, Zhiyuan Liu, Maosong Sun. THUCTC: An Efficient Chinese Text Classifier. 2016.

  5. 本工具包采用LibSVMLiblinear实现分类算法,特此致谢。该模块遵守LibSVM/Liblinear工具包指定的协议。

相关论文

  • Jingyang Li, Maosong Sun. Scalable Term Selection for Text Categorization. Proc. of the 2007 Joint Conference on Empirical Methods in Natural Language Processing and Computational Natural Language Learning (EMNLP-CoNLL), Prague, Czech Republic, 2007, pp. 774-782.

  • Jingyang Li, Maosong Sun, Xian Zhang. A Comparison and Semi-Quantitative Analysis of Words and Character-Bigrams as Features in Chinese Text Categorization. Proc. of the 2006 Joint Conference of the International Committee on Computational Linguistics and the Association for Computational Linguistics (COLING-ACL 2006), Sydney, Australia, 2006, pp. 545-552.

作者

指导教师:Maosong Sun(孙茂松教授)

贡献者:Zhipeng Guo(郭志芃),Yu Zhao(赵宇),Yabin Zheng(郑亚斌),Xiance Si(司宪策),Zhiyuan Liu(刘知远).

使用者如有任何问题、建议和意见,欢迎发邮件至 [email protected]

More Repositories

1

GNNPapers

Must-read papers on graph neural networks (GNN)
15,490
star
2

WantWords

An open-source online reverse dictionary.
JavaScript
6,933
star
3

OpenPrompt

An Open-Source Framework for Prompt-Learning.
Python
4,323
star
4

OpenNRE

An Open-Source Package for Neural Relation Extraction (NRE)
Python
4,322
star
5

PromptPapers

Must-read papers on prompt-based tuning for pre-trained language models.
4,059
star
6

OpenKE

An Open-Source Package for Knowledge Embedding (KE)
Python
3,813
star
7

PLMpapers

Must-read Papers on pre-trained language models.
3,161
star
8

NRLPapers

Must-read papers on network representation learning (NRL) / network embedding (NE)
TeX
2,524
star
9

UltraChat

Large-scale, Informative, and Diverse Multi-round Chat Data (and Models)
Python
2,225
star
10

THULAC-Python

An Efficient Lexical Analyzer for Chinese
Python
1,997
star
11

OpenNE

An Open-Source Package for Network Embedding (NE)
Python
1,683
star
12

KRLPapers

Must-read papers on knowledge representation learning (KRL) / knowledge embedding (KE)
TeX
1,532
star
13

TAADpapers

Must-read Papers on Textual Adversarial Attack and Defense
Python
1,505
star
14

ERNIE

Source code and dataset for ACL 2019 paper "ERNIE: Enhanced Language Representation with Informative Entities"
Python
1,408
star
15

KB2E

Knowledge Graph Embeddings including TransE, TransH, TransR and PTransE
C++
1,360
star
16

NREPapers

Must-read papers on neural relation extraction (NRE)
TeX
1,028
star
17

OpenDelta

A plug-and-play library for parameter-efficient-tuning (Delta Tuning)
Python
991
star
18

WebCPM

Official codes for ACL 2023 paper "WebCPM: Interactive Web Search for Chinese Long-form Question Answering"
HTML
977
star
19

OpenCLaP

Open Chinese Language Pre-trained Model Zoo
977
star
20

RCPapers

Must-read papers on Machine Reading Comprehension
890
star
21

ToolLearningPapers

865
star
22

NRE

Neural Relation Extraction, including CNN, PCNN, CNN+ATT, PCNN+ATT
C++
812
star
23

THULAC

An Efficient Lexical Analyzer for Chinese
C++
790
star
24

FewRel

A Large-Scale Few-Shot Relation Extraction Dataset
Python
727
star
25

THUOCL

THUOCL(THU Open Chinese Lexicon)中文词库
697
star
26

Chinese_Rumor_Dataset

中文谣言数据
693
star
27

OpenAttack

An Open-Source Package for Textual Adversarial Attack.
Python
682
star
28

DocRED

Dataset and codes for ACL 2019 DocRED: A Large-Scale Document-Level Relation Extraction Dataset.
Python
609
star
29

OpenHowNet

Core Data of HowNet and OpenHowNet Python API
Python
608
star
30

TensorFlow-TransX

An implementation of TransE and its extended models for Knowledge Representation Learning on TensorFlow
Python
514
star
31

LegalPapers

Must-read Papers on Legal Intelligence
465
star
32

CAIL

Chinese AI & Law Challenge
449
star
33

OpenMatch

An Open-Source Package for Information Retrieval.
Python
447
star
34

BERT-KPE

Python
443
star
35

Fast-TransX

An Efficient implementation of TransE and its extended models for Knowledge Representation Learning
C++
401
star
36

TensorFlow-Summarization

Python
390
star
37

Few-NERD

Code and data of ACL 2021 paper "Few-NERD: A Few-shot Named Entity Recognition Dataset"
Python
385
star
38

SOS4NLP

Survey of Surveys for Natural Language Processing (SOS4NLP)
327
star
39

THULAC-Java

An Efficient Lexical Analyzer for Chinese
Java
325
star
40

BMCourse

The repo for Tsinghua summer course: Interdisciplinary Seminar on Big Models
Python
321
star
41

InfLLM

The code of our paper "InfLLM: Unveiling the Intrinsic Capacity of LLMs for Understanding Extremely Long Sequences with Training-Free Memory"
Python
287
star
42

NSC

Neural Sentiment Classification
Python
286
star
43

LLaVA-UHD

LLaVA-UHD: an LMM Perceiving Any Aspect Ratio and High-Resolution Images
Python
276
star
44

DeltaPapers

Must-read Papers of Parameter-Efficient Tuning (Delta Tuning) Methods on Pre-trained Models.
273
star
45

Chinese_NRE

Source code for ACL 2019 paper "Chinese Relation Extraction with Multi-Grained Information and External Linguistic Knowledge"
Python
268
star
46

PL-Marker

Source code for "Packed Levitated Marker for Entity and Relation Extraction"
Python
255
star
47

LEGENT

Open Platform for Embodied Agents
Python
250
star
48

SE-WRL

Improved Word Representation Learning with Sememes
C
197
star
49

SCPapers

Must-read Papers on Sememe Computation
196
star
50

KnowledgeablePromptTuning

kpt code
Python
192
star
51

CANE

Source code and datasets of "CANE: Context-Aware Network Embedding for Relation Modeling"
Python
191
star
52

JointNRE

Joint Neural Relation Extraction with Text and KGs
Python
187
star
53

HATT-Proto

Code and dataset of AAAI2019 paper Hybrid Attention-Based Prototypical Networks for Noisy Few-Shot Relation Classification
Python
185
star
54

LegalPLMs

Source code and checkpoints for legal pre-trained language models.
Python
169
star
55

NLP-THU

NLP Course Material & QA
168
star
56

KernelGAT

The source codes for Fine-grained Fact Verification with Kernel Graph Attention Network.
Python
161
star
57

PTR

Prompt Tuning with Rules
Python
155
star
58

EntityDuetNeuralRanking

Entity-Duet Neural Ranking Model
Python
153
star
59

OOP-THU

OOP Course Material & QA
149
star
60

OpenBackdoor

An open-source toolkit for textual backdoor attack and defense (NeurIPS 2022 D&B, Spotlight)
Python
148
star
61

Auto_CLIWC

Code for Chinese LIWC Lexicon Expansion via Hierarchical Classification of Word Embeddings with Sememe Attention (AAAI18)
Python
142
star
62

attribute_charge

The source code of our COLING'18 paper "Few-Shot Charge Prediction with Discriminative Legal Attributes".
Python
128
star
63

ConceptFlow

Python
119
star
64

THUCKE

THU Chinese Keyphrase Extraction Toolkit
C++
118
star
65

CAIL2018

Python
112
star
66

Neural-Snowball

Code and dataset of AAAI2020 Paper Neural Snowball for Few-Shot Relation Learning
Python
112
star
67

KR-EAR

Knowledge Representation Learning with Entities, Attributes and Relations
C++
111
star
68

ChatEval

Codes for our paper "ChatEval: Towards Better LLM-based Evaluators through Multi-Agent Debate"
Python
109
star
69

MultiRD

Code and data of the AAAI-20 paper "Multi-channel Reverse Dictionary Model"
Python
106
star
70

TransNet

Source code and datasets of IJCAI2017 paper "TransNet: Translation-Based Network Representation Learning for Social Relation Extraction".
Jupyter Notebook
103
star
71

RE-Context-or-Names

Bert-based models(BERT, MTB, CP) for relation extraction.
Python
101
star
72

AGE

Source code and dataset for KDD 2020 paper "Adaptive Graph Encoder for Attributed Graph Embedding"
Python
99
star
73

TopJudge

Python
97
star
74

Prompt-Transferability

On Transferability of Prompt Tuning for Natural Language Processing
Python
97
star
75

GEAR

Source code for ACL 2019 paper "GEAR: Graph-based Evidence Aggregating and Reasoning for Fact Verification"
Python
95
star
76

HNRE

Hierarchical Neural Relation Extraction
Python
95
star
77

LEVEN

Source code and dataset for ACL2022 Findings Paper "LEVEN: A Large-Scale Chinese Legal Event Detection dataset"
Python
94
star
78

SememePSO-Attack

Code and data of the ACL 2020 paper "Word-level Textual Adversarial Attacking as Combinatorial Optimization"
Python
86
star
79

HMEAE

Source code for EMNLP-IJCNLP 2019 paper "HMEAE: Hierarchical Modular Event Argument Extraction".
Python
85
star
80

XQA

Dataset and baseline for ACL 2019 paper "XQA: A Cross-lingual Open-domain Question Answering Dataset"
Python
84
star
81

ERICA

Source code for ACL 2021 paper "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive Learning"
Python
83
star
82

CLAIM

78
star
83

TKRL

Representation Learning of Knowledge Graphs with Hierarchical Types (IJCAI-2016)
C++
76
star
84

TLNN

Source code for EMNLP-IJCNLP 2019 paper "Event Detection with Trigger-Aware Lattice Neural Network".
Python
75
star
85

NeuIRPapers

Must-read Papers on Neural Information Retrieval
72
star
86

MMDW

Max-margin DeepWalk
Java
71
star
87

KV-PLM

Source code for "A Deep-learning System Bridging Molecule Structure and Biomedical Text with Comprehension Comparable to Human Professionals"
Python
71
star
88

KNET

Neural Entity Typing with Knowledge Attention
Python
69
star
89

SelectiveMasking

Source code for "Train No Evil: Selective Masking for Task-Guided Pre-Training"
Python
68
star
90

MoEfication

Python
66
star
91

Adv-ED

Source code and dataset for NAACL 2019 paper "Adversarial Training for Weakly Supervised Event Detection".
Python
66
star
92

CorefBERT

Source code for EMNLP 2020 paper "Coreferential Reasoning Learning for Language Representation"
Python
65
star
93

ConversationQueryRewriter

Code and Data for SIGIR 2020 Paper "Few-Shot Generative Conversational Query Rewriting"
Roff
63
star
94

Ouroboros

Ouroboros: Speculative Decoding with Large Model Enhanced Drafting (EMNLP 2024 main)
Python
62
star
95

MuGNN

Source code for ACL2019 paper "Multi-Channel Graph Neural Network for Entity Alignment".
Python
61
star
96

sememe_prediction

Codes for Lexical Sememe Prediction via Word Embeddings and Matrix Factorization (IJCAI 2017).
Python
60
star
97

DIAG-NRE

Source code for ACL 2019 paper "DIAG-NRE: A Neural Pattern Diagnosis Framework for Distantly Supervised Neural Relation Extraction".
Python
59
star
98

topical_word_embeddings

Topical Word Embeddings
Python
57
star
99

QuoteR

Official code and data of the ACL 2022 paper "QuoteR: A Benchmark of Quote Recommendation for Writing"
Python
57
star
100

paragraph2vec

Paragraph Vector Implementation
Python
56
star