{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Defining a custom corpus for plotting text\n\nBy default, the text samples will be transformed into a vector of word counts\nand then modeled using Latent Dirichlet Allocation (# of topics = 100) using a\nmodel fit to a large sample of wikipedia pages. However, you can optionally\npass your own text to fit the semantic model. To do this define corpus as a\nlist of documents (strings). A topic model will be fit on the fly and the text\nwill be plotted.\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\ntext_samples = ['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(text_samples, 'o', corpus=text_samples)" ] } ], "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 }