Logo Lanfrica

hotchpotch/ncd_classifier

Domain:

natural language processing

Record type:

software
Creator:
hot
Host:
NCD Classifier is a Python library that implements the method proposed in the paper "Low-Resource" Text Classification: A Parameter-Free Classification Method with Compressors". # NCD Classifier NCD Classifier is a Python library that implements the method proposed in the paper "Low-Resource" Text Classification: A Parameter-Free Classification Method with Compressors". This method is a non-parametric alternative to deep neural networks for text classification, using a combination of a simple compressor like gzip with a k-nearest-neighbor classifier. It is easy to use, lightweight, and does not require any training parameters, making it suitable for low-resource languages and few-shot settings. This code was implemented with reference to github.com. This library is designed with a scikit-learn interface, making it familiar and straightforward for users with experience in scikit-learn. ## Table of Contents - Installation - Usage - License ## Installation This library can be installed using pip: ```bash pip install ncd-classifier ``` ## Usage Here is a simple example of how to use the NCD Classifier: ```python from ncd_classifier import NCDClassifier from sklearn.metrics import accuracy_score, confusion_matrix X_train = ["hello world", "hello?", "world?", "good evening"] y_train = [0, 0, 0, 1] X_test = ["hello", "world"] y_test = [0, 0] classifier = NCDClassifier(n_jobs=-1, k=3, show_progress=True, label_frequency_weighting=False) classifier.fit(X_train, y_train) y_pred = classifier.predict(X_test) print(y_pred) print(accuracy_score(y_test, y_pred)) print(confusion_matrix(y_test, y_pred)) ``` ## License This code is licensed under the MIT License. # Citation ``` @inproceedings{jiang-etal-2023-low, title = "{``}Low-Resource{''} Text Classification: A Parameter-Free Classification Method with Compressors", author = "Jiang, Zhiying and Yang, Matthew and Tsirlin, Mikhail and Tang, Raphael and Dai, Yiqin and Lin, Jimmy", booktitle = "Findings of the Association for Computational Linguistics: ACL 2023", month = jul, year = "2023", address = "Toronto, Canada", publisher = "Association for Computatio …