Skip to main content

w2widget

Widget for exploring and sampling words from text data through word2vec models in order to construct topic dictionaries.

Package content

The w2widget package contains two modules:

  • doc2vec.py
  • widget.py

Examples

In the widget_example.ipynb you can play with the widget from pretrained data from Reuters dataset.

If you want to see an example of the data-workflow generating the necessary input, check out workflow_example.ipynb.

Doc2Vec

This module helps with calculating and handling doc2vec. The approach applied is that every document's vector is calculated by taking a weighted (ie. based on inverse frequencies) average of the document's word vectors.

from w2widget.doc2vec import calculate_inverse_frequency, Doc2Vec

# Calculate word weigts from inverse frequency
word_weights = calculate_inverse_frequency(document_tokens)

# Initiate the model
dv_model = Doc2Vec(wv_model, word_weights)

# Add documents and calculated the document vectors
dv_model.add_doc2vec(document_tokens)

# reduce the dimensions
dv_model.reduce_dimensions()

# Store the embeddings
two_dim_doc_embedding = dv_model.TSNE_embedding_array

Widget

This widget module displays the results from:

  • A gensim word2vec model,
  • it's 2-dimensional embedding (ie. TSNE).
  • The custom implemented doc2vec model,
  • it's 2-dimensional embedding (ie. TSNE).
  • A list of tokenized documents with whitespaces and
  • optionally a list of initial search words
from w2widget.widget import Widget

wv_widget = Widget(
    wv_model,
    two_dim_word_embedding,
    tokens_with_ws
    dv_model=None,
    two_dim_doc_embedding=None,
    initial_search_words=[],
)

wv_widget.display_widget()

You can save the topics to a json file from the widget, or access them from the dictionary stored in wv_widget.topics.

Metadata

Release files for w2widget 0.0.3

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

Source distribution (sdist)

Source distribution for w2widget 0.0.3
File Size Uploaded
w2widget-0.0.3.tar.gz 13.2 kB Details

Built distribution (wheel)

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

Total release size: 26.4 kB

Release files / w2widget-0.0.3.tar.gz

Download URL w2widget-0.0.3.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7e4bec16d5f51c55ef1d24c002046b1bd2fa24555aff7e27de7b09e3ce7bd6a3
BLAKE2b-256 checksum
How to use checksums
fcb763b450dba9598b8b5a55c329dfcfa65336b1949e119a6c710274b01a9ddd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release files / w2widget-0.0.3-py3-none-any.whl

Download URL w2widget-0.0.3-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
748a5f5332adeb5b254a8911734d2f263895fb1999cb9624b9bafdeec269e4c5
BLAKE2b-256 checksum
How to use checksums
834d9545324981b025bc123f01ed79df1c530e75f0c158c8027c14336c8e2306
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.15

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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