Skip to content

Commit

Permalink
Removed unclosed code block
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiopaniego committed Sep 13, 2024
1 parent de288a0 commit 8494538
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions chapters/zh-TW/chapter3/2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ DatasetDict({
<Youtube id="7q5NyFT8REg"/>

{#if fw === 'pt'}

負責在批處理中將數據整理為一個batch的函數稱為*collate函數*。它是你可以在構建**DataLoader**時傳遞的一個參數,默認是一個函數,它將把你的數據集轉換為PyTorch張量,並將它們拼接起來(如果你的元素是列表、元組或字典,則會使用遞歸)。這在我們的這個例子中下是不可行的,因為我們的輸入不是都是相同大小的。我們故意在之後每個batch上進行填充,避免有太多填充的過長的輸入。這將大大加快訓練速度,但請注意,如果你在TPU上訓練,這可能會導致問題——TPU喜歡固定的形狀,即使這需要額外的填充。

{:else}
Expand Down Expand Up @@ -321,8 +322,6 @@ samples = {k: v for k, v in samples.items() if k not in ["idx", "sentence1", "se

毫無疑問,我們得到了不同長度的樣本,從32到67。動態填充意味著該批中的所有樣本都應該填充到長度為67,這是該批中的最大長度。如果沒有動態填充,所有的樣本都必須填充到整個數據集中的最大長度,或者模型可以接受的最大長度。讓我們再次檢查**data_collator**是否正確地動態填充了這批樣本:

```py:
```py
batch = data_collator(samples)
{k: v.shape for k, v in batch.items()}
Expand Down

0 comments on commit 8494538

Please sign in to comment.