aitech-moj/wyk/02_Jezyki.ipynb

1781 lines
392 KiB
Plaintext
Raw Normal View History

2022-03-06 17:51:23 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![Logo 1](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech1.jpg)\n",
"<div class=\"alert alert-block alert-info\">\n",
"<h1> Modelowanie języka</h1>\n",
"<h2> 2. <i>Języki</i> [wykład]</h2> \n",
"<h3> Filip Graliński (2022)</h3>\n",
"</div>\n",
"\n",
"![Logo 2](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech2.jpg)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Języki i ich prawa\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Jakim rozkładom statystycznym podlegają języki?\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Język naturalny albo „Pan Tadeusz” w liczbach\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Przygotujmy najpierw „infrastrukturę” do *segmentacji* tekstu na różnego rodzaju jednostki.\n",
"Używać będziemy generatorów.\n",
"\n",
"**Pytanie** Dlaczego generatory zamiast list?\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Księga pierwsza\\r\\n\\r\\n\\r\\n\\r\\nGospodarstwo\\r\\n\\r\\nPowrót pani'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import requests\n",
"\n",
"url = 'https://wolnelektury.pl/media/book/txt/pan-tadeusz.txt'\n",
"pan_tadeusz = requests.get(url).content.decode('utf-8')\n",
"\n",
"pan_tadeusz[100:150]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Znaki\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['K',\n",
" 's',\n",
" 'i',\n",
" 'ę',\n",
" 'g',\n",
" 'a',\n",
" ' ',\n",
" 'p',\n",
" 'i',\n",
" 'e',\n",
" 'r',\n",
" 'w',\n",
" 's',\n",
" 'z',\n",
" 'a',\n",
" '\\r',\n",
" '\\n',\n",
" '\\r',\n",
" '\\n',\n",
" '\\r',\n",
" '\\n',\n",
" '\\r',\n",
" '\\n',\n",
" 'G',\n",
" 'o',\n",
" 's',\n",
" 'p',\n",
" 'o',\n",
" 'd',\n",
" 'a',\n",
" 'r',\n",
" 's',\n",
" 't',\n",
" 'w',\n",
" 'o',\n",
" '\\r',\n",
" '\\n',\n",
" '\\r',\n",
" '\\n',\n",
" 'P',\n",
" 'o',\n",
" 'w',\n",
" 'r',\n",
" 'ó',\n",
" 't',\n",
" ' ',\n",
" 'p',\n",
" 'a',\n",
" 'n',\n",
" 'i']"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from itertools import islice\n",
"\n",
"def get_characters(t):\n",
" yield from t\n",
"\n",
"list(islice(get_characters(pan_tadeusz), 100, 150))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'A': 698,\n",
" 'd': 11465,\n",
" 'a': 30979,\n",
" 'm': 10269,\n",
" ' ': 63444,\n",
" 'M': 585,\n",
" 'i': 29353,\n",
" 'c': 14153,\n",
" 'k': 12362,\n",
" 'e': 25343,\n",
" 'w': 14625,\n",
" 'z': 22741,\n",
" '\\r': 10851,\n",
" '\\n': 10851,\n",
" 'P': 1265,\n",
" 'n': 15505,\n",
" 'T': 971,\n",
" 'u': 7699,\n",
" 's': 15255,\n",
" 'y': 13732,\n",
" 'l': 6677,\n",
" 'o': 23050,\n",
" 't': 10757,\n",
" 'j': 6586,\n",
" 'L': 316,\n",
" 'I': 795,\n",
" 'S': 1045,\n",
" 'B': 567,\n",
" 'N': 793,\n",
" '9': 8,\n",
" '7': 2,\n",
" '8': 10,\n",
" '-': 33,\n",
" '3': 3,\n",
" '2': 6,\n",
" '4': 2,\n",
" '5': 2,\n",
" 'K': 683,\n",
" 'ę': 5534,\n",
" 'g': 4775,\n",
" 'p': 8031,\n",
" 'r': 15328,\n",
" 'G': 358,\n",
" 'ó': 3097,\n",
" '—': 720,\n",
" ',': 9130,\n",
" 'ł': 10059,\n",
" 'W': 1258,\n",
" 'ż': 3334,\n",
" 'ś': 2524,\n",
" 'ą': 4794,\n",
" 'Ż': 219,\n",
" 'O': 567,\n",
" 'ź': 414,\n",
" 'b': 5753,\n",
" 'R': 489,\n",
" 'E': 23,\n",
" '!': 1083,\n",
" ':': 1152,\n",
" 'ć': 1956,\n",
" '.': 2380,\n",
" 'D': 552,\n",
" 'J': 729,\n",
" 'C': 556,\n",
" 'h': 3915,\n",
" '(': 76,\n",
" 'f': 386,\n",
" ';': 1445,\n",
" 'ń': 651,\n",
" ')': 76,\n",
" 'Z': 785,\n",
" 'Ś': 71,\n",
" 'U': 184,\n",
" 'F': 47,\n",
" 'é': 43,\n",
" '?': 441,\n",
" '…': 157,\n",
" '«': 540,\n",
" 'H': 309,\n",
" '»': 538,\n",
" 'Ó': 13,\n",
" 'Ł': 24,\n",
" 'x': 3,\n",
" 'v': 5,\n",
" '*': 150,\n",
" 'à': 1,\n",
" 'Ź': 4,\n",
" 'V': 3,\n",
" '/': 19,\n",
" 'Ć': 1,\n",
" 'q': 2,\n",
" '1': 4,\n",
" 'æ': 2,\n",
" '6': 1,\n",
" '0': 1})"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from collections import Counter\n",
"\n",
"c = Counter(get_characters(pan_tadeusz))\n",
"\n",
"c"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Napiszmy pomocniczą funkcję, która zwraca **listę frekwencyjną**.\n",
"\n",
"Counter({' ': 63444, 'a': 30979, 'i': 29353, 'e': 25343, 'o': 23050, 'z': 22741, 'n': 15505, 'r': 15328, 's': 15255, 'w': 14625, 'c': 14153, 'y': 13732, 'k': 12362, 'd': 11465, '\\r': 10851, '\\n': 10851, 't': 10757, 'm': 10269, 'ł': 10059, ',': 9130, 'p': 8031, 'u': 7699, 'l': 6677, 'j': 6586, 'b': 5753, 'ę': 5534, 'ą': 4794, 'g': 4775, 'h': 3915, 'ż': 3334, 'ó': 3097, 'ś': 2524, '.': 2380, 'ć': 1956, ';': 1445, 'P': 1265, 'W': 1258, ':': 1152, '!': 1083, 'S': 1045, 'T': 971, 'I': 795, 'N': 793, 'Z': 785, 'J': 729, '—': 720, 'A': 698, 'K': 683, 'ń': 651, 'M': 585, 'B': 567, 'O': 567, 'C': 556, 'D': 552, '«': 540, '»': 538, 'R': 489, '?': 441, 'ź': 414, 'f': 386, 'G': 358, 'L': 316, 'H': 309, 'Ż': 219, 'U': 184, '…': 157, '\\*': 150, '(': 76, ')': 76, 'Ś': 71, 'F': 47, 'é': 43, '-': 33, 'Ł': 24, 'E': 23, '/': 19, 'Ó': 13, '8': 10, '9': 8, '2': 6, 'v': 5, 'Ź': 4, '1': 4, '3': 3, 'x': 3, 'V': 3, '7': 2, '4': 2, '5': 2, 'q': 2, 'æ': 2, 'à': 1, 'Ć': 1, '6': 1, '0': 1})\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OrderedDict([(' ', 63444),\n",
" ('a', 30979),\n",
" ('i', 29353),\n",
" ('e', 25343),\n",
" ('o', 23050),\n",
" ('z', 22741),\n",
" ('n', 15505),\n",
" ('r', 15328)])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from collections import Counter\n",
"from collections import OrderedDict\n",
"\n",
"def freq_list(g, top=None):\n",
" c = Counter(g)\n",
"\n",
" if top is None:\n",
" items = c.items()\n",
" else:\n",
" items = c.most_common(top)\n",
"\n",
" return OrderedDict(sorted(items, key=lambda t: -t[1]))\n",
"\n",
"freq_list(get_characters(pan_tadeusz), top=8)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_6969/6903746.py:14: UserWarning: Glyph 13 (\r",
") missing from current font.\n",
" plt.savefig(fname)\n"
]
},
{
"data": {
"text/plain": [
"'02_Jezyki/pt-chars.png'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/lib/python3.10/site-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 13 (\r",
") missing from current font.\n",
" fig.canvas.print_figure(bytes_io, **kw)\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAuEAAADCCAYAAADn5xwjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAsGElEQVR4nO3de/wVVb3/8ddbQMULXhBNQf1q0kU9pUJm2U2pI5WFdjSxY2JRpFnasX6G1TnZhdLudtEyMdG8cSiTY2oZaFqRiooB4oUUlTTBO2qo4Of3x1pbhs3s/d3fL9+9v7f38/HYjz2zZtbMmtlrz17z2WtmFBGYmZmZmVnrbNDdBTAzMzMz62/cCDczMzMzazE3ws3MzMzMWsyNcDMzMzOzFnMj3MzMzMysxdwINzMzMzNrsYHdXYDusM0220RbW1t3F8PMzMzM+rBbbrnl0YgYVjatXzbC29ramDt3bncXw8zMzMz6MEn315rm7ihmZmZmZi3mRriZmZmZWYu5EW5mZmZm1mJuhJuZmZmZtZgb4WZmZmZmLdYv747SXdom/3adtCWnvbcbSmJmZmZm3cmRcDMzMzOzFnMj3MzMzMysxdwINzMzMzNrMTfCzczMzMxarKmNcElbSpoh6U5JiyS9SdLWkq6RdE9+36ow/ymSFku6S9JBhfRRkubnaT+UpJy+kaRLc/qNktqauT1mZmZmZl2h2ZHwM4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9WKOR8MOAX0TEEwAR8QDuE25mZmZm1imNRsJfAdwsabqksZLUzEKZmZmZmfVlDTXCI+JLwEhgKnAMcI+kb0h6ZRPLZmZmZmbWJzUaCSffHeWf+bUK2AqYIelbTSqbmZmZmVmf1FCfcEknABOAR4FzgP8XES9K2gC4h3TvcDM
"text/plain": [
"<Figure size 864x216 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from collections import OrderedDict\n",
"\n",
"def rang_freq_with_labels(name, g, top=None):\n",
" freq = freq_list(g, top)\n",
"\n",
" plt.figure(figsize=(12, 3))\n",
" plt.ylabel('liczba wystąpień')\n",
"\n",
" plt.bar(freq.keys(), freq.values())\n",
"\n",
" fname = f'02_Jezyki/{name}.png'\n",
"\n",
" plt.savefig(fname)\n",
"\n",
" return fname\n",
"\n",
"rang_freq_with_labels('pt-chars', get_characters(pan_tadeusz))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Słowa\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Co rozumiemy pod pojęciem słowa czy wyrazu, nie jest oczywiste. W praktyce zależy to od wyboru **tokenizatora**.\n",
"\n",
"Załóżmy, że przez wyraz rozumieć będziemy nieprzerwany ciąg liter bądź cyfr (oraz gwiazdek\n",
"— to za chwilę ułatwi nam analizę pewnego tekstu…).\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Ty',\n",
" 'co',\n",
" 'gród',\n",
" 'zamkowy',\n",
" 'Nowogródzki',\n",
" 'ochraniasz',\n",
" 'z',\n",
" 'jego',\n",
" 'wiernym',\n",
" 'ludem',\n",
" 'Jak',\n",
" 'mnie',\n",
" 'dziecko',\n",
" 'do',\n",
" 'zdrowia',\n",
" 'powróciłaś',\n",
" 'cudem',\n",
" 'Gdy',\n",
" 'od',\n",
" 'płaczącej',\n",
" 'matki',\n",
" 'pod',\n",
" 'Twoją',\n",
" 'opiekę',\n",
" 'Ofiarowany',\n",
" 'martwą',\n",
" 'podniosłem',\n",
" 'powiekę',\n",
" 'I',\n",
" 'zaraz']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from itertools import islice\n",
"import regex as re\n",
"\n",
"def get_words(t):\n",
" for m in re.finditer(r'[\\p{L}0-9\\*]+', t):\n",
" yield m.group(0)\n",
"\n",
"list(islice(get_words(pan_tadeusz), 100, 130))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zobaczmy 20 najczęstszych wyrazów.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABLAAAAEsCAYAAADTvUpQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAABC3UlEQVR4nO3deViU9f7/8dfIruAEmBCJS7mkgktWbhV43FJJO56yo4b2y6OWueCu2YLmUnYUCk+LHk+YS6aWrSdzSUkOrigWaZqmuQTRQihKgHD//ujy/jqCZsVwz9DzcV1zXd6f+z0zrxmYG3zzuT+3zTAMQwAAAAAAAICLqmZ1AAAAAAAAAOBKaGABAAAAAADApdHAAgAAAAAAgEujgQUAAAAAAACXRgMLAAAAAAAALo0GFgAAAAAAAFwaDSwAAAAAAAC4NBpYAAAAAAAAcGk0sAAAAAAAAODSaGABAAAAAADApdHAAgAAAAAAgEujgQUAAAAAAACXRgMLAAAAAAAALo0GFgAAAAAAAFwaDSwAAAAAAAC4NBpYAAAAAAAAcGk0sAAAAAAAAODSaGABAAAAAADApdHAAgAAAAAAgEujgQUAAAAAAACXRgMLAAAAAAAALo0GFgAAAAAAAFwaDSwAAAAAAAC4NBpYAAAAAAAAcGk0sAAAAAAAAODSaG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4LfH19lZSUpKSkpMvWBAUFadmyZVedCwAAAAAAwNlYA6sCrVq1Sl9//bW5PX78eD300EM6c+aMfvrpJ+Xm5pq3H3/80cKkAAAAAAAA7oMGVgX
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rang_freq_with_labels('pt-words-20', get_words(pan_tadeusz), top=20)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zobaczmy pełny obraz, już bez etykiet.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAwSElEQVR4nO3df3QV9Z3/8dclP64hm1zzo7mXWwKme7LWNSm1wYZEt2CBADWkLt9dtLgp3eWruAg0S/AHx+2Kfk+Tyq7ArqlWWb5CQYyn3xXWs7WRUDWaL6AYyAqIqGsKQXMN+r3cJBBvQjLfPyizvSSAQiZ3bub5OGfOyZ15z+QzfrwnLz4znxmXYRiGAAAA4Bijot0AAAAADC8CIAAAgMMQAAEAAByGAAgAAOAwBEAAAACHIQACAAA4DAEQAADAYQiAAAAADkMABAAAcBgCIAAAgMMQAAEAAByGAAgAAOAwBEAAAACHIQACAAA4DAEQAADAYQiAAAAADkMABAAAcBgCIAAAgMMQAAEAAByGAAgAAOAwBEAAAACHIQACAAA4DAEQAADAYQiAAAAADkMABAAAcBgCIAAAgMMQAAEAAByGAAgAAOAwBEAAAACHIQACAAA4DAEQAADAYQiAAAAADkMABAAAcBgCIAAAgMMQAAEAAByGAAgAAOAwBEAAAACHIQACAAA4DAEQAADAYQiAAAAADkMABAAAcBgCIAAAgMMQAAEAAByGAAgAAOAwBEAAAACHIQACAAA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upU6e0d+9e/eQnP9HevXv1/PPP67333lNZWVlEXUVFhbZu3ara2lo1Njaqq6tLpaWl6uvrM2vmzZun5uZm1dXVqa6uTs3NzSovL7f8/AAAAKItPtoNONesWbM0a9asQbd5PB7V19dHrHvsscf07W9/W0ePHtW4ceMUCoW0fv16bdq0SdOmTZMkbd68WdnZ2dqxY4dmzJihQ4cOqa6uTrt371ZhYaEkad26dSoqKtLhw4d19dVXW3uSX5DBc2AAAIAFbDcC+GWFQiG5XC5deeWVkqSmpib19vaqpKTErPH7/crLy9POnTslSbt27ZLH4zHDnyRNmjRJHo/HrBlMOBxWR0dHxAIAABBrYjoAfv7557r//vs1b948paamSpICgYASExOVlpYWUev1ehUIBMyarKysAcfLysoyawZTXV1t3jPo8XiUnZ09hGcDAAAwPGI2APb29uq2225Tf3+/Hn/88YvWG4YRMblisIkW59aca8WKFQqFQubS2tp6aY0HAACIopgMgL29vZo7d65aWlpUX19vjv5Jks/nU09Pj4LBYMQ+7e3t8nq9Zs0nn3wy4LjHjx83awbjdruVmpoasQAAAMSamAuAZ8Pf+++/rx07digjIyNie0FBgRISEiImi7S1tenAgQMqLi6WJBUVFSkUCunNN980a9544w2FQiGzJpp4CAwAALCS7WYBd3V16YMPPjA/t7S0qLm5Wenp6fL7/fqLv/gL7d27V//xH/+hvr4+85699PR0JSYmyuPxaMGCBaqsrFRGRobS09O1fPly5efnm7OCr7nmGs2cOVN33HGHnnzySUnSnXfeqdLSUtvMAJYkJgEDAAAr2C4AvvXWW7rpppvMz8uWLZMkzZ8/XytXrtQLL7wgSfrmN78Zsd8rr7yiKVOmSJLWrFmj+Ph4zZ07V93d3Zo6dao2bNiguLg4s/6ZZ57R0qVLzdnCZWVlgz57EAAAYKRxGQZPm7tUHR0d8ng8CoVCQ3o/4P9ubNHD//GOZk/w67EfXDdkxwUAANb9/Y4lMXcPIAAAAC4PARAAAMBhCIA2dIFHEQIAAFw2AiAAAIDDEABtjPk5AADACgR
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from math import log\n",
"\n",
"def rang_freq(name, g):\n",
" freq = freq_list(g)\n",
"\n",
" plt.figure().clear()\n",
" plt.plot(range(1, len(freq.values())+1), freq.values())\n",
"\n",
" fname = f'02_Jezyki/{name}.png'\n",
"\n",
" plt.savefig(fname)\n",
"\n",
" return fname\n",
"\n",
"rang_freq('pt-words', get_words(pan_tadeusz))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Widać, jak różne skale obejmuje ten wykres. Zastosujemy logartm,\n",
"najpierw tylko do współrzędnej y.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAo10lEQVR4nO3dfZSV5X03+t+eFzY4DqOIvEwYkZgYNaCxaBWNifGFSMQkzcsyqTEkabqWWWBqtWc1NutZmrQV2z718TzHxlaPx2rTiOusqvU8MSZ4VNSjGF+wQTQGowFUECU4w4tsmJn7/MHMxglCVPae+95zfT5r7eXsPfdmfsM1s/j6u+7rukpZlmUBAEAymvIuAACA4SUAAgAkRgAEAEiMAAgAkBgBEAAgMQIgAEBiBEAAgMQIgAAAiREAAQASIwACACRGAAQASIwACACQGAEQACAxAiAAQGIEQACAxAiAAACJEQABABIjAAIAJEYABABIjAAIAJAYARAAIDECIABAYgRAAIDECIAAAIkRAAEAEiMAAgAkRgAEAEiMAAgAkBgBEAAgMQIgAEBiBEAAgMQIgAAAiREAAQASIwACACRGAAQASIwACACQGAEQACAxAiAAQGIEQACAxAiAAACJEQABABIjAAIAJEYABABIjAAIAJAYARAAIDECIABAYgRAAIDECIAAAI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wgA1JgAWFCDi0C27dABBABqSwAsqDGjBjuAAiAAUFsCYEHtNxAAt1QEQACgtgTAgtq/3BIREVu39+Z
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from math import log\n",
"\n",
"def rang_log_freq(name, g):\n",
" freq = freq_list(g)\n",
"\n",
" plt.figure().clear()\n",
" plt.plot(range(1, len(freq.values())+1), [log(y) for y in freq.values()])\n",
"\n",
" fname = f'02_Jezyki/{name}.png'\n",
"\n",
" plt.savefig(fname)\n",
"\n",
" return fname\n",
"\n",
"rang_log_freq('pt-words-log', get_words(pan_tadeusz))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"****Pytanie**** Dlaczego widzimy coraz dłuższe „schodki”?\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Hapax legomena\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Z poprzedniego wykresu możemy odczytać, że ok. 2/3 wyrazów wystąpiło\n",
"dokładnie 1 raz. Słowa występujące jeden raz w danym korpusie noszą\n",
"nazwę *hapax legomena* (w liczbie pojedynczej *hapax legomenon*, ἅπαξ\n",
"λεγόμενον, „raz powiedziane”, żargonowo: „hapaks”).\n",
"\n",
"„Prawdziwe” hapax legomena, słowa, które wystąpiły tylko raz w *całym*\n",
"korpusie tekstów danego języka (np. starożytnego) rzecz jasna\n",
"sprawiają olbrzymie trudności w tłumaczeniu. Przykładem jest greckie\n",
"słowo ἐπιούσιος, przydawka odnosząca się do chleba w modlitwie „Ojcze\n",
"nasz”. Jest to jedyne poświadczenie tego słowa w całym znanym korpusie\n",
"greki (nie tylko z Pisma Świętego). W języku polskim tłumaczymy je na\n",
"„powszedni”, ale na przykład w rosyjskim przyjął się odpowiednik\n",
"„насущный” — o przeciwstawnym do polskiego znaczeniu!\n",
"\n",
"W sumie podobne problemy hapaksy mogą sprawiać metodom statystycznym\n",
"przy przetwarzaniu jakiekolwiek korpusu.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Wykres log-log\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Jeśli wspomniany wcześniej wykres narysujemy używając skali\n",
"logarytmicznej dla ****obu**** osi, otrzymamy kształt zbliżony do linii prostej.\n",
"\n",
"Tę własność tekstów nazywamy ****prawem Zipfa****.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA340lEQVR4nO3deXhU5cH+8fvMJJksZAaSkEBMgLALyI7IDiooWqvVuqLi2mpBRboo2vd1Jz+1tfYtimKtG3WpG6J1w4WALLIrsohsSVjCTiYJZEIy8/sjMBpZAiSZZ2bO93Ndc7VzZgbupqPPneec5zlWIBAICAAAALbhMB0AAAAAoUUBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZiiAAAAANkMBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZiiAAAAANkMBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZiiAAAAANkMBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZiiAAAAANkMBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZiiAAAAANkMBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZiiAAAAANkMBBAAAsBkKIAAAgM1QAAEAAGyGAggAAGAzFEAAAACboQACAADYDAUQAADAZm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"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from math import log\n",
"\n",
"def log_rang_log_freq(name, g):\n",
" freq = freq_list(g)\n",
"\n",
" plt.figure().clear()\n",
" plt.plot([log(x) for x in range(1, len(freq.values())+1)], [log(y) for y in freq.values()])\n",
"\n",
" fname = f'02_Jezyki/{name}.png'\n",
"\n",
" plt.savefig(fname)\n",
"\n",
" return fname\n",
"\n",
"log_rang_log_freq('pt-words-log-log', get_words(pan_tadeusz))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Związek między frekwencją a długością\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Powiązane z prawem Zipfa prawo językowe opisuje zależność między\n",
"częstością użycia słowa a jego długością. Generalnie im krótsze słowo, tym częstsze.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAACkPklEQVR4nO2dd3gUZdvFz6bSQugldBDpvYMiUkXBLlbE3hALVuwdFJXXXpFib6AIKKICKoiAgIL0DgIiIAk1pMz3x/nG2U02hXlmU5jzu669Zneezdyz2U3m7F0DlmVZEEIIIYQQviGqsE9ACCGEEEIULBKAQgghhBA+QwJQCCGEEMJnSAAKIYQQQvgMCUAhhBBCCJ8hASiEEEII4TMkAIUQQgghfIYEoBBCCCGEz5AAFEIIIYTwGRKAQgghhBA+QwJQCCGEEMJnSAAKIYQQQvgMCUAhhBBCCJ8hASiEEEII4TMkAIUQQgghfIYEoBBCCCGEz5AAFEIIIYTwGRKAQgghhBA+QwJQCCGEEMJnSAAKIYQQQvg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/wOHwbuuAOoWRMYMKBwzk8IIYQQABQCLhpYVu7rxal33qhRwLx5QPv2DFt37Qps3gy88QawbRswbRoQo4+dEEIIUZjIA1gU6NgRiI9nhWw4PvmEIvDkkwv2vNxQuTJbv9xwA/Duu8AFF7AtTNu2wC+/AKeeWthnKIQQQviegGXl5X4SOZGSkoLExEQkJyejbNmyZge77jrgo4+Ar78GunVz9i9bxiKQzp2LfhFIVjIygJQUoHRpIC6usM9GCCGEAODx9buYolh
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def freq_vs_length(name, g, top=None):\n",
" freq = freq_list(g)\n",
"\n",
" plt.figure().clear()\n",
" plt.scatter([len(x) for x in freq.keys()], [log(y) for y in freq.values()],\n",
" facecolors='none', edgecolors='r')\n",
"\n",
" fname = f'02_Jezyki/{name}.png'\n",
"\n",
" plt.savefig(fname)\n",
"\n",
" return fname\n",
"\n",
"freq_vs_length('pt-lengths', get_words(pan_tadeusz))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### N-gramy\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"W modelowaniu języka często rozpatruje się n-gramy, czyli podciągi o\n",
"rozmiarze $n$.\n",
"\n",
"Na przykład *digramy* (*bigramy*) to zbitki dwóch jednostek, np. liter albo wyrazów.\n",
"\n",
"| $n$|$n$-gram|nazwa|\n",
"|---|---|---|\n",
"| 1|1-gram|unigram|\n",
"| 2|2-gram|digram/bigram|\n",
"| 3|3-gram|trigram|\n",
"| 4|4-gram|tetragram|\n",
"| 5|5-gram|pentagram|\n",
"\n",
"**Pytanie:** Jak nazywa się 6-gram?\n",
"\n",
"Jak widać, dla symetrii mówimy czasami o unigramach, jeśli operujemy\n",
"po prostu na jednostkach, nie na ich podciągach.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### N-gramy z Pana Tadeusza\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Statystyki, które policzyliśmy dla pojedynczych liter czy wyrazów możemy powtórzyć dla n-gramów.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('k', 'o', 't'), ('o', 't', 'e'), ('t', 'e', 'k')]"
]
}
],
"source": [
"def ngrams(iter, size):\n",
" ngram = []\n",
" for item in iter:\n",
" ngram.append(item)\n",
" if len(ngram) == size:\n",
" yield tuple(ngram)\n",
" ngram = ngram[1:]\n",
"\n",
"list(ngrams(\"kotek\", 3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zauważmy, że policzyliśmy wszystkie n-gramy, również częściowo pokrywające się.\n",
"\n",
"Zawsze powinniśmy się upewnić, czy jest jasne, czy chodzi o n-gramy znakowe czy wyrazowe\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3-gramy znakowe\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA7x0lEQVR4nO3deXhU5eH28XsySSb7kBUICSFsssmOyCoIoqhULdVqEXFtrbjQtFZwK6gYtWrtqwVFrba40VbFpehPXNj3VWTfE9YQlkxIyCSZmfePwCAFZMnyzMz5fq5rLjgnM/Q212meO895zjk2n8/nEwAAACwjzHQAAAAA1C0KIAAAgMVQAAEAACyGAggAAGAxFEAAAACLoQACAABYDAUQAADAYiiAAAAAFkMBBAAAsBgKIAAAgMVQAAEAACyGAggAAGAxFEAAAACLoQACAABYDAUQAADAYiiAAAAAFkMBBAAAsBgKIAAAgMVQAAEAACyGAggAAGAxFEAAAACLoQACAAB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BSMj+zfTnX2a8pQRAKhDjN8UwGrhAML5+GFnkcZ9tlqLtx2UJGUkRuuBAS10XadGrA8EgDrA+E0BrBYOIJwvn8+nT1fuUu60ddrjKpMkNU2J1f0DWqhl/XiFhUl2m02ZSTHMDgJADWP8pgBWCwcQqutIuUeTF2zTxBmbdbC04qSvJ8ZE6Nae2RrRM0v1YriNDADUBMZvCmC1cAChphx2V+qtOVv1n2U7VFrukc/nU1mFV4fdlZKk2Ei7rm6fru5Nk9StSZIa1YtWGM8jBoDzwvh
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"log_rang_log_freq('pt-3-char-ngrams-log-log', ngrams(get_characters(pan_tadeusz), 3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2-gramy wyrazowe\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAnlUlEQVR4nO3df3CV9Z3o8c9JAgloiAKSHxI0bL1IQRGCU7GCet3GhV133XJ33V/V2dY7y4xWMeOOojvTrbuV267rMK4Kw66ut/W669yLtXpLd+S2Cna1W8Wg1iLWygICKWA1AawJIef+gQmmRERJzvOc87xeM5lpDufoJxn1vPt9zvf75PL5fD4AAMiMsqQHAACgsAQgAEDGCEAAgIwRgAAAGSMAAQAyRgACAGSMAAQAyBgBCACQMQIQACBjBCAAQMYIQACAjBGAAAAZIwABADJGAAIAZIwABADIGAEIAJAxAhAAIGMEIABAxghAAICMEYAAABkjAAEAMkYAAgBkjAAEAMgYAQgAkDECEAAgYwQgAEDGCEAAgIwRgAAAGSMAAQAyRgACAGSMAAQAyBgBCAC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JL1qQknxozGk+LFbe/El/7nc3HKiZVJj9Qvl8vFH86eGC3T6pIeBQBKigAkrpjdGC9ueydeerMj6VGOsHFnpwAEgCEmAIk/OrcxTh49IjrfO5D0KP0O9kbc+ujLsf2dX8WefV0xPkUrkwBQ7AQgUVaWi/ln1Sc9xhHu++E
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"log_rang_log_freq('pt-2-word-ngrams-log-log', ngrams(get_words(pan_tadeusz), 3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Tajemniczy język Manuskryptu Wojnicza\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[Manuskrypt Wojnicza](https://pl.wikipedia.org/wiki/Manuskrypt_Wojnicza) to powstały w XV w. manuskrypt spisany w\n",
"tajemniczym alfabecie, do dzisiaj nieodszyfrowanym. Rękopis stanowi\n",
"jedną z największych zagadek historii (i lingwistyki).\n",
"\n",
2022-03-06 17:55:47 +01:00
"![Źródło](./02_Jezyki/voynich135.jpg)\n",
2022-03-06 17:51:23 +01:00
"\n",
"Sami zbadajmy statystyczne własności tekstu manuskryptu. Użyjmy\n",
"transkrypcji Vnow, gdzie poszczególne znaki tajemniczego alfabetu\n",
"zamienione na litery alfabetu łacińskiego, cyfry i gwiazdkę. Jak\n",
"transkrybować manuskrypt, pozostaje sprawą dyskusyjną, natomiast wybór\n",
"takiego czy innego systemu transkrypcji nie powinien wpływać\n",
"dramatycznie na analizę statystyczną.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"9 OR 9FAM ZO8 QOAR9 Q*R 8ARAM 29 [O82*]OM OPCC9 OP"
]
}
],
"source": [
"import requests\n",
"\n",
"voynich_url = 'http://www.voynich.net/reeds/gillogly/voynich.now'\n",
"voynich = requests.get(voynich_url).content.decode('utf-8')\n",
"\n",
"voynich = re.sub(r'\\{[^\\}]+\\}|^<[^>]+>|[-# ]+', '', voynich, flags=re.MULTILINE)\n",
"\n",
"voynich = voynich.replace('\\n\\n', '#')\n",
"voynich = voynich.replace('\\n', ' ')\n",
"voynich = voynich.replace('#', '\\n')\n",
"\n",
"voynich = voynich.replace('.', ' ')\n",
"\n",
"voynich[100:150]"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABLAAAAEsCAYAAADTvUpQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAABLY0lEQVR4nO3deVjU1f///8fEJipMoAKiuJSGu6aWovVGU0Fzac/SSHPLXEnNLMuld7mnZaaVuZBL+jHflmUiZmqa4oJZmuSSkKYQlQhiBgqv3x/9nK8jCDMjOCPdb9c11+Wc13nOeb5wFubJOedlMgzDEAAAAAAAAOCibnF2AgAAAAAAAEBhKGABAAAAAADApVHAAgAAAAAAgEujgAUAAAAAAACXRgELAAAAAAAALo0CFgAAAAAAAFwaBSwAAAAAAAC4NApYAAAAAAAAcGkUsAAAAAAAAODSKGABAAAAAADApVHAAgAAAAAAgEujgAUAAAAAAACXRgELAAAAAAAALo0CFgAAAAAAAFwaBSwAAAAAAAC4NApYAAAAAAAAcGkUsAAAAAAAAODSKGABAAAAAADApVHAAgAAAAAAgEujgAUAAAAAAACXRgELAAAAAAAALo0CFgAAAAAAAFwaBSwAAAAAAAC4NApYAAAAAAAAcGkUsAAAAAAAAODSKGABAAAAAADApVHAAgAAAAAAgEujgAUAAAAAAACXRgELAAAAAAAALo0CFgAAAAAAAFwaBSwAAAAAAAC4NApYAAAAAAAAcGkUsAAAAAAAAODSKGABAAAAAADApbk7OwGUPnl5eTp9+rR8fHxkMpmcnQ4AAAAAoJQzDEPnzp1TcHCwbrmFuTqlEQUsFLvTp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gAAAAAAAFwaBSwAAAAAAAC4NApYAAAAAAAAcGkUsAAAAAAAAODSKGABAAAAAADApVHAAgAAAAAAgEujgAUAAAAAAACXRgELAAAAAAAALo0CFgAAAAAAAFwaBSwAAAAAAAC4NApYAAAAAAAAcGkUsAAAAAAAAODSKGABAAAAAADApVHAAgAAAAAAgEujgAUAAAAAAACX5u7sBG5mZ8+e1e7du5WWlqa8vDyrY08//bSTsgIAAAAAAChdKGA56PPPP1fPnj11/vx5+fj4yGQyWY6ZTCYKWAAAAAAAAMWEJYQ2+r//+z/98ssvlvsjR45Unz59dO7cOZ09e1bp6emW25kzZ5yYKQAAAAAAQOlCActG5cuXV9u2bbV3715J0qlTpzRs2DCVLVvWyZkBAAAAAACUbhSwbHT//ffrs88+03PPPSdJioyMtBSzAAAAAAAAUHLYA8sODRs21DfffCNJ6ty5s1544QUdOnRIDRs2lIeHh1Xfbt26OSNFAAAAAACAUocClp28vb0lSf3795ckvfbaa/n6mEwm5ebm3tC8AAAAAAAASisKWA7Ky8tzdgoAAAAAAAD/CuyBVQz+/vtvZ6cAAAAAAABQalHAclBubq7++9//qkqVKipfvryOHz8uSXr11Ve1YMECJ2cHAAAAAABQelDActAbb7yhxYsXa9q0afL09LS0N2zYUB9++KFdj/XNN9+oa9euCg4Olslk0qeffmp1vHfv3jKZTFa3li1bWvXJzs7W0KFDVbFiRZUrV07dunXTr7/+atUnPT1dUVFRMpvNMpvNioqK0tmzZ636nDhxQl27dlW5cuVUsWJFDRs2TDk5OXadDwAAAAAAQHGigOWgjz76SB988IF69uwpNzc3S3ujRo30008/2fVY58+fV+PGjTVnzpxr9unYsaNSUlIsty+//NLqeHR0tNasWaMVK1Zo+/btysrKUpcuXaw2k+/Ro4f279+v2NhYxcbGav/+/YqKirIcz83NVefOnXX
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rang_freq_with_labels('voy-chars', get_characters(voynich))"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA2SElEQVR4nO3deXhU5cH+8fvMJJksJJOEkISYCQZlCSBbUGTRYkEqbqVardSt1PpKiwvmrVa0qz81rdalr1YUXutaKnVBqa9LcWMR2cKq7GsCBEJYMlnIJJnM74+ESMpiQpZnJuf7ua65JCcz6e2VY8/Nc57nOVYgEAgIAAAAtuEwHQAAAADtiwIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNhJkOEMpqa2u1Z88excbGyrIs03EAAEATBAIBlZaWKi0tTQ6HPcfCKIAtsGfPHnk8HtMxAADAaSgoKFB6errpGEZQAFsgNjZWUt0JFBcXZzgNAABoCq/XK4/H03AdtyMKYAscve0bFxdHAQQAIMTYefqWPW98AwAA2BgFEAAAwGYogAAAADZDAQQAALAZCiAAAIDNUAABAABshgIIAABgMxRAAAAAm6EAAgAA2AwFEAAAwGYogAAAADZDAQxStbUB0xEA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R6uqOUld3pNLio5QWH6mu7m/+mRzrUpiTBSYAgJbj+k0BbBFOoOarrQ3oqz0l+nh9kT7bUKRN+0rlO2Z08GScDkspsS51jf+mJHZPitGgjAT1SO4kh4P5hQCApuH6TQFsEU6glgsEAjpUUa09h49oz+EjKiyp1J6SIyo8XKnCkiPac7hSe72V8tee/DSNdYVpgCdegzPiNSgjQYMy4hUfHdGO/xYAgFDC9ZsC2CKcQO3DXxvQ/lJfo2K4+/ARrS/0anVBiY5U+4/7zNHRwUEZ8RqckaCeKZ24hQwAkMT1W6IAtggnkHk1/lpt3FeqlfmHtSL/kFbmH9b24vLj3hcT4dQDl/XRj4dmGEgJAAgmXL8pgC3CCRScDpVXaWXBoYZSuLqgRGW+GoU5LL318+Ea4Ik3HREAYBDXbwpgi3AChQZ/bUB3vr5S/7emUN2TYvTenSMVHRFmOhYAwBCu3xKTotDhOR2WHh7fT6lxkdpWXK5H3l9vOhIAAEZRAGEL8dERevzaAZKk1xbn69MN+wwnAgDAHAogbGPE2Um6ZWSmJOneN9c0enYxAAB2QgGErdzzvV7qlRKr4rIq3ffWGjEFFgBgRxRA2EpkuFNPXTdQEU6HPl5fpNeXFZiOBABAu6MAwnayusbpnu/1kiQ9+K91J9w3EACAjowCCFu6ZWSmhnXvrCPVfk2ZtUrV/m9/HjEAAB0FBRC25HBYevzaAYqLDNPqgsN65tMtpiMBANBuKICwrbT4KD30g3MkSc98tkV5Ow8ZTgQAQPugAMLWrhyQpvE
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"log_rang_log_freq('voy-log-log', get_words(voynich))"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABLAAAAEsCAYAAADTvUpQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYf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dq10x/+8Ae9/vrr+uabb7RgwYIzX1kAAAAAAIBSIMBy2GuvvaZ///vf6tWrlwICAnzjGzdurG+//fa053f//ferU6dOateund/4jIwMZWVlKSUlxTcuJCRErVu31tKlSyVJK1eu1JEjR/zaJCQkqFGjRr42AAAAAAAAFY2LuDts165dqlu3bpHxBQUFOnLkyGnNa/r06Vq1apVWrFhRZFpWVpYkKS4uzm98XFycfvjhB1+b4OBgv55bhW0Kn1+c3Nxc5ebm+h7n5OScVt0AAAAAAAAnQw8shzVs2FCLFy8uMn7mzJn6wx/+UOL57NixQ4MGDdLrr7+u0NDQE7bzeDx+j82syLjjnarN2LFj5fV6fUNiYmKJ6wYAAAAAADgVemA57O9//7tuu+027dq1SwUFBXr77be1adMmvfbaa3r//fdLPJ+VK1dq9+7datq0qW9cfn6+PvvsM7344ovatGmTpN97WVWvXt3XZvfu3b5eWfHx8crLy9O+ffv8emHt3r1bLVu2POGyR4wYocGDB/se5+TkEGIBAAAAAIAyQw8sh3Xp0kVvvvmm5s6dK4/Ho8cee0wbN27Ue++9p/bt25d4Pm3bttU333yjNWvW+IZmzZqpV69eWrNmjS666CLFx8dr/vz5vufk5eVp0aJ
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rang_freq_with_labels('voy-words-20', get_words(voynich), top=20)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA2SElEQVR4nO3deXhU5cH+8fvMJJksJJOEkISYCQZlCSBbUGTRYkEqbqVardSt1PpKiwvmrVa0qz81rdalr1YUXutaKnVBqa9LcWMR2cKq7GsCBEJYMlnIJJnM74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SL/kFbmH9b24vLj3hcT4dQDl/XRj4dmGEgJAAgmXL8pgC3CCRScDpVXaWXBoYZSuLqgRGW+GoU5LL318+Ea4Ik3HREAYBDXbwpgi3AChQZ/bUB3vr5S/7emUN2TYvTenSMVHRFmOhYAwBCu3xKTotDhOR2WHh7fT6lxkdpWXK5H3l9vOhIAAEZRAGEL8dERevzaAZKk1xbn69MN+wwnAgDAHAogbGPE2Um6ZWSmJOneN9c0enYxAAB2QgGErdzzvV7qlRKr4rIq3ffWGjEFFgBgRxRA2EpkuFNPXTdQEU6HPl5fpNeXFZiOBABAu6MAwnayusbpnu/1kiQ9+K91J9w3EACAjowCCFu6ZWSmhnXvrCPVfk2ZtUrV/m9/HjEAAB0FBRC25HBYevzaAYqLDNPqgsN65tMtpiMBANBuKICwrbT4KD30g3MkSc98tkV5Ow8ZTgQAQPugAMLWrhyQpvE
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"log_rang_log_freq('voy-words-log-log', get_words(voynich))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Język DNA\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Kod genetyczny przejawia własności zaskakująco podobne do języków naturalnych.\n",
"Przede wszystkim ma charakter dyskretny, genotyp to ciąg symboli ze skończonego alfabetu.\n",
"Podstawowe litery są tylko cztery, reprezentują one nukleotydy, z których zbudowana jest nić DNA:\n",
"a, g, c, t.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TATAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTA"
]
}
],
"source": [
"import requests\n",
"\n",
"dna_url = 'https://raw.githubusercontent.com/egreen18/NanO_GEM/master/rawGenome.txt'\n",
"dna = requests.get(dna_url).content.decode('utf-8')\n",
"\n",
"dna = ''.join(dna.split('\\n')[1:])\n",
"dna = dna.replace('N', 'A')\n",
"\n",
"dna[0:100]"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABLAAAAEsCAYAAADTvUpQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAwBElEQVR4nO3df1iUdb7/8dcEMiLCBLJAY5R26ZIE9gM3JdvFPQVoItt2NjthJCeXbDWJ0GOZm6mb0JqiJz22ZRbmj2NHzVObxUJuaV5GEEmJGtamx18g7oqgZIAw3z827++OjLYWct8yz8d1zXUxn/vNzIu5rnuvfO3nvsfmcrlcAgAAAAAAACzqMrMDAAAAAAAAAOdDgQUAAAAAAABLo8ACAAAAAACApVFgAQAAAAAAwNIosAAAAAAAAGBpFFgAAAAAAACwNAosAAAAAAAAWBoFFgAAAAAAACyNAgsAAAAAAACWRoEFAAAAAAAAS6PAAgAAAAAAgKVRYAEAAAAAAMDSKLAAAAAAAABgaRRYAAAAAAAAsDQKLAAAAAAAAFgaBRYAAAAAAAAsjQILAAAAAAAAlkaBBQAAAAAAAEujwAIAAAAAAIClUWABAAAAAADA0iiwAAAAAAAAYGkUWAAAAAAAALA0CiwAAAAAAABYGgUWAAAAAAAALI0CCwAAAAAAAJZGgQUAAAAAAABLo8ACAAAAAACApVFgAQAAAAAAwNIosAAAAAAAAGBpFFgAAAAAAACwNAosAAAAAAAAWBoFFgAAAAAAACyNAgsAAAAAAACWRoEFAAAAAAAAS/M1OwC6nra2Nh0+fFiBgYGy2WxmxwEAAAAAdHEul0snTpyQ0+nUZZexV6crosBChzt8+LAiIyPNjgEAAAAA8DIHDhzQlVdeaXYMXAQUWOhwgYGBkv7+PxxBQUEmpwEAAAAAdHUNDQ2KjIw0/j2KrocCCx3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QfX295e+H1efxjWZHAH6wfc+MNDvCBePcQ1dwKZ57AAB0VZfSv0Px/XAPLAAAAAAAAFgalxACAAB4AXY+oitg5yMAeC8KLAAAAAC4SCiP0RVQHsMKuIQQAAAAAAAAlkaBBQAAAAAAAEujwAIAAAAAAIClUWABAAAAAADA0iiwAAAAAAAAYGkUWAAAAAAAALA0CiwAAAAAAABYGgUWAAAAAAAALI0CCwAAAAAAAJZGgQUAAAAAAABLo8ACAAAAAACApVFgAQAAAAAAwNIosAAAAAAAAGBpvmYHsKrjx4+rtLRUtbW1amtrczt2//33m5QKAAAAAADA+1BgefDHP/5RY8aMUWNjowIDA2Wz2YxjNpuNAgsAAAAAAKATcQmhpP/5n//R//3f/xnPJ0+erAceeEAnTpzQ8ePHVVdXZzyOHTtmYlIAAAAAAADvQ4ElqWfPnvr5z3+ujz/+WJJ06NAhZWVlqUePHiYnAwAAAAAAAAWWpDvuuENvvPGGfvOb30iSkpOTjTILAAAAAAAA5uIeWN+KjY3Vli1bJEkjR47Uf/zHf2jXrl2KjY1Vt27d3GZTU1PNiAgAAAAAAOCVKLD+gb+/vyQpMzNTkjR79ux2MzabTa2trZ2aCwAAAAAAwJtRYHnQ1tZmdgQAAAAAAAB8i3tgfYdvvvnG7AgAAAAAAABejQLLg9bWVv3ud79T79691bNnT3311VeSpCeffFLLli0zOR0AAAAAAIB3ocDyYM6cOSooKNDcuXPl5+dnrMfGxuqll14yMRkAAAAAAID3ocDy4NVXX9WLL76oMWPGyMfHx1gfOHCgPv/8cxOTAQAAAAAAeB8KLA8OHTqkfv36tVtva2tTS0uLCYkAAAAAAAC8FwWWB9ddd50++OCDdutr167VjTfeaEIiAAAAAAAA7+VrdgAreuqpp5Senq5
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rang_freq_with_labels('dna-chars', get_characters(dna))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Tryplety — znaczące cząstki genotypu\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Nukleotydy rzeczywiście są jak litery, same w sobie nie niosą\n",
"znaczenia. Dopiero ciągi trzech nukleotydów, *tryplety*, kodują jeden\n",
"z dwudziestu aminokwasów.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABLAAAAEsCAYAAADTvUpQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAAA9HUlEQVR4nO3de1hU9b7H8c8EgogwgQRE4qU0UtEuVEq2A1NBN4hd9rYTRllutU2JpB7TPBlWonkvOXYxDfOSZWal7gg1MQlJQ6lM0txqooFaIl4yQJzzR4/rNKLuGLG1pPfreeZ5nLW+rPnMqFw+/NYam8PhcAgAAAAAAACwqMvMDgAAAAAAAACcDwUWAAAAAAAALI0CCwAAAAAAAJZGgQUAAAAAAABLo8ACAAAAAACApVFgAQAAAAAAwNIosAAAAAAAAGBpFFgAAAAAAACwNAosAAAAAAAAWBoFFgAAAAAAACyNAgsAAAAAAACWRoEFAAAAAAAAS6PAAgAAAAAAgKVRYAEAAAAAAMDSKLAAAAAAAABgaRRYAAAAAAAAsDQKLAAAAAAAAFgaBRYAAAAAAAAsjQILAAAAAAAAlkaBBQAAAAAAAEujwAIAAAAAAIClUWABAAAAAADA0iiwAAAAAAAAYGkUWAAAAAAAALA0CiwAAAAAAABYGgUWAAAAAAAALI0CCwAAAAAAAJZGgQUAAAAAAABLo8ACAAAAAACApVFgAQAAAAAAwNIosAAAAAAAAGBpFFgAAAAAAACwNAosAAAAAAAAWBoFFgAAAAAAACzN3ewAqH9OnTqlH374QT4+PrLZbGbHAQAAAADUcw6HQ0ePHlVISIguu4y1OvURBRbq3A8//KDQ0FCzYwAAAAAA/mSKi4vVt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AAAABWximEAAAAAAAAsDQKLAAAAAAAAFgaBRYAAAAAAAAsjQILAAAAAAAAlkaBBQAAAAAAAEujwAIAAAAAAIClUWABAAAAAADA0iiwAAAAAAAAYGkUWAAAAAAAALA0CiwAAAAAAABYmrvZAS5lhw8f1oYNG3TgwAGdOnXKad+DDz5oUioAAAAAAID6hQLLRcuWLVPfvn11/Phx+fj4yGazGftsNhsFFgAAAAAAQB3hFMLf6Z133tH3339v3B82bJgeeeQRHT16VIcPH1ZZWZlxO3TokIlJAQAAAAAA6hcKrN+pcePG6tKli7744gtJ0r59+5SSkqJGjRqZnAwAAAAAAKB+o8D6nf7617/qgw8+0D//+U9JUmxsrFFm1bXx48fLZrMpNTXV2OZwOJSWlqaQkBB5eXkpOjpa33zzjdPHVVRUaPDgwQoICJC3t7cSEhK0d+9ep5mysjIlJSXJbrfLbrcrKSlJhw8fdprZs2ePevXqJW9vbwUEBCglJUWVlZUX5bkCAAAAAAD8J1wDqxbat2+vTz/9VJIUFxen//7v/9bWrVvVvn17NWjQwGk2ISHBpcfYuHGjXnvtNXXo0MFp+8SJEzV16lRlZmbq2muv1fPPP6/u3btr27Zt8vHxkSSlpqZq2bJlWrRokZo0aaJhw4YpPj5eBQUFcnNzkyQlJiZq7969ysrKkiQNHDhQSUlJWrZsmSSpurpacXFxuuKKK5Sbm6uffvpJDz30kBwOh2bMmOHScwIAAAAAALgQFFi15OXlJUkaMGCAJOnZZ5+tMWOz2VRdXV3rYx87dkx9+/bVrFmz9PzzzxvbHQ6Hpk+frtGjR+uee+6RJM2dO1dBQUFauHChBg0apPLycs2ePVvz5s1Tt27dJEnz589XaGioVq1apdjYWBUVFSkrK0v5+fnq2LGjJGnWrFmKjIzUtm3bFBYWpuzsbG3dulXFxcUKCQmRJE2ZMkX9+vX
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"genetic_code = {\n",
" 'ATA':'I', 'ATC':'I', 'ATT':'I', 'ATG':'M',\n",
" 'ACA':'T', 'ACC':'T', 'ACG':'T', 'ACT':'T',\n",
" 'AAC':'N', 'AAT':'N', 'AAA':'K', 'AAG':'K',\n",
" 'AGC':'S', 'AGT':'S', 'AGA':'R', 'AGG':'R',\n",
" 'CTA':'L', 'CTC':'L', 'CTG':'L', 'CTT':'L',\n",
" 'CCA':'P', 'CCC':'P', 'CCG':'P', 'CCT':'P',\n",
" 'CAC':'H', 'CAT':'H', 'CAA':'Q', 'CAG':'Q',\n",
" 'CGA':'R', 'CGC':'R', 'CGG':'R', 'CGT':'R',\n",
" 'GTA':'V', 'GTC':'V', 'GTG':'V', 'GTT':'V',\n",
" 'GCA':'A', 'GCC':'A', 'GCG':'A', 'GCT':'A',\n",
" 'GAC':'D', 'GAT':'D', 'GAA':'E', 'GAG':'E',\n",
" 'GGA':'G', 'GGC':'G', 'GGG':'G', 'GGT':'G',\n",
" 'TCA':'S', 'TCC':'S', 'TCG':'S', 'TCT':'S',\n",
" 'TTC':'F', 'TTT':'F', 'TTA':'L', 'TTG':'L',\n",
" 'TAC':'Y', 'TAT':'Y', 'TAA':'_', 'TAG':'_',\n",
" 'TGC':'C', 'TGT':'C', 'TGA':'_', 'TGG':'W',\n",
" }\n",
"\n",
"def get_triplets(t):\n",
" for triplet in re.finditer(r'.{3}', t):\n",
" yield genetic_code[triplet.group(0)]\n",
"\n",
"rang_freq_with_labels('dna-aminos', get_triplets(dna))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### „Zdania” w języku DNA\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Z aminokwasów zakodowanych przez tryplet budowane są białka.\n",
"Maszyneria budująca białka czyta sekwencję aż do napotkania\n",
"trypletu STOP (\\_ powyżej). Taka sekwencja to *gen*.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRF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P+JGnKlCmyLMupGUo4HFZXV1fEBgAAEG9iOgC+9NJL6uzs1IMPPihJCgQCkiS32x1R53a7nX2BQEBJSUkaNWrUJWsyMzMHPV9mZqZTM5SKigrnM4OWZSkrK+sj9wYAABAtMR0At27dqjlz5sjr9UaMu1yuiMe2bQ8aG2hgzVD1lzvP2rVrFQqFnO3UqVNX0gYAAEBMidkAeOLECe3du1df+9rXnDGPxyNJg1bpOjo6nFVBj8ej3t5eBYPBS9a0t7cPes6zZ88OWl28WHJystLT0yM2AACAeBOzAfC5555TZmam7r77zzc+ZGdny+PxOHcGS+9/TrCurk5FRUWSpPz8fCUmJkbUtLW16fDhw05NYWGhQqGQDh486NQcOHBAoVDIqQEAABiuEqI9gaGcP39ezz33nBYsWKCEhD9P0eVyye/3q7y8XDk5OcrJyVF5eblGjhypsrIySZJlWVq4cKFWrFih0aNHKyMjQytXrlReXp5mzJghSZo4caJmz56tRYsWacuWLZKkxYsXq6Sk5IrvAAYAAIhXMRkA9+7dq5MnT+qhhx4atG/VqlXq6enR0qVLFQwGVVBQoD179igtLc2p2bx5sxISEjR37lz19PRo+vTp2rZtm0aMGOHU7Ny5U8uXL3fuFi4tLVVlZeW1bw4AACDKYv57AGMZ3wMIAED84XsAY/gzgAAAALg2CIAAAACGIQACAAAYhgAIAABgGAI
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def get_genes(triplets):\n",
" gene = []\n",
" for ammino in triplets:\n",
" if ammino == '_':\n",
" yield gene\n",
" gene = []\n",
" else:\n",
" gene.append(ammino)\n",
"\n",
"plt.figure().clear()\n",
"plt.hist([len(g) for g in get_genes(get_triplets(dna))], bins=100)\n",
"\n",
"fname = '02_Jezyki/dna_length.png'\n",
"\n",
"plt.savefig(fname)\n",
"\n",
"fname"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entropia\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Entropia** ($E$) to miara nieuporządkowania, niepewności, niewiedzy. Im\n",
"większa entropia, tym mniej wiemy. Pojęcie to pierwotnie wywodzi się z\n",
"termodynamiki, później znaleziono wiele zaskakujących analogii i zastosowań w\n",
"innych dyscyplinach nauki.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Entropia w fizyce\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"W termodynamice entropia jest miarą nieuporządkowania układów\n",
"fizycznych, na przykład pojemników z gazem. Przykładowo, wyobraźmy\n",
"sobie dwa pojemniki z gazem, w którym panuje różne temperatury.\n",
"\n",
"![img](./02_Jezyki/gas-low-entropy.drawio.png)\n",
"\n",
"Jeśli usuniemy przegrodę między pojemnikami, temperatura się wyrówna,\n",
"a uporządkowanie się zmniejszy.\n",
"\n",
"![img](./02_Jezyki/gas-high-entropy.drawio.png)\n",
"\n",
"Innymi słowy, zwiększy się stopień nieuporządkowania układu, czyli właśnie entropia.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### II prawo termodynamiki\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Jedno z najbardziej fundamentalnych praw fizyki, II prawo\n",
"termodynamiki głosi, że w układzie zamkniętym entropia nie spada.\n",
"\n",
"****Pytanie****: Czy to, że napisałem te materiały do wykładu i\n",
"*uporządkowałem* wiedzę odnośnie do statystycznych własności języka, nie\n",
"jest sprzeczne z II prawem termodynamiki?\n",
"\n",
"Konsekwencją II prawa termodynamiki jest śmierć cieplna Wszechświata\n",
"(zob. [wizualizacja przyszłości Wszechświata]([https://www.youtube.com/watch?v=uD4izuDMUQA](https://www.youtube.com/watch?v=uD4izuDMUQA))).\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Entropia w teorii informacji\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Pojęcie entropii zostało „odkryte” na nowo przez Claude'a Shannona,\n",
"gdy wypracował ogólną teorię informacji.\n",
"\n",
"Teoria informacji zajmuje się między innymi zagadnieniem optymalnego kodowania komunikatów.\n",
"\n",
"Wyobraźmy sobie pewne źródło (generator) losowych komunikatów z\n",
"zamkniętego zbioru symboli ($\\Sigma$; nieprzypadkowo używamy oznaczeń\n",
"z poprzedniego wykładu). Nadawca $N$ chce przesłać komunikat o wyniku\n",
"losowania do odbiorcy $O$ używając zer i jedynek (bitów).\n",
"Teorioinformacyjną entropię można zdefiniować jako średnią liczbę\n",
"bitów wymaganych do przesłania komunikatu.\n",
"\n",
"![img](./02_Jezyki/communication.drawio.png)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obliczanie entropii — proste przykłady\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Załóżmy, że nadawca chce przekazać odbiorcy informację o wyniku rzutu monetą.\n",
"Entropia wynosi wówczas rzecz jasna 1 — na jedno losowanie wystarczy jeden bit\n",
"(informację o tym, że wypadł orzeł, możemy zakodować na przykład za pomocą zera,\n",
"zaś to, że wypadła reszka — za pomocą jedynki).\n",
"\n",
"Rozpatrzmy przypadek, gdy nadawca rzuca ośmiościenną kością. Aby przekazać\n",
"wynik, potrzebuje wówczas 3 bity (a więc entropia ośmiościennej kości\n",
"wynosi 3 bity). Przykładowe kodowanie może mieć następującą postać:\n",
"\n",
"| Wynik|Kodowanie|\n",
"|---|---|\n",
"| 1|001|\n",
"| 2|010|\n",
"| 3|011|\n",
"| 4|100|\n",
"| 5|101|\n",
"| 6|110|\n",
"| 7|111|\n",
"| 8|000|\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obliczenie entropii — trudniejszy przykład\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Załóżmy, że $\\Sigma = \\{A, B, C, D\\}$, natomiast poszczególne komunikaty\n",
"są losowane zgodnie z następującym rozkładem prawdopodobieństwa:\n",
"$P(A)=1/2$, $P(B)=1/4$, $P(C)=1/8$, $P(D)=1/8$. Ile wynosi entropia w\n",
"takim przypadku? Można by sądzić, że 2, skoro wystarczą 2 bity do\n",
"przekazania wyniku losowania przy zastosowaniu następującego kodowania:\n",
"\n",
"| Wynik|Kodowanie|\n",
"|---|---|\n",
"| A|00|\n",
"| B|01|\n",
"| C|10|\n",
"| D|11|\n",
"\n",
"Problem w tym, że w rzeczywistości nie jest to *optymalne* kodowanie.\n",
"Możemy sprytnie zmniejszyć średnią liczbę bitów wymaganych do\n",
"przekazania losowego wyniku przypisując częstszym wynikom krótsze\n",
"kody, rzadszym zaś — dłuższe. Oto takie optymalne kodowanie:\n",
"\n",
"| Wynik|Kodowanie|\n",
"|---|---|\n",
"| A|0|\n",
"| B|10|\n",
"| C|110|\n",
"| D|111|\n",
"\n",
"Używając takiego kodowanie średnio potrzebujemy:\n",
"\n",
"$$\\frac{1}{2}1 + \\frac{1}{4}2 + \\frac{1}{8}3 + \\frac{1}{8}3 = 1,75$$\n",
"\n",
"bita. Innymi słowy, entropia takiego źródła wynosi 1,75 bita.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Kodowanie musi być jednoznaczne!\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Można by sądzić, że da się stworzyć jeszcze krótsze kodowanie dla omawianego rozkładu nierównomiernego:\n",
"\n",
"| Wynik|Kodowanie|\n",
"|---|---|\n",
"| A|0|\n",
"| B|1|\n",
"| C|01|\n",
"| D|11|\n",
"\n",
"Niestety, nie jest to właściwe rozwiązanie — kodowanie musi być\n",
"jednoznaczne nie tylko dla pojedynczego komunikatu, lecz dla całej sekwencji.\n",
"Na przykład ciąg 0111 nie jest jednoznaczny przy tym kodowaniu (ABBB czy CD?).\n",
"Podane wcześniej kodowanie spełnia warunek jednoznaczności, ciąg 0111 można odkodować tylko\n",
"jako AD.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Ogólny wzór na entropię.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Na podstawie poprzedniego przykładu można dojść do intuicyjnego wniosku, że\n",
"optymalny kod dla wyniku o prawdopodobieństwie $p$ ma długość $-\\log_2(p)$, a zatem ogólnie\n",
"entropia źródła o rozkładzie prawdopodobieństwa $\\{p_1,\\ldots,p_|\\Sigma|\\}$ wynosi:\n",
"\n",
"$$E = -\\sum_{i=1}^{|\\Sigma|} p_i\\log_2(p_i)$$.\n",
"\n",
"Zauważmy, że jest to jeden z nielicznych przypadków, gdy w nauce naturalną\n",
"podstawą logarytmu jest 2 zamiast… podstawy logarytmu naturalnego ($e$).\n",
"\n",
"Teoretycznie można mierzyć entropię używając logarytmu naturalnego\n",
"($\\ln$), jednostką entropii będzie wówczas **nat** zamiast bita,\n",
"niewiele to jednak zmienia i jest mniej poręczne i trudniejsze do interpretacji\n",
"(przynajmniej w kontekście informatyki) niż operowanie na bitach.\n",
"\n",
"****Pytanie**** Ile wynosi entropia zwykłej sześciennej kostki? Jak wygląda\n",
"optymalne kodowanie wyników rzutu taką kostką?\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Entropia dla próby Bernoulliego\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Wiemy już, że entropia dla rzutu monetą wynosi 1 bit. A jaki będzie wynik dla źle wyważonej monety?\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAHgCAYAAAA10dzkAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAA9hAAAPYQGoP6dpAABlTElEQVR4nO3deVhU9f4H8PcsDPsMsoMgi4qCKCi4YeSSS1ourVY3zbJuXvOaetvMe69l3euvW5l5S9tMr7lkVlaWlVqpKC6J4AIICCgiIIKy7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ApGc7U4rxP99fwqnCsoBAK6OGswe0R0PDwmQ3bp95q4pCL63J9PUItjHV4sXJ4RiWA93iasj6ny8fjMA3hSeQCRHpwvL8ep3qdidZpzV62yrxhO3BuOxW4LgxBY/s1ZV14C18Wew6pdMlNcal+IZ0csDC8eHopc3l48h+eD1mwHwpvAEIjm5XFmHt3/KwCcHz0JvELBRKfDI0EDMGdUDLg4c42dJLlXWYcVPGVh/8CwaDAJKBfDAoG54dmwvdOF4TZIBXr8ZAG8KTyCSA4NBYMPhHLzxYxpKq4336B0T5oUXJ4QiyJ2zei1ZdlEl/vPDKXx/sgCA8RZ8L4zvjfui/Dk+kKwar98MgDeFJxBZu9T8Mry49QQSc0oAAL29nfGPO8M4bszKHMoqxj++Pon0CxUAgP7dXPDK5HCEd9VJXBlRx+D1mwHwpvAEImtVVdeAt3dl4KN92dAbBJxs1XhmbAimDQ2Eii1DVqleb8D/4s/grZ3pqKzTQ6kAHokJxLPjesFBw7GdZF14/WYAvCk8gcga7Um/iBe/PGFaz29CX2/8884
"text/plain": [
"<matplotlib.figure.Figure>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"from math import log\n",
"import numpy as np\n",
"\n",
"def binomial_entropy(p):\n",
" return -(p * log(p, 2) + (1-p) * log(1-p, 2))\n",
"\n",
"x = list(np.arange(0.001,1,0.001))\n",
"y = [binomial_entropy(x) for x in x]\n",
"plt.figure().clear()\n",
"plt.xlabel('prawdopodobieństwo wylosowania orła')\n",
"plt.ylabel('entropia')\n",
"plt.plot(x, y)\n",
"\n",
"fname = f'02_Jezyki/binomial-entropy.png'\n",
"\n",
"plt.savefig(fname)\n",
"\n",
"fname"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Pytanie** Dla oszukańczej monety (np. dla której wypada zawsze orzeł) entropia\n",
"wynosi 0, czy to wynik zgodny z intuicją?\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Entropia a język\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Tekst w danym języku możemy traktować jako ciąg symboli (komunikatów) losowanych według jakiegoś\n",
"rozkładu prawdopodobieństwa. W tym sensie możemy mówić o entropii języka.\n",
"\n",
"Oczywiście, jak zawsze, musimy jasno stwierdzić, czym są symbole\n",
"języka: literami, wyrazami czy jeszcze jakimiś innymi jednostkami.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Pomiar entropii języka — pierwsze przybliżenie\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Załóżmy, że chcemy zmierzyć entropię języka polskiego na przykładzie\n",
"„Pana Tadeusza” — na poziomie znaków. W pierwszym przybliżeniu można\n",
"by policzyć liczbę wszystkich znaków…\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"95"
]
}
],
"source": [
"chars_in_pan_tadeusz = len(set(get_characters(pan_tadeusz)))\n",
"chars_in_pan_tadeusz"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"… założyć jednostajny rozkład prawdopodobieństwa i w ten sposób policzyć entropię:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6.569855608330948"
]
}
],
"source": [
"from math import log\n",
"\n",
"95 * (1/95) * log(95, 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Mniej rozrzutne kodowanie\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Przypomnijmy sobie jednak, że rozkład jednostek języka jest zawsze\n",
"skrajnie nierównomierny! Jeśli uwzględnić ten nierównomierny rozkład\n",
"znaków, można opracować o wiele efektywniejszy sposób zakodowania znaków składających się na „Pana Tadeusza”\n",
"(częste litery, np. „a” i „e” powinny mieć krótkie kody, a rzadkie, np. „ź” — dłuższe).\n",
"\n",
"Policzmy entropię przy takim założeniu:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.938605272823633"
]
}
],
"source": [
"from collections import Counter\n",
"from math import log\n",
"\n",
"def unigram_entropy(t):\n",
" counter = Counter(t)\n",
"\n",
" total = counter.total()\n",
" return -sum((p := count / total) * log(p, 2) for count in counter.values())\n",
"\n",
"unigram_entropy(get_characters(pan_tadeusz))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(Jak dowiemy się na kolejnym wykładzie, zastosowaliśmy tutaj **unigramowy model języka**).\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Ile wynosi entropia rękopisu Wojnicza?\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.902708104423842"
]
}
],
"source": [
"unigram_entropy(get_characters(voynich))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Rzeczywista entropia?\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"W rzeczywistości entropia jest jeszcze mniejsza, tekst nie jest\n",
"generowany przecież według rozkładu wielomianowego. Istnieją rzecz\n",
"jasna pewne zależności między znakami, np. niemożliwe, żeby po „ń”\n",
"wystąpiły litera „a” czy „e”. Na poziomie wyrazów zależności mogę mieć\n",
"jeszcze bardziej skrajny charakter, np. po wyrazie „przede” prawie na\n",
"pewno wystąpi „wszystkim”, co oznacza, że w takiej sytuacji słowo\n",
"„wszystkim” może zostać zakodowane za pomocą 0 (!) bitów.\n",
"\n",
"Można uwzględnić takie zależności i uzyskać jeszcze lepsze kodowanie,\n",
"a co za tym idzie lepsze oszacowanie entropii. (Jak wkrótce się\n",
"dowiemy, oznacza to użycie digramowego, trigramowego, etc. modelu języka).\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Rozmiar skompresowanego pliku jako przybliżenie entropii\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Celem algorytmów kompresji jest właściwie wyznaczanie efektywnych\n",
"sposobów kodowania danych. Możemy więc użyć rozmiaru skompresowanego pliku w bitach\n",
"(po podzieleniu przez oryginalną długość) jako dobrego przybliżenia entropii.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.673019884633768"
]
}
],
"source": [
"import zlib\n",
"\n",
"def entropy_by_compression(t):\n",
" compressed = zlib.compress(t.encode('utf-8'))\n",
" return 8 * len(compressed) / len(t)\n",
"\n",
"entropy_by_compression(pan_tadeusz)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Dla porównania wynik dla rękopisu Wojnicza:\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2.942372881355932"
]
}
],
"source": [
"entropy_by_compression(voynich)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Gra Shannona\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Innym sposobem oszacowania entropii tekstu jest użycie… ludzi. Można poprosić rodzimych użytkowników\n",
"danego języka o przewidywanie kolejnych liter (bądź wyrazów) i w ten sposób oszacować entropię.\n",
"\n",
"**Projekt** Zaimplementuj aplikację webową, która umożliwi „rozegranie” gry Shannona.\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.10.2"
},
"org": null
},
"nbformat": 4,
"nbformat_minor": 1
}