Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression module #1455

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix trim trailing whitespace and mixed line ending
Signed-off-by: mariliatd <mariliatd@gmail.com>
mariliatd committed Nov 19, 2023
commit 47a21bb7b8da403a91735a5613e299139ffb03db
10 changes: 7 additions & 3 deletions river/compression/text_compression_classifier.py
Original file line number Diff line number Diff line change
@@ -20,8 +20,10 @@ def learn_one(self, x, y):
self.label_documents[y] = self.label_documents.get(y, "") + x_str

# Compress new document
zstd_compressor = zstandard.ZstdCompressor(level=self.compression_level).compress(x_str.encode("utf-8"))

zstd_compressor = zstandard.ZstdCompressor(level=self.compression_level).compress(
x_str.encode("utf-8")
)

# Create a dictionary using the compressed document
if y not in self.compression_contexts:
data_source = zstd_compressor
@@ -44,7 +46,9 @@ def predict_one(self, x):
for label, compressor in self.compression_contexts.items():
# Concatenate and compress
concatenated_doc = (self.label_documents[label] + x_str).encode("utf-8")
new_compressed_size = len(zstandard.ZstdCompressor(level=self.compression_level).compress(concatenated_doc))
new_compressed_size = len(
zstandard.ZstdCompressor(level=self.compression_level).compress(concatenated_doc)
)

# Calculate size increase (you can define your own metric here)
size_increase = new_compressed_size - len(compressor.as_bytes())