{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plotting text\n\nTo plot text, simply pass the text data to the plot function. By default, the\ntext samples will be transformed into a vector of word counts and then modeled\nusing Latent Dirichlet Allocation (# of topics = 100) using a model fit to a\nlarge sample of wikipedia pages. If you specify semantic=None, the word\ncount vectors will be plotted. To convert the text t0 a matrix (or list of\nmatrices), we also expose the format_data function.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Code source: Andrew Heusser\n# License: MIT\n\n# load hypertools\nimport hypertools as hyp\n\n# load the data\ndata = [['i like cats alot', 'cats r pretty cool', 'cats are better than dogs'],\n ['dogs rule the haus', 'dogs are my jam', 'dogs are a mans best friend'],\n 'i haz a cheezeburger?']\n\n# plot it\nhyp.plot(data, 'o')\n\n# convert text to matrix without plotting\n# mtx = hyp.tools.format_data(data, vectorizer='TfidfVectorizer', semantic='NMF')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.4" } }, "nbformat": 4, "nbformat_minor": 0 }