У этого 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'))
Я хочу выяснить, откуда эта функция.Кстати, это проект Udacity DL для генерации скриптов Simpsons.Пример проекта находится здесь: проект на github
Редактировать:
Фактически это был кортеж, который был определен и использован позже для print
print('The sentences {} to {}:'.format(*view_sentence_range))
print('\n'.join(text.split('\n')[view_sentence_range[0]:view_sentence_range[1]]))