nlp-lab/Project/Tools/emoji_plotting.ipynb

201 lines
4.8 KiB
Plaintext
Raw Normal View History

2018-07-16 11:54:56 +02:00
{
"cells": [
{
"cell_type": "code",
2018-07-16 12:10:35 +02:00
"execution_count": 1,
2018-07-16 11:54:56 +02:00
"metadata": {},
"outputs": [],
"source": [
2018-07-16 12:10:35 +02:00
"%matplotlib widget"
2018-07-16 11:54:56 +02:00
]
},
{
"cell_type": "code",
2018-07-16 12:10:35 +02:00
"execution_count": 2,
2018-07-16 11:54:56 +02:00
"metadata": {},
"outputs": [],
"source": [
"def sentiment_score(s):\n",
" #(pos, neg, neu)^T\n",
" return s[0] - s[1]"
]
},
{
"cell_type": "code",
2018-07-16 12:10:35 +02:00
"execution_count": 3,
2018-07-16 11:54:56 +02:00
"metadata": {},
"outputs": [],
"source": [
"import Emoji_Distance as edist\n",
2018-07-16 12:10:35 +02:00
"import numpy as np\n",
"from __future__ import unicode_literals\n",
"\n",
2018-07-20 11:54:14 +02:00
"import matplotlib.pyplot as plt\n",
"import matplotlib\n"
2018-07-16 11:54:56 +02:00
]
},
{
"cell_type": "code",
2018-07-16 12:10:35 +02:00
"execution_count": 4,
2018-07-16 11:54:56 +02:00
"metadata": {},
"outputs": [],
"source": [
"list_emoticon_scores = np.array([sentiment_score(x) for x in edist.list_sentiment_emoticon_vectors])"
]
},
{
"cell_type": "code",
2018-07-20 11:54:14 +02:00
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"matplotlib.rc('font', family='symbola', size=16)"
]
},
{
"cell_type": "code",
"execution_count": 6,
2018-07-16 11:54:56 +02:00
"metadata": {},
"outputs": [],
"source": [
"def plot_emoji_list(sentiment_vectors, unicode_repr, title=\"Emoji Space\"):\n",
" \n",
" # sentiment score axis\n",
" X = np.array([sentiment_score(x) for x in sentiment_vectors])\n",
" \n",
" # neutral axis:\n",
" Y = np.array([x[2] for x in sentiment_vectors])\n",
" \n",
2018-07-20 11:54:14 +02:00
" fig_1, ax_1 = plt.subplots(figsize=(15,10))\n",
" plt.title(title + \" -- sentiment-plot\")\n",
2018-07-16 11:54:56 +02:00
" plt.xlabel(\"sentiment score\")\n",
" plt.ylabel(\"neutrality\")\n",
" plt.xlim([-1,1])\n",
" for i in range(len(X)):\n",
" plt.text(X[i], Y[i], unicode_repr[i])\n",
2018-07-20 11:54:14 +02:00
" plt.savefig(title + \" -- sentiment-plot.png\", bbox_inches='tight')\n",
" \n",
" # sentiment score axis\n",
" X = np.array([x[0] for x in sentiment_vectors])\n",
" \n",
" # neutral axis:\n",
" Y = np.array([x[1] for x in sentiment_vectors])\n",
" \n",
" fig_2, ax_2 = plt.subplots(figsize=(15,10))\n",
" plt.title(title + \" -- positive-negative-plot\")\n",
" plt.xlabel(\"positive\")\n",
" plt.ylabel(\"negative\")\n",
" for i in range(len(X)):\n",
" plt.text(X[i], Y[i], unicode_repr[i])\n",
" plt.savefig(title + \" -- positive-negative-plot.png\", bbox_inches='tight')\n",
2018-07-16 12:11:39 +02:00
" #plt.show()\n",
2018-07-20 11:54:14 +02:00
" "
2018-07-16 11:54:56 +02:00
]
},
{
"cell_type": "code",
2018-07-20 11:54:14 +02:00
"execution_count": 7,
2018-07-16 11:54:56 +02:00
"metadata": {},
"outputs": [
{
"data": {
2018-07-16 12:10:35 +02:00
"application/vnd.jupyter.widget-view+json": {
2018-07-20 11:54:14 +02:00
"model_id": "130af70105914e61a07d14248df3d114",
2018-07-16 12:10:35 +02:00
"version_major": 2,
"version_minor": 0
},
2018-07-16 11:54:56 +02:00
"text/plain": [
2018-07-16 12:10:35 +02:00
"FigureCanvasNbAgg()"
2018-07-16 11:54:56 +02:00
]
},
"metadata": {},
"output_type": "display_data"
2018-07-16 12:11:39 +02:00
},
{
"data": {
2018-07-20 11:54:14 +02:00
"application/vnd.jupyter.widget-view+json": {
"model_id": "e6a1d7210b874215bb8d0e576b4ca133",
"version_major": 2,
"version_minor": 0
},
2018-07-16 12:11:39 +02:00
"text/plain": [
2018-07-20 11:54:14 +02:00
"FigureCanvasNbAgg()"
2018-07-16 12:11:39 +02:00
]
},
"metadata": {},
2018-07-20 11:54:14 +02:00
"output_type": "display_data"
2018-07-16 11:54:56 +02:00
}
],
"source": [
"plot_emoji_list(sentiment_vectors=edist.list_sentiment_emoticon_vectors, unicode_repr=edist.list_emoticon_emojis, title=\"Emoticon Emoji space\")"
]
},
{
"cell_type": "code",
2018-07-20 11:54:14 +02:00
"execution_count": 8,
2018-07-16 11:54:56 +02:00
"metadata": {},
2018-07-16 12:11:39 +02:00
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2018-07-20 11:54:14 +02:00
"model_id": "26d17ff521604443ab1da9ff63d1108a",
2018-07-16 12:11:39 +02:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"FigureCanvasNbAgg()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
2018-07-20 11:54:14 +02:00
"application/vnd.jupyter.widget-view+json": {
"model_id": "188c871e705040c1b17bca0e10d5c5fe",
"version_major": 2,
"version_minor": 0
},
2018-07-16 12:11:39 +02:00
"text/plain": [
2018-07-20 11:54:14 +02:00
"FigureCanvasNbAgg()"
2018-07-16 12:11:39 +02:00
]
},
"metadata": {},
2018-07-20 11:54:14 +02:00
"output_type": "display_data"
2018-07-16 12:11:39 +02:00
}
],
2018-07-16 11:54:56 +02:00
"source": [
"plot_emoji_list(sentiment_vectors=edist.list_sentiment_vectors, unicode_repr=edist.list_emojis, title=\"Full Emoji space\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}