Mask
DiscreteMaskedPrior
Bases: DiscretePriorDistribution
表示离散 Masked 先验分布的子类。
源代码在 bionemo/moco/distributions/prior/discrete/mask.py
中
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
__init__(num_classes=10, mask_dim=None, inclusive=True)
离散 Masked 先验分布。
关于如何定义这个问题,我想到了 3 种很难整合在一起的方法。
- [..., M, ....] 包含任何位置 --> 现有的 LLM 标记器,其中 mask 具有特定位置,而不是在末尾
- [......, M] 包含在末尾 --> mask_dim = None,且 inclusive 设置为 True 默认粘在末尾
- [.....] + [M] 独占 --> 类别的数量表示数据类别的数量,并且希望添加一个单独的 MASK 维度。
- 请注意,提供了 pad_sample 函数来帮助添加这个额外的外部维度。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
num_classes
|
int
|
分布中的类别数量。默认为 10。 |
10
|
mask_dim
|
int
|
mask 令牌的索引。如果 inclusive 为 True,则默认为 num_classes - 1;如果 exclusive 为 True,则默认为 num_classes。 |
None
|
inclusive
|
bool
|
mask 是否包含在指定的类别数量中。如果为 True,则将 mask 视为其中一个类别。如果为 False,则将 mask 视为一个额外的类别。默认为 True。 |
True
|
源代码在 bionemo/moco/distributions/prior/discrete/mask.py
中
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
is_masked(sample)
创建一个 mask,用于指示状态是否被 mask。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
sample
|
Tensor
|
要检查的样本。 |
必需 |
返回值
名称 | 类型 | 描述 |
---|---|---|
Tensor |
Tensor
|
一个浮点张量,指示样本是否被 mask。 |
源代码在 bionemo/moco/distributions/prior/discrete/mask.py
中
88 89 90 91 92 93 94 95 96 97 |
|
pad_sample(sample)
沿最后一个维度用零填充输入样本。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
sample
|
Tensor
|
要填充的输入样本。 |
必需 |
返回值
名称 | 类型 | 描述 |
---|---|---|
Tensor |
Tensor
|
填充后的样本。 |
源代码在 bionemo/moco/distributions/prior/discrete/mask.py
中
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
sample(shape, mask=None, device='cpu', rng_generator=None)
生成指定数量的样本。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
shape
|
Tuple
|
要生成的样本的形状。 |
必需 |
device
|
str
|
cpu 或 gpu。 |
'cpu'
|
mask
|
Optional[Tensor]
|
一个可选的 mask,用于应用于样本。默认为 None。 |
None
|
rng_generator
|
Optional[Generator]
|
一个可选的 :class: |
None
|
返回值
名称 | 类型 | 描述 |
---|---|---|
Float |
Tensor
|
样本张量。 |
源代码在 bionemo/moco/distributions/prior/discrete/mask.py
中
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|