{ "metadata": { "name": "", "signature": "sha256:d514892e91439011b3eb3230f11ce497bb0b91c5eabfb8ddf0c282d8ebf07dd4" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import pandas as pd\n", "\n", "import ndl\n", "\n", "%matplotlib inline\n", "\n", "%precision 3\n", "pd.set_option('display.precision', 3)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 49 }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we'll try a strictly agglutinative morphemic alignment, with a one-to-one mapping between forms and meanings:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "morphemes = pd.DataFrame()\n", "morphemes['Cues'] = [('stem','a','c'),('stem','a','d'),('stem','b','c'),('stem','b','d')]\n", "morphemes['Outcomes'] = [('nom','sg'),('nom','pl'),('acc','sg'),('acc','pl')]\n", "morphemes['Frequency'] = [1,1,1,1]\n", "morphemes" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CuesOutcomesFrequency
0 (stem, a, c) (nom, sg) 1
1 (stem, a, d) (nom, pl) 1
2 (stem, b, c) (acc, sg) 1
3 (stem, b, d) (acc, pl) 1
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 50, "text": [ " Cues Outcomes Frequency\n", "0 (stem, a, c) (nom, sg) 1\n", "1 (stem, a, d) (nom, pl) 1\n", "2 (stem, b, c) (acc, sg) 1\n", "3 (stem, b, d) (acc, pl) 1" ] } ], "prompt_number": 50 }, { "cell_type": "markdown", "metadata": {}, "source": [ "After 1,000 learning iterations, we check the associations between the cues and the outcomes:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "W1 = ndl.rw(morphemes,M=1000)\n", "W1" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
accnomplsg
a-0.37 0.62 0.13 0.12
b 0.62-0.37 0.12 0.13
c 0.13 0.12-0.37 0.62
d 0.12 0.13 0.62-0.37
stem 0.25 0.25 0.25 0.25
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 51, "text": [ " acc nom pl sg\n", "a -0.37 0.62 0.13 0.12\n", "b 0.62 -0.37 0.12 0.13\n", "c 0.13 0.12 -0.37 0.62\n", "d 0.12 0.13 0.62 -0.37\n", "stem 0.25 0.25 0.25 0.25" ] } ], "prompt_number": 51 }, { "cell_type": "markdown", "metadata": {}, "source": [ "And, the complete forms get the right interpretation:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "pd.DataFrame([ndl.activation(c,W1) for c in morphemes.Cues],index=morphemes.Cues)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
accnomplsg
Cues
(stem, a, c) 0 1 0 1
(stem, a, d) 0 1 1 0
(stem, b, c) 1 0 0 1
(stem, b, d) 1 0 1 0
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 52, "text": [ " acc nom pl sg\n", "Cues \n", "(stem, a, c) 0 1 0 1\n", "(stem, a, d) 0 1 1 0\n", "(stem, b, c) 1 0 0 1\n", "(stem, b, d) 1 0 1 0" ] } ], "prompt_number": 52 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we'll try a paradigm with the same cues and the same outcomes, but this time they're not arrange with a one-to-one correspondence:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "gestalt = morphemes.copy()\n", "gestalt['Cues'] = [('stem','a','c'),('stem','b','c'),('stem','b','d'),('stem','a','d')]\n", "gestalt" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CuesOutcomesFrequency
0 (stem, a, c) (nom, sg) 1
1 (stem, b, c) (nom, pl) 1
2 (stem, b, d) (acc, sg) 1
3 (stem, a, d) (acc, pl) 1
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 53, "text": [ " Cues Outcomes Frequency\n", "0 (stem, a, c) (nom, sg) 1\n", "1 (stem, b, c) (nom, pl) 1\n", "2 (stem, b, d) (acc, sg) 1\n", "3 (stem, a, d) (acc, pl) 1" ] } ], "prompt_number": 53 }, { "cell_type": "code", "collapsed": false, "input": [ "W2 = ndl.rw(gestalt,M=1000)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 54 }, { "cell_type": "markdown", "metadata": {}, "source": [ "This time, the number distincton doesn't get learned:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "pd.DataFrame([ndl.activation(c,W2) for c in gestalt.Cues],index=gestalt.Cues)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
accnomplsg
Cues
(stem, a, c) 0.00 1 0.60 0.40
(stem, b, c) 0.00 1 0.64 0.36
(stem, b, d) 0.99 0 0.61 0.39
(stem, a, d) 1.00 0 0.57 0.43
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 55, "text": [ " acc nom pl sg\n", "Cues \n", "(stem, a, c) 0.00 1 0.60 0.40\n", "(stem, b, c) 0.00 1 0.64 0.36\n", "(stem, b, d) 0.99 0 0.61 0.39\n", "(stem, a, d) 1.00 0 0.57 0.43" ] } ], "prompt_number": 55 }, { "cell_type": "markdown", "metadata": {}, "source": [ "But, if we add compound cues, things work:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "gestalt2 = gestalt.copy()\n", "gestalt2['Cues'] = [('stem','a','c','a&c'),('stem','b','c','b&c'),('stem','b','d','b&d'),('stem','a','d','a&d')]\n", "gestalt2" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CuesOutcomesFrequency
0 (stem, a, c, a&c) (nom, sg) 1
1 (stem, b, c, b&c) (nom, pl) 1
2 (stem, b, d, b&d) (acc, sg) 1
3 (stem, a, d, a&d) (acc, pl) 1
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 59, "text": [ " Cues Outcomes Frequency\n", "0 (stem, a, c, a&c) (nom, sg) 1\n", "1 (stem, b, c, b&c) (nom, pl) 1\n", "2 (stem, b, d, b&d) (acc, sg) 1\n", "3 (stem, a, d, a&d) (acc, pl) 1" ] } ], "prompt_number": 59 }, { "cell_type": "code", "collapsed": false, "input": [ "W3 = ndl.rw(gestalt2,M=1000)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 64 }, { "cell_type": "code", "collapsed": false, "input": [ "pd.DataFrame([ndl.activation(c,W3) for c in gestalt2.Cues],index=gestalt2.Cues)" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
accnomplsg
Cues
(stem, a, c, a&c) 8.14e-04 1.00e+00 0.04 0.96
(stem, b, c, b&c)-4.13e-04 1.00e+00 0.95 0.05
(stem, b, d, b&d) 1.00e+00 2.06e-04 0.04 0.96
(stem, a, d, a&d) 9.99e-01 3.18e-04 0.96 0.04
\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 65, "text": [ " acc nom pl sg\n", "Cues \n", "(stem, a, c, a&c) 8.14e-04 1.00e+00 0.04 0.96\n", "(stem, b, c, b&c) -4.13e-04 1.00e+00 0.95 0.05\n", "(stem, b, d, b&d) 1.00e+00 2.06e-04 0.04 0.96\n", "(stem, a, d, a&d) 9.99e-01 3.18e-04 0.96 0.04" ] } ], "prompt_number": 65 } ], "metadata": {} } ] }