This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add start of sentence token to dict.py #221
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dc7f752
minor comment and print statement fixes
Henry-E d4acdd4
Merge branch 'master' of https://github.com/facebookresearch/ParlAI
Henry-E 973d53d
add start of sentence token to dict.py
Henry-E 8a0e4aa
return original order of special tokens; change names of start and en…
Henry-E 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,8 +71,9 @@ class DictionaryAgent(Agent): | |
default_maxngram = -1 | ||
default_minfreq = 0 | ||
default_null = '__NULL__' | ||
default_eos = '__EOS__' | ||
default_unk = '__UNK__' | ||
default_eos = '__EOS__' | ||
default_go = '__GO__' | ||
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. maybe having a START and an END is better? 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. So SOS instead of GO throughout? I was following the Tensor flow seq2seq tutorial but I'm happy to go with it 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. Thanks for the addition Henry! Can you change GO to START and EOS to END? slightly more generic names I guess / they match each other better |
||
|
||
@staticmethod | ||
def add_cmdline_args(argparser): | ||
|
@@ -100,12 +101,15 @@ def add_cmdline_args(argparser): | |
dictionary.add_argument( | ||
'--dict-nulltoken', default=DictionaryAgent.default_null, | ||
help='empty token, can be used for padding or just empty values') | ||
dictionary.add_argument( | ||
'--dict-unktoken', default=DictionaryAgent.default_unk, | ||
help='token to return for unavailable words') | ||
dictionary.add_argument( | ||
'--dict-eostoken', default=DictionaryAgent.default_eos, | ||
help='token for end of sentence markers, if needed') | ||
dictionary.add_argument( | ||
'--dict-unktoken', default=DictionaryAgent.default_unk, | ||
help='token to return for unavailable words') | ||
'--dict-gotoken', default=DictionaryAgent.default_go, | ||
help='token for starting sentence generation, if needed') | ||
dictionary.add_argument( | ||
'--dict-maxexs', default=100000, type=int, | ||
help='max number of examples to build dict on') | ||
|
@@ -115,8 +119,9 @@ def __init__(self, opt, shared=None): | |
# initialize fields | ||
self.opt = copy.deepcopy(opt) | ||
self.null_token = opt['dict_nulltoken'] | ||
self.eos_token = opt['dict_eostoken'] | ||
self.unk_token = opt['dict_unktoken'] | ||
self.eos_token = opt['dict_eostoken'] | ||
self.go_token = opt['dict_gotoken'] | ||
self.max_ngram_size = opt['dict_max_ngram_size'] | ||
|
||
if shared: | ||
|
@@ -132,17 +137,23 @@ def __init__(self, opt, shared=None): | |
self.tok2ind[self.null_token] = 0 | ||
self.ind2tok[0] = self.null_token | ||
|
||
if self.unk_token: | ||
# set special unknown word token | ||
index = len(self.tok2ind) | ||
self.tok2ind[self.unk_token] = index | ||
self.ind2tok[index] = self.unk_token | ||
|
||
if self.eos_token: | ||
# set special end of sentence token | ||
# set special end of sentence word token | ||
index = len(self.tok2ind) | ||
self.tok2ind[self.eos_token] = index | ||
self.ind2tok[index] = self.eos_token | ||
|
||
if self.unk_token: | ||
# set special unknown word token | ||
if self.go_token: | ||
# set special start of sentence word token | ||
index = len(self.tok2ind) | ||
self.tok2ind[self.unk_token] = index | ||
self.ind2tok[index] = self.unk_token | ||
self.tok2ind[self.go_token] = index | ||
self.ind2tok[index] = self.go_token | ||
|
||
if opt.get('dict_file') and os.path.isfile(opt['dict_file']): | ||
# load pre-existing dictionary | ||
|
@@ -164,13 +175,17 @@ def __init__(self, opt, shared=None): | |
|
||
if not shared: | ||
|
||
if self.null_token: | ||
# fix count for null token to one billion and two | ||
self.freq[self.null_token] = 1000000002 | ||
if self.go_token: | ||
# fix count for start of sentence token to one billion and three | ||
self.freq[self.go_token] = 1000000003 | ||
|
||
if self.eos_token: | ||
# fix count for end of sentence token to one billion and one | ||
self.freq[self.eos_token] = 1000000001 | ||
# fix count for end of sentence token to one billion and two | ||
self.freq[self.eos_token] = 1000000002 | ||
|
||
if self.null_token: | ||
# fix count for null token to one billion and one | ||
self.freq[self.null_token] = 1000000001 | ||
|
||
if self.unk_token: | ||
# fix count for unknown token to one billion | ||
|
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.
don't think it's a good idea to change the existing order..
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.
ok will undo that