nlp-lab/Project/Tools/emoji_plotting.ipynb

132 lines
2.9 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",
"import matplotlib.pyplot as plt"
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-16 12:10:35 +02:00
"execution_count": 5,
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",
" plt.title(title)\n",
" 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",
" plt.show()\n",
" "
]
},
{
"cell_type": "code",
2018-07-16 12:10:35 +02:00
"execution_count": 6,
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": {
"model_id": "192190b95ac94d5bb04a5f2b73c7e481",
"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"
}
],
"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-16 12:10:35 +02:00
"execution_count": 7,
2018-07-16 11:54:56 +02:00
"metadata": {},
2018-07-16 12:10:35 +02:00
"outputs": [],
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
}