-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace open() with smart_open() in notebooks. Fix #1789 #1812
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
725efed
Replace open() with smart_open()
sharanry 872c55c
Fix in Corpora_and_Vector_Spaces.ipynb
sharanry 18a18f3
Specify read/write explicitly while calling smart_open()
sharanry 159f095
Merge branch 'develop' of https://github.com/RaRe-Technologies/gensim…
sharanry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,8 @@ | |
"from datetime import datetime\n", | ||
"\n", | ||
"from gensim.models import CoherenceModel\n", | ||
"from gensim.corpora.dictionary import Dictionary" | ||
"from gensim.corpora.dictionary import Dictionary\n", | ||
"from smart_open import smart_open" | ||
] | ||
}, | ||
{ | ||
|
@@ -114,7 +115,7 @@ | |
" # as well as pages about a single year.\n", | ||
" # As a result, this preprocessing differs from the paper.\n", | ||
" \n", | ||
" with open(os.path.join(data_dir, fname)) as f:\n", | ||
" with smart_open(os.path.join(data_dir, fname), 'rb') as f:\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a bug. If you open the file in binary mode, operations like I see the same problem in many places in this PR. |
||
" for line in f:\n", | ||
" # lower case all words\n", | ||
" lowered = line.lower()\n", | ||
|
@@ -206,7 +207,7 @@ | |
], | ||
"source": [ | ||
"topics = [] # list of 100 topics\n", | ||
"with open(topics_path) as f:\n", | ||
"with smart_open(topics_path, 'rb') as f:\n", | ||
" topics = [line.split() for line in f if line]\n", | ||
"len(topics)" | ||
] | ||
|
@@ -231,7 +232,7 @@ | |
], | ||
"source": [ | ||
"human_scores = []\n", | ||
"with open(human_scores_path) as f:\n", | ||
"with smart_open(human_scores_path, 'rb') as f:\n", | ||
" for line in f:\n", | ||
" human_scores.append(float(line.strip()))\n", | ||
"len(human_scores)" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug (not in this PR, notebook already bad): use
os.path.join
for joining filesystem paths.Also, why the change in
errors='ignore'
?