Skip to content

Commit 761d6c2

Browse files
author
Svetlana Karslioglu
committed
Update pyspelling for all beginner tutorials in Python
1 parent ea3d6ae commit 761d6c2

File tree

5 files changed

+110
-68
lines changed

5 files changed

+110
-68
lines changed

.pyspelling.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
spellchecker: aspell
22
matrix:
3-
- name: beginner
3+
- name: python
44
sources:
55
- beginner_source/data_loading_tutorial.py
6+
- beginner_source/chatbot_tutorial.py
67
dictionary:
78
wordlists:
8-
- tutorials-wordlist.txt
9+
- en-wordlist.txt
910
pipeline:
1011
- pyspelling.filters.python:
1112
group_comments: true
@@ -23,3 +24,4 @@ matrix:
2324
ignores:
2425
- code
2526
- pre
27+
- pyspelling.filters.url:

beginner_source/chatbot_tutorial.py

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,28 @@
3131
# :align: center
3232
# :alt: bot
3333
#
34-
# .. code:: python
35-
#
36-
# > hello?
37-
# Bot: hello .
38-
# > where am I?
39-
# Bot: you re in a hospital .
40-
# > who are you?
41-
# Bot: i m a lawyer .
42-
# > how are you doing?
43-
# Bot: i m fine .
44-
# > are you my friend?
45-
# Bot: no .
46-
# > you're under arrest
47-
# Bot: i m trying to help you !
48-
# > i'm just kidding
49-
# Bot: i m sorry .
50-
# > where are you from?
51-
# Bot: san francisco .
52-
# > it's time for me to leave
53-
# Bot: i know .
54-
# > goodbye
55-
# Bot: goodbye .
34+
# .. code-block:: python
35+
#
36+
# > hello?
37+
# Bot: hello .
38+
# > where am I?
39+
# Bot: you re in a hospital .
40+
# > who are you?
41+
# Bot: i m a lawyer .
42+
# > how are you doing?
43+
# Bot: i m fine .
44+
# > are you my friend?
45+
# Bot: no .
46+
# > you're under arrest
47+
# Bot: i m trying to help you !
48+
# > i'm just kidding
49+
# Bot: i m sorry .
50+
# > where are you from?
51+
# Bot: san francisco .
52+
# > it's time for me to leave
53+
# Bot: i know .
54+
# > goodbye
55+
# Bot: goodbye .
5656
#
5757
# **Tutorial Highlights**
5858
#
@@ -65,7 +65,7 @@
6565
# - Implement greedy-search decoding module
6666
# - Interact with trained chatbot
6767
#
68-
# **Acknowledgements**
68+
# **Acknowledgments**
6969
#
7070
# This tutorial borrows code from the following sources:
7171
#
@@ -75,7 +75,7 @@
7575
# 2) Sean Robertson’s practical-pytorch seq2seq-translation example:
7676
# https://github.com/spro/practical-pytorch/tree/master/seq2seq-translation
7777
#
78-
# 3) FloydHub’s Cornell Movie Corpus preprocessing code:
78+
# 3) FloydHub Cornell Movie Corpus preprocessing code:
7979
# https://github.com/floydhub/textutil-preprocess-cornell-movie-corpus
8080
#
8181

@@ -162,11 +162,11 @@ def printLines(file, n=10):
162162
# contains a tab-separated *query sentence* and a *response sentence* pair.
163163
#
164164
# The following functions facilitate the parsing of the raw
165-
# *utterances.jsonl* data file.
165+
# ``utterances.jsonl`` data file.
166166
#
167167
# - ``loadLinesAndConversations`` splits each line of the file into a dictionary of
168-
# lines with fields: lineID, characterID, and text and then groups them
169-
# into conversations with fields: conversationID, movieID, and lines.
168+
# lines with fields: ``lineID``, ``characterID``, and text and then groups them
169+
# into conversations with fields: ``conversationID``, ``movieID``, and lines.
170170
# - ``extractSentencePairs`` extracts pairs of sentences from
171171
# conversations
172172
#
@@ -215,7 +215,7 @@ def extractSentencePairs(conversations):
215215

216216
######################################################################
217217
# Now we’ll call these functions and create the file. We’ll call it
218-
# *formatted_movie_lines.txt*.
218+
# ``formatted_movie_lines.txt``.
219219
#
220220

221221
# Define path to new file
@@ -359,12 +359,12 @@ def readVocs(datafile, corpus_name):
359359
voc = Voc(corpus_name)
360360
return voc, pairs
361361

362-
# Returns True iff both sentences in a pair 'p' are under the MAX_LENGTH threshold
362+
# Returns True if both sentences in a pair 'p' are under the MAX_LENGTH threshold
363363
def filterPair(p):
364364
# Input sequences need to preserve the last word for EOS token
365365
return len(p[0].split(' ')) < MAX_LENGTH and len(p[1].split(' ')) < MAX_LENGTH
366366

367-
# Filter pairs using filterPair condition
367+
# Filter pairs using the ``filterPair`` condition
368368
def filterPairs(pairs):
369369
return [pair for pair in pairs if filterPair(pair)]
370370

@@ -659,7 +659,7 @@ def __init__(self, hidden_size, embedding, n_layers=1, dropout=0):
659659
self.hidden_size = hidden_size
660660
self.embedding = embedding
661661

