Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 66 additions & 61 deletions asg2/Assignment 2 work-sheet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def uniFreq():\n",
Expand Down Expand Up @@ -51,10 +49,8 @@
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Function Definition starts with def <function name> (<input arguments>)\n",
Expand Down Expand Up @@ -94,16 +90,15 @@
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.866666666667\n"
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-3-48060c6bb643>, line 2)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-3-48060c6bb643>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m print jaro_winkler('bimal','vimal')\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
]
}
],
Expand Down Expand Up @@ -140,10 +135,8 @@
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -158,7 +151,7 @@
"0.6666666666666666"
]
},
"execution_count": 25,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -170,7 +163,7 @@
" bi = biDict[bigramWord1]\n",
" uni = uniDict[word1]\n",
"\n",
" print bi,uni\n",
" print(bi,uni)\n",
"\n",
" bigramProb = bi/(uni*1.0)\n",
" return bigramProb\n",
Expand All @@ -187,42 +180,40 @@
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.00980244307043 <s> sandip\n",
"0.00905109489051 sandip babu\n",
"0.000149075730471 babu sang\n",
"0.000150784077201 sang bande\n",
"0.00584883023395 bande mataram\n",
"0.000149970005999 mataram </s>\n",
"0.000150806816468 </s>\n",
"1.74932821106e-18\n",
"0.000904840898809 <s> chandranath\n",
"0.00180695678362 chandranath babu\n",
"0.000149075730471 babu asked\n",
"0.0001495215311 asked for\n",
"0.009802443070426783 <s> sandip\n",
"0.009051094890510949 sandip babu\n",
"0.0001490757304710793 babu sang\n",
"0.00015078407720144752 sang bande\n",
"0.005848830233953209 bande mataram\n",
"0.00014997000599880023 mataram </s>\n",
"</s>\n",
"1.7493282110562895e-18\n",
"0.0009048408988086261 <s> chandranath\n",
"0.0018069567836169252 chandranath babu\n",
"0.0001490757304710793 babu asked\n",
"0.00014952153110047846 asked for\n",
"for\n",
"0.000301477238468 betel leaves\n",
"0.000150625094141 leaves </s>\n",
"0.000150806816468 </s>\n",
"1.65494105455e-21\n",
"0.00120645453174 <s> poor\n",
"0.00045051809581 poor bimala\n",
"0.000297707651087 bimala went\n",
"0.00014905351021 went to\n",
"0.000150693188668 to the\n",
"0.000150715900528 the dressing\n",
"0.00105342362679 dressing room\n",
"0.000148345942738 room </s>\n",
"0.000150806816468 </s>\n",
"8.56025744882e-29\n"
"0.00030147723846849563 betel leaves\n",
"0.00015062509414068384 leaves </s>\n",
"</s>\n",
"1.6549410545482572e-21\n",
"0.0012064545317448348 <s> poor\n",
"0.0004505180958101817 poor bimala\n",
"0.00029770765108663293 bimala went\n",
"0.00014905351021016544 went to\n",
"0.0001506931886678722 to the\n",
"0.00015071590052750564 the dressing\n",
"0.001053423626787058 dressing room\n",
"0.0001483459427384661 room </s>\n",
"</s>\n",
"8.560257448823198e-29\n"
]
}
],
Expand All @@ -234,35 +225,49 @@
" mult = 1.0\n",
" for i,item in enumerate(stri.split(' ')):\n",
" try:\n",
" print (wordBigram[item+' '+stri.split()[i+1]] + 1)/((wordFreq[item] + len(wordFreq.keys()))*1.0),item+' '+stri.split()[i+1]\n",
" print ((wordBigram[item+' '+stri.split()[i+1]] + 1)/((wordFreq[item] + len(wordFreq.keys()))*1.0),item+' '+stri.split()[i+1])\n",
" mult = mult * (wordBigram[item+' '+stri.split()[i+1]] + 1)/((wordFreq[item] + len(wordFreq.keys()))*1.0)\n",
" except:\n",
" try:\n",
" print (1)/((wordFreq[item] + len(wordFreq.keys()))*1.0),item+' '+stri.split()[i+1]\n",
" print((1)/((wordFreq[item] + len(wordFreq.keys()))*1.0),item+' '+stri.split()[i+1])\n",
" mult = mult * (1)/((wordFreq[item] + len(wordFreq.keys()))*1.0)\n",
" except:\n",
" print item\n",
" print mult"
" print(item)\n",
" print( mult)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down
Loading