Skip to main content

TextKNNClassifier

Build codecov Code style: black L-GPL License pages

TextKNNClassifier is a k-nearest neighbors classifier for text data. It uses a compression algorithm to compute the distance between texts and predicts the label of a test entry based on the labels of the k-nearest neighbors in the training data.

Installation

You can install TextKNNassifier using pip:

pip install textknnassifier

Usage

Here's an example of how to use TextKNNClassifier:

from textknnassifier import classifier

training_text = [
    "This is a test",
    "Another test",
    "General Tarkin",
    "General Grievous",
]
training_labels = ["test", "test", "star_wars", "star_wars"]
testing_data = [
    "This is a test",
    "Testing here too!",
    "General Kenobi",
    "General Skywalker",
]

KNN = classifier.TextKNNClassifier(n_neighbors=2)
KNN.fit(training_data, training_labels)
predicted_labels = KNN.predict(testing_data)

print(predicted_labels)
# Output: ['test1', 'test1', 'star_wars', 'star_wars']

In this example, we create a TextKNNClassifier instance and use it to predict the labels of the test entries. The initialization is given n_neighbors=2, this denotes the number of training datapoints to consider for predicting the testing label. The fit method takes two arguments: the training data, and the training labels. It simply stores these values for later use. The predict method takes the testing data as an argument and returns the predicted labels.

References

  • Jiang, Z., Yang, M., Tsirlin, M., Tang, R., Dai, Y., & Lin, J. (2023, July). “Low-Resource” Text Classification: A Parameter-Free Classification Method with Compressors. In Findings of the Association for Computational Linguistics: ACL 2023 (pp. 6810-6828).

Metadata

Release files for textknnassifier 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for textknnassifier 0.0.1
File Size Uploaded Provenance
textknnassifier-0.0.1.tar.gz 12.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for textknnassifier 0.0.1
File Interpreter ABI Platform
textknnassifier-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.5 kB

Release files / textknnassifier-0.0.1.tar.gz

Download URL textknnassifier-0.0.1.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
aa5661180ebd054f829b050eddb6d2efdbaa4c9dc153be28cdcaa8f57dd342bb
BLAKE2b-256 checksum
How to use checksums
98f263482d62ee176ec69cf4fc127c06b1d3d09cc1a7dccae15b51cc0c4a2293
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / textknnassifier-0.0.1-py3-none-any.whl

Download URL textknnassifier-0.0.1-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ef0ae81f3cd2eca0b920ab15d3f49a6779cb758c168a8d7390a60a26bdb5a50c
BLAKE2b-256 checksum
How to use checksums
66e274c4957950df458f70ea31b709b883c367c68f184d0632ac42cef925992a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for textknnassifier 0.0.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page