This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| join_by () { | |
| # Argument #1 is the separator. It can be multi-character. | |
| # Argument #2, 3, and so on, are the elements to be joined. | |
| # Usage: join_by ", " "${array[@]}" | |
| local SEPARATOR="$1" | |
| shift | |
| local F=0 | |
| for x in "$@" | |
| do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| torch.einsum("blm,mn->bln", torch.randn(3, 4, 5), torch.randn(5, 6)).size() # torch.Size([3, 4, 6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (torch.randn(3, 4, 5) @ torch.randn(5, 6)).size() # torch.Size([3, 4, 6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| torch.randn(3, 4, 5).view(12, 5).mm(torch.randn(5, 6)).view(3, 4, 6).size() # torch.Size([3, 4, 6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| torch.randn(3, 4, 5).mm(torch.randn(5, 6)).size() | |
| # RuntimeError: matrices expected, got 3D, 2D tensors at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| (torch.randn(3, 4, 5).bmm(torch.randn(3, 5, 6))).size() # torch.Size([3, 4, 6]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| (torch.randn(3, 4) @ torch.randn(4, 5)).size() # torch.Size([3, 5]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| torch.mm(torch.randn(3, 4), torch.randn(4, 5)).size() # torch.Size([3, 5]) | |
| torch.randn(3, 4).mm(torch.randn(4, 5)).size() # torch.Size([3, 5]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __all__ = ["BLEUEvaluator"] | |
| import bisect | |
| import logging | |
| import collections | |
| from dataclasses import dataclass | |
| from typing import Sequence, Optional, List | |
| import torch | |
| import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Sequence | |
| import numpy as np | |
| def split_list(items: Sequence, ratios: Sequence[float]): | |
| ratios = np.cumsum(np.array(ratios) / sum(ratios)).tolist() | |
| indices = [0] + [int(round(len(items) * r)) for r in ratios] | |
| return [items[i:j] for i, j in zip(indices, indices[1:])] |
NewerOlder