Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/course/videos/batch_inputs_pt.ipynb
Views: 2542
Kernel: Unknown Kernel
This notebook regroups the code sample of the video below, which is a part of the Hugging Face course.
In [ ]:
Install the Transformers and Datasets libraries to run this notebook.
In [ ]:
In [ ]:
[1045, 1005, 2310, 2042, 3403, 2005, 1037, 17662, 12172, 2607, 2026, 2878, 2166, 1012]
[1045, 5223, 2023, 1012]
In [ ]:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-2-b3483c81e2fd> in <module>
4 [1045, 5223, 2023, 1012]]
5
----> 6 input_ids = torch.tensor(ids)
ValueError: expected sequence of length 14 at dim 1 (got 4)
In [ ]:
In [ ]:
0
In [ ]:
tensor([[-2.7276, 2.8789]], grad_fn=<AddmmBackward>)
tensor([[ 3.9497, -3.1357]], grad_fn=<AddmmBackward>)
tensor([[-2.7276, 2.8789],
[ 1.5444, -1.3998]], grad_fn=<AddmmBackward>)
In [ ]:
In [ ]:
tensor([[-2.7276, 2.8789]], grad_fn=<AddmmBackward>)
tensor([[ 3.9497, -3.1357]], grad_fn=<AddmmBackward>)
In [ ]:
tensor([[-2.7276, 2.8789],
[ 3.9497, -3.1357]], grad_fn=<AddmmBackward>)
In [ ]:
{'input_ids': [[101, 1045, 1005, 2310, 2042, 3403, 2005, 1037, 17662, 12172, 2607, 2026, 2878, 2166, 1012, 102], [101, 1045, 5223, 2023, 1012, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}
In [ ]: