Skip to content
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

Rename word2vec_helpers.py to word2vec_helpers9.28.py #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions word2vec_helpers9.28.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def padding_sentences(input_sentences, padding_token, padding_sentence_length = None):
# sentences = [sentence.split(' ') for sentence in input_sentences]
padding_sentences=[]
#input_sentences为每一句话构成的列表而构成的列表
if padding_sentence_length is not None:
max_sentence_length = padding_sentence_length
else:
max_sentence_length = max([len(sentence) for sentence in input_sentences])
# max_sentence_length = padding_sentence_length if padding_sentence_length is not None else max([len(sentence) for sentence in input_sentences])
for sentence in input_sentences:
#如果句子长度大于给定的长度最大值,则取前max_sentence_length个字符
if len(sentence) > max_sentence_length:
sentence = sentence[:max_sentence_length]
else:
#如果句子长度小于给定的长度最大值,则用给定的字符将原句填充到最大长度
sentence.extend([padding_token] * (max_sentence_length - len(sentence)))
padding_sentences.append(sentence)
return padding_sentences, max_sentence_length