Skip to content
Open
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
20 changes: 12 additions & 8 deletions Chapter09_NaturalLanguages.ipynb
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,7 @@
"from bs4 import BeautifulSoup\n",
"import re\n",
"import string\n",
"from collections import Counter\n",
"from collections import Counter, defaultdict\n",
"\n",
"def cleanSentence(sentence):\n",
" sentence = sentence.split(' ')\n",
Expand DownExpand Up@@ -187,13 +187,8 @@
" # Filter out empty words\n",
" words = [word for word in words if word != '']\n",
"\n",
" wordDict = {}\n",
" wordDict = defaultdict(lambda: defaultdict(int))\n",
" for i in range(1, len(words)):\n",
" if words[i-1] not in wordDict:\n",
" # Create a new dictionary for this word\n",
" wordDict[words[i-1]] ={}\n",
" if words[i] not in wordDict[words[i-1]]:\n",
" wordDict[words[i-1]][words[i]] = 0\n",
" wordDict[words[i-1]][words[i]] += 1\n",
" return wordDict\n",
"\n",
Expand DownExpand Up@@ -305,8 +300,17 @@
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
},
"pycharm":{
"stem_cell":{
"cell_type": "raw",
"source": [],
"metadata":{
"collapsed": false
}
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}