Skip to main content

Generative Text Compression with Agglomerative Clustering Summarization (GTCACS)

Project description

A library for topic modeling based on the algorithm: Generative Text Compression with Agglomerative Clustering Summarization (GTCACS).


Installation

Install these packages first:

pip3 install scipy==1.4.1 numpy==1.19.1 scikit-learn==0.23.1 tensorflow==2.2.0 tqdm==4.48.0

Use the package manager pip to install gtcacs.

pip3 install gtcacs

Usage

from sklearn.datasets import fetch_20newsgroups
from gtcacs.topic_modeling import GTCACS

# load dataset
corpus, labels = fetch_20newsgroups(subset='all', return_X_y=True, download_if_missing=False)

# set stop words
eng_stopwords = {'i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're", "you've", "you'll", "you'd", 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', "she's", 'her', 'hers', 'herself', 'it', "it's", 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', "that'll", 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above', 'below', 'to', 'from', 'up', 'down', 'in', 'out', 'on', 'off', 'over', 'under', 'again', 'further', 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how', 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other', 'some', 'such', 'no', 'nor', 'not', 'only', 'own', 'same', 'so', 'than', 'too', 'very', 's', 't', 'can', 'will', 'just', 'don', "don't", 'should', "should've", 'now', 'd', 'll', 'm', 'o', 're', 've', 'y', 'ain', 'aren', "aren't", 'couldn', "couldn't", 'didn', "didn't", 'doesn', "doesn't", 'hadn', "hadn't", 'hasn', "hasn't", 'haven', "haven't", 'isn', "isn't", 'ma', 'mightn', "mightn't", 'mustn', "mustn't", 'needn', "needn't", 'shan', "shan't", 'shouldn', "shouldn't", 'wasn', "wasn't", 'weren', "weren't", 'won', "won't", 'wouldn', "wouldn't"}

# instantiate the GTCACS object
gtcacs_obj = GTCACS(
        num_topics=20,                # number of topics
        max_num_words=50,             # maximum number of terms to consider
        max_df=0.95,                  # maximum document frequency
        min_df=15,                    # minimum document frequency
        stopwords=eng_stopwords,      # stopwords set
        ngram_range=(1, 2),           # range for ngram
        max_features=None,            # maximum number of terms to consider (max vocabulary size)
        lowercase=True,               # flag for convert to lowercase
        num_epoches=5,                # number of epochs
        batch_size=128,               # number of documents in a batch
        gen_learning_rate=0.005,      # learning rate for optimize the generative part
        discr_learning_rate=0.005,    # learning rate for optimize the discriminative part
        random_seed_size=100,         # dimension of generator input layer
        generator_hidden_dim=512,     # dimension of generator hidden layer
        document_dim=None,            # dimension of generator output layer and discriminator's input/output layer
        latent_space_dim=64,          # dimension of discriminator latent space
        discriminator_hidden_dim=256  # dimension of discriminator hidden layer
)

# compuation on corpus (dimensional reduction, clustering, summarization)
gtcacs_obj.extract_topics(corpus=corpus)

# get the extracted clusters of words
topics = gtcacs_obj.get_topics_words()
for i, topic in enumerate(topics):
    print(">>> TOPIC", i + 1, topic)

# get the topics distribution scores for each document
corpus_transf = gtcacs_obj.get_topics_distribution_scores()
print(corpus_transf)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gtcacs-0.0.3.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file gtcacs-0.0.3.tar.gz.

File metadata

  • Download URL: gtcacs-0.0.3.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

File hashes

Hashes for gtcacs-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ee5f39da8d79f8e3058f106759db59c813eefcd57d9a177a49e21b309f0e52a5
MD5 57b4ca50932f76b94d63c0591f1f2d2d
BLAKE2b-256 9c37b5c4a809ac093817cb6d0e3a203983ed6278bdf2c09c0cdd64ab16eba511

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page