此ipynb具有view_sentence_range()
,但是在上面的单元格或导入的helper.py
中都没有定义,因此我不知道它来自哪里。在其上方的单元格中仅导入文本数据。
我已经用Google搜索了它是否是Python库函数,并检查了helper.py
和文本文件,以防万一这是我的新手薪水之上的某种花招。
import helper
data_dir = './data/simpsons/moes_tavern_lines.txt'
text = helper.load_data(data_dir)
# Ignore notice, since we don't use it for analysing the data
text = text[81:] #skip the notice, text is a list of words?
print(text[120:150])
view_sentence_range = (0, 10)
这是helper.py
import os
import pickle
def load_data(path):
"""
Load Dataset from File
"""
input_file = os.path.join(path)
with open(input_file, "r") as f:
data = f.read()
return data
def preprocess_and_save_data(dataset_path, token_lookup, create_lookup_tables):
"""
Preprocess Text Data
"""
text = load_data(dataset_path)
# Ignore notice, since we don't use it for analysing the data
text = text[81:]
token_dict = token_lookup()
for key, token in token_dict.items():
text = text.replace(key, ' {} '.format(token))
text = text.lower()
text = text.split()
vocab_to_int, int_to_vocab = create_lookup_tables(text)
int_text = [vocab_to_int[word] for word in text]
pickle.dump((int_text, vocab_to_int, int_to_vocab, token_dict), open('preprocess.p', 'wb'))
def load_preprocess():
"""
Load the Preprocessed Training data and return them in batches of <batch_size> or less
"""
return pickle.load(open('preprocess.p', mode='rb'))
def save_params(params):
"""
Save parameters to file
"""
pickle.dump(params, open('params.p', 'wb'))
def load_params():
"""
Load parameters from file
"""
return pickle.load(open('params.p', mode='rb'))
我想找出此功能的来源。顺便说一句,这是用于Simpsons脚本生成的Udacity DL项目。这里有一个示例项目:project on github
编辑:
实际上,它是一个元组,后来被用于print
print('The sentences {} to {}:'.format(*view_sentence_range))
print('\n'.join(text.split('\n')[view_sentence_range[0]:view_sentence_range[1]]))
答案 0 :(得分:0)
@ hockeymonkey33从您的代码中,看起来view_sentence_range
用来定义一个元组而不是一个函数。
view_sentence_range =(0,10)