Code for Paper: “Low-Resource” Text Classification: A Parameter-Free Classification Method with Compressors
This paper is accepted to Findings of ACL2023.
Getting Started
This codebase is available on pypi.org via:
pip install npc-gzip
Usage
See the examples directory for example usage.
Testing
This package utilizes poetry to maintain its dependencies and pytest to execute tests. To get started running the tests:
poetry shell
poetry install
pytest
Original Codebase
Require
See requirements.txt.
Install requirements in a clean environment:
conda create -n npc python=3.7
conda activate npc
pip install -r requirements.txt
Run
python main_text.py
By default, this will only use 100 test and training samples per class as a quick demo. They can be changed by --num_test, --num_train.
--compressor <gzip, lzma, bz2>
--dataset <AG_NEWS, SogouNews, DBpedia, YahooAnswers, 20News, Ohsumed_single, R8, R52, kinnews, kirnews, swahili, filipino> [Note that for small datasets like kinnews, default 100-shot is too big, need to set --num_test and --num_train.]
--num_train <INT>
--num_test <INT>
--data_dir <DIR> [This needs to be specified for R8, R52 and Ohsumed.]
--all_test [This will use the whole test dataset.]
--all_train
--record [This will record the distance matrix in order to save for the future use. It's helpful when you when to run on the whole dataset.]
--test_idx_start <INT>
--test_idx_end <INT> [These two args help us to run on a certain range of test set. Also helpful for calculating the distance matrix on the whole dataset.]
--para [This will use multiprocessing to accelerate.]
--output_dir <DIR> [The output directory to save information of tested indices or distance matrix.]
Calculate Accuracy (Optional)
If we want to calculate accuracy from recorded distance file <DISTANCE DIR>, use
python main_text.py --record --score --distance_fn <DISTANCE DIR>
to calculate accuracy. Otherwise, the accuracy will be calculated automatically using the command in the last section.
Use Custom Dataset
You can use your own custom dataset by passing custom to --dataset; pass the data directory that contains train.txt and test.txt to --data_dir; pass the class number to the --class_num.
Both train.txt and test.txt are expected to have the format {label}\t{text} per line.
You can change the delimiter according to you dataset by changing delimiter in load_custom_dataset() in data.py.
Metadata
Release files for npc-gzip 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| npc_gzip-0.1.1.tar.gz | 11.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| npc_gzip-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.7 kB
Release files / npc_gzip-0.1.1.tar.gz
| Download URL | npc_gzip-0.1.1.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d81142055516d0ce4c0eedfec87a53cdfe0cf7b3cd4f59f9c033a219355e2e1e
|
|
BLAKE2b-256 checksum How to use checksums |
c0bc936d3d8828a6c5e739863b03490a6048b484a67b797c0e55c6dcf48764db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / npc_gzip-0.1.1-py3-none-any.whl
| Download URL | npc_gzip-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8051e6cc24ad2f19028f3a1f9427790e742fb5dd32fb1c669de79928c532264
|
|
BLAKE2b-256 checksum How to use checksums |
9fa8bb0b75702a650d4757f6db171f8bd82264c0fd43dbb010c09921ef7d6c06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for npc-gzip 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.