271 lines
6.4 KiB
Plaintext
271 lines
6.4 KiB
Plaintext
{
|
|
"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> Ekstrakcja informacji </h1>\n",
|
|
"<h2> 4. <i>Statystyczny model językowy</i> [ćwiczenia]</h2> \n",
|
|
"<h3> Jakub Pokrywka (2022)</h3>\n",
|
|
"</div>\n",
|
|
"\n",
|
|
"![Logo 2](https://git.wmi.amu.edu.pl/AITech/Szablon/raw/branch/master/Logotyp_AITech2.jpg)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 71,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"NR_INDEKSU = 375985"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"https://web.stanford.edu/~jurafsky/slp3/3.pdf"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 72,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class Model():\n",
|
|
" \n",
|
|
" def __init__(self, vocab_size, UNK_token= '<UNK>'):\n",
|
|
" pass\n",
|
|
" \n",
|
|
" def train(corpus:list) -> None:\n",
|
|
" pass\n",
|
|
" \n",
|
|
" def predict(text: list, probs: str) -> float:\n",
|
|
" pass"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 73,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def get_ppl(text: list) -> float:\n",
|
|
" pass"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 74,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"text = 'Pani Ala ma kota oraz ładnego pieska i 3 chomiki'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 75,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"text_splitted = text.split(' ')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 76,
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"['Pani', 'Ala', 'ma', 'kota', 'oraz', 'ładnego', 'pieska', 'i', '3', 'chomiki']"
|
|
]
|
|
},
|
|
"execution_count": 76,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"text_splitted"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 77,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"text_masked = text_splitted[:4] + ['<MASK>'] + text_splitted[5:]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 78,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"['Pani',\n",
|
|
" 'Ala',\n",
|
|
" 'ma',\n",
|
|
" 'kota',\n",
|
|
" '<MASK>',\n",
|
|
" 'ładnego',\n",
|
|
" 'pieska',\n",
|
|
" 'i',\n",
|
|
" '3',\n",
|
|
" 'chomiki']"
|
|
]
|
|
},
|
|
"execution_count": 78,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"text_masked"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"trigram_model działa na ['ma', 'kota', <'MASK>']"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"trigram_model.predict(['ma', 'kota']) → 'i:0.55 oraz:0.25 czarnego:0.1 :0.1'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ZADANIE:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 79,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"g1 = [470618, 415366, 434695, 470611, 470607]\n",
|
|
"g2 = [440054, 434742, 434760, 434784, 434788]\n",
|
|
"g3 = [434804, 430705, 470609, 470619, 434704]\n",
|
|
"g4 = [434708, 470629, 434732, 434749, 426206]\n",
|
|
"g5 = [434766, 470628, 437622, 434780, 470627, 440058]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 80,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"proszę zgłosić się do prowadzącego\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if NR_INDEKSU in g1:\n",
|
|
" print('model bigramowy standardowy')\n",
|
|
"elif NR_INDEKSU in g2:\n",
|
|
" print('model bigramowy odwrotny')\n",
|
|
"elif NR_INDEKSU in g3:\n",
|
|
" print('model trigramowy')\n",
|
|
"elif NR_INDEKSU in g4:\n",
|
|
" print('model trigramowy odwrotny')\n",
|
|
"elif NR_INDEKSU in g5:\n",
|
|
" print('model trigramowy ze zgadywaniem środka')\n",
|
|
"else:\n",
|
|
" print('proszę zgłosić się do prowadzącego')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### gonito:\n",
|
|
"- zapisanie do achievmentu przez start working\n",
|
|
"- send to review"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### ZADANIE\n",
|
|
"\n",
|
|
"Proszę stworzyć rozwiązanie modelu (komórka wyżej) dla https://gonito.net/challenge/challenging-america-word-gap-prediction i umieścić je na platformie gonito\n",
|
|
" \n",
|
|
"Warunki zaliczenia:\n",
|
|
"- wynik widoczny na platformie zarówno dla dev i dla test\n",
|
|
"- wynik dla dev i test lepszy (niższy) od 1024.00\n",
|
|
"- deadline do końca dnia 27.04\n",
|
|
"- commitując rozwiązanie proszę również umieścić rozwiązanie w pliku /run.py (czyli na szczycie katalogu). Można przekonwertować jupyter do pliku python przez File → Download as → Python. Rozwiązanie nie musi być w pythonie, może być w innym języku.\n",
|
|
"- zadania wykonujemy samodzielnie\n",
|
|
"- w nazwie commita podaj nr indeksu\n",
|
|
"- w tagach podaj \"n-grams\" (należy zatwierdzić przecinkiem po wybraniu tagu)!\n",
|
|
"\n",
|
|
"Uwagi:\n",
|
|
"\n",
|
|
"- nie trzeba korzystać z całego zbioru trenującego\n",
|
|
"- zadanie to 50 punktów, za najlepsze rozwiązanie w swojej grupie (g1,g2,g3,g4,g5), przyznaję dodatkowo 40 punktów\n",
|
|
"- punkty będą przyznane na gonito\n",
|
|
"- warto monitorować RAM, próbować z różnym vocab_size, można skorzystać z pythonowego Counter"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"author": "Jakub Pokrywka",
|
|
"email": "kubapok@wmi.amu.edu.pl",
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"lang": "pl",
|
|
"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.8.3"
|
|
},
|
|
"subtitle": "0.Informacje na temat przedmiotu[ćwiczenia]",
|
|
"title": "Ekstrakcja informacji",
|
|
"year": "2021"
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|