662-
# Initialize GRU; the input_size and hidden_size params are both set to 'hidden_size'
662+
# Initialize GRU; the input_size and hidden_size parameters are both set to 'hidden_size'
663663
# because our input size is a word embedding with number of features == hidden_size
664664
self.gru = nn.GRU(hidden_size, hidden_size, n_layers,
665665
dropout=(0 if n_layers == 1 else dropout), bidirectional=True)
@@ -958,7 +958,7 @@ def train(input_variable, lengths, target_variable, mask, max_target_len, encode
958958
input_variable = input_variable.to(device)
959959
target_variable = target_variable.to(device)
960960
mask = mask.to(device)
961-
# Lengths for rnn packing should always be on the cpu
961+
# Lengths for RNN packing should always be on the CPU
962962
lengths = lengths.to("cpu")
963963

964964
# Initialize variables
@@ -1007,7 +1007,7 @@ def train(input_variable, lengths, target_variable, mask, max_target_len, encode
10071007
print_losses.append(mask_loss.item() * nTotal)
10081008
n_totals += nTotal
10091009

1010-
# Perform backpropatation
1010+
# Perform backpropagation
10111011
loss.backward()
10121012

10131013
# Clip gradients: gradients are modified in place
@@ -1032,8 +1032,8 @@ def train(input_variable, lengths, target_variable, mask, max_target_len, encode
10321032
# lifting with the ``train`` function.
10331033
#
10341034
# One thing to note is that when we save our model, we save a tarball
1035-
# containing the encoder and decoder state_dicts (parameters), the
1036-
# optimizers’ state_dicts, the loss, the iteration, etc. Saving the model
1035+
# containing the encoder and decoder ``state_dicts`` (parameters), the
1036+
# optimizers’ ``state_dicts``, the loss, the iteration, etc. Saving the model
10371037
# in this way will give us the ultimate flexibility with the checkpoint.
10381038
# After loading a checkpoint, we will be able to use the model parameters
10391039
# to run inference, or we can continue training right where we left off.
@@ -1240,8 +1240,8 @@ def evaluateInput(encoder, decoder, searcher, voc):
12401240
# Configure models
12411241
model_name = 'cb_model'
12421242
attn_model = 'dot'
1243-
#attn_model = 'general'
1244-
#attn_model = 'concat'
1243+
#``attn_model = 'general'``
1244+
#``attn_model = 'concat'``
12451245
hidden_size = 500
12461246
encoder_n_layers = 2
12471247
decoder_n_layers = 2
@@ -1251,12 +1251,17 @@ def evaluateInput(encoder, decoder, searcher, voc):
12511251
# Set checkpoint to load from; set to None if starting from scratch
12521252
loadFilename = None
12531253
checkpoint_iter = 4000
1254-
#loadFilename = os.path.join(save_dir, model_name, corpus_name,
1255-
# '{}-{}_{}'.format(encoder_n_layers, decoder_n_layers, hidden_size),
1256-
# '{}_checkpoint.tar'.format(checkpoint_iter))
12571254

1255+
#############################################################
1256+
# Sample code to load from a checkpoint:
1257+
#
1258+
# .. code-block:: python
1259+
#
1260+
# loadFilename = os.path.join(save_dir, model_name, corpus_name,
1261+
# '{}-{}_{}'.format(encoder_n_layers, decoder_n_layers, hidden_size),
1262+
# '{}_checkpoint.tar'.format(checkpoint_iter))
12581263

1259-
# Load model if a loadFilename is provided
1264+
# Load model if a ``loadFilename`` is provided
12601265
if loadFilename:
12611266
# If loading on same machine the model was trained on
12621267
checkpoint = torch.load(loadFilename)
@@ -1319,7 +1324,7 @@ def evaluateInput(encoder, decoder, searcher, voc):
13191324
encoder_optimizer.load_state_dict(encoder_optimizer_sd)
13201325
decoder_optimizer.load_state_dict(decoder_optimizer_sd)
13211326

1322-
# If you have cuda, configure cuda to call
1327+
# If you have CUDA, configure CUDA to call
13231328
for state in encoder_optimizer.state.values():
13241329
for k, v in state.items():
13251330
if isinstance(v, torch.Tensor):
@@ -1344,7 +1349,7 @@ def evaluateInput(encoder, decoder, searcher, voc):
13441349
# To chat with your model, run the following block.
13451350
#
13461351

1347-
# Set dropout layers to eval mode
1352+
# Set dropout layers to ``eval`` mode
13481353
encoder.eval()
13491354
decoder.eval()
13501355

dictionary.dic

2.31 KB
Binary file not shown.

en-wordlist.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Kuei
2+
Chatbots
3+
helpdesk
4+
helpdesks
5+
FloydHub’s
6+
FloydHub
7+
datafile
8+
Unescape
9+
parallelization
10+
RNNs
11+
EOS
12+
NaN
13+
Bahdanau
14+
num
15+
eq
16+
Luong
17+
thresholding
18+
Goodfellow
19+
et
20+
al
21+
softmax
22+
Iteratively
23+
Initializations
24+
RNN
25+
backpropagation
26+
GRU
27+
cpu
28+
loadFilename
29+
chatbot
30+
chatbot's
31+
csv
32+
CUDA
33+
DataLoaders
34+
dataloader
35+
dataset
36+
datasets
37+
dir
38+
embeddings
39+
evaluateInput
40+
imagenet
41+
io
42+
jpg
43+
ndarrays
44+
Numpy's
45+
numpy
46+
optimizers
47+
preprocess
48+
preprocessing
49+
pytorch
50+
rescale
51+
runtime
52+
th
53+
subclasses
54+
submodule
55+
tanh
56+
torchvision
57+
uncomment
58+
voc

tutorials-wordlist.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)