{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plotting State of the Union Addresses with Text Analysis\n\nThis example demonstrates how to plot text data using hypertools. We create\nsample State of the Union address excerpts covering different political themes\nand visualize them in a reduced dimensional space. By default, hypertools \ntransforms the text data using a topic model to capture semantic relationships \nbetween different speech segments.\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\n# Note: 'sotus' loads a text processing model, not the actual SOTU speeches\n# We'll create sample text data to demonstrate text plotting capabilities\nprint(\"Creating sample State of the Union demonstration...\")\n\n# Sample State of the Union excerpts for demonstration\nsample_speeches = [\n \"Tonight I can report to the nation that America is stronger, America is more secure, and America is respected again. After years of decline, our economy is growing again.\",\n \"We gather tonight knowing that this generation of Americans has been tested by crisis and proven worthy of our founding principles. The state of our union is strong.\",\n \"As we work together to advance America's interests, we must also recognize the threats we face. We will rebuild our military and defend our nation.\",\n \"Education is the great equalizer in America. We must ensure every child has access to quality education regardless of their zip code.\",\n \"Healthcare should be affordable and accessible to all Americans. We will work to reduce costs while maintaining quality care.\",\n \"We must secure our borders and have an immigration system that works for America and reflects our values.\",\n \"Innovation and technology will drive America forward in the 21st century. We must invest in research and development.\",\n \"Climate change poses real challenges, and we will address them with American innovation and determination.\",\n \"Our military is the finest in the world, and we will ensure our veterans receive the care they have earned.\",\n \"The economy is strong, unemployment is low, and American families are prospering like never before.\"\n]\n\n# Add labels for the different themes\nlabels = ['Security', 'Unity', 'Defense', 'Education', 'Healthcare', \n 'Immigration', 'Innovation', 'Environment', 'Veterans', 'Economy']\n\n# Plot the sample speeches with labels\nhyp.plot(sample_speeches, labels=labels)" ] } ], "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 }