mirror of
https://github.com/rasbt/LLMs-from-scratch.git
synced 2025-08-28 18:40:01 +00:00
More pythonic way to find the longest sequence (#512)
* More pythonic way to find the longest sequence * pep8 fix
This commit is contained in:
parent
c1c10c89c8
commit
7e2092dd01
@ -451,6 +451,9 @@ class SpamDataset(Dataset):
|
||||
if encoded_length > max_length:
|
||||
max_length = encoded_length
|
||||
return max_length
|
||||
# Note: A more pythonic version to implement this method
|
||||
# is the following, which is also used in the next chapter:
|
||||
# return max(len(encoded_text) for encoded_text in self.encoded_texts)
|
||||
|
||||
|
||||
@torch.no_grad() # Disable gradient tracking for efficiency
|
||||
|
@ -777,7 +777,10 @@
|
||||
" encoded_length = len(encoded_text)\n",
|
||||
" if encoded_length > max_length:\n",
|
||||
" max_length = encoded_length\n",
|
||||
" return max_length"
|
||||
" return max_length\n",
|
||||
" # Note: A more pythonic version to implement this method\n",
|
||||
" # is the following, which is also used in the next chapter:\n",
|
||||
" # return max(len(encoded_text) for encoded_text in self.encoded_texts)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -132,6 +132,9 @@ class SpamDataset(Dataset):
|
||||
if encoded_length > max_length:
|
||||
max_length = encoded_length
|
||||
return max_length
|
||||
# Note: A more pythonic version to implement this method
|
||||
# is the following, which is also used in the next chapter:
|
||||
# return max(len(encoded_text) for encoded_text in self.encoded_texts)
|
||||
|
||||
|
||||
def calc_accuracy_loader(data_loader, model, device, num_batches=None):
|
||||
|
@ -94,6 +94,9 @@ class SpamDataset(Dataset):
|
||||
if encoded_length > max_length:
|
||||
max_length = encoded_length
|
||||
return max_length
|
||||
# Note: A more pythonic version to implement this method
|
||||
# is the following, which is also used in the next chapter:
|
||||
# return max(len(encoded_text) for encoded_text in self.encoded_texts)
|
||||
|
||||
|
||||
def download_and_unzip(url, zip_path, extract_to, new_file_path):
|
||||
|
@ -51,6 +51,9 @@ class SpamDataset(Dataset):
|
||||
if encoded_length > max_length:
|
||||
max_length = encoded_length
|
||||
return max_length
|
||||
# Note: A more pythonic version to implement this method
|
||||
# is the following, which is also used in the next chapter:
|
||||
# return max(len(encoded_text) for encoded_text in self.encoded_texts)
|
||||
|
||||
|
||||
def download_and_unzip(url, zip_path, extract_to, new_file_path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user