tkitAutoMask
自动构建掩码 加入多种动态掩码合集,上下三角和动态片段,以及默认的概率
pip install tkitAutoMask
from tkitAutoMask import autoMask
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained("uer/chinese_roberta_L-2_H-128")
# dir(tokenizer)
tomask = autoMask(
# transformer,
mask_token_id = tokenizer.mask_token_id, # the token id reserved for masking
pad_token_id = tokenizer.pad_token_id, # the token id for padding
mask_prob = 0.05, # masking probability for masked language modeling
replace_prob = 0.90, # ~10% probability that token will not be masked, but included in loss, as detailed in the epaper
mask_ignore_token_ids = [tokenizer.cls_token_id,tokenizer.eos_token_id] # other tokens to exclude from masking, include the [cls] and [sep] here
)
x=torch.ones(5,5)
for i in range(100):
a,b=tomask(x)
# a,b
print(b)
tensor([[1., 1., 1., 0., 1.],
[0., 1., 1., 1., 0.],
[0., 0., 1., 1., 1.],
[0., 0., 0., 1., 1.],
[0., 1., 0., 0., 1.]])
tensor([[1., 1., 0., 0., 0.],
[0., 1., 1., 0., 0.],
[1., 0., 1., 1., 0.],
[0., 1., 0., 1., 1.],
[0., 0., 0., 0., 1.]])
tensor([[1., 1., 1., 0., 1.],
[0., 1., 1., 1., 0.],
[0., 1., 1., 1., 1.],
[1., 0., 0., 1., 1.],
[0., 0., 0., 1., 1.]])
tensor([[0., 0., 1., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 1., 0., 0., 0.],
[0., 1., 0., 0., 0.]])
tensor([[1., 1., 1., 0., 0.],
[0., 1., 1., 1., 0.],
[1., 0., 1., 1., 1.],
[0., 1., 0., 1., 1.],
[0., 0., 0., 1., 1.]])
tensor([[0., 0., 0., 1., 0.],
[0., 1., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 1., 0., 0.]])
tensor([[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.],
[1., 0., 0., 0., 1.],
[1., 1., 0., 0., 0.],
[1., 1., 1., 0., 1.]])
tensor([[1., 0., 0., 0., 0.],
[0., 0., 0., 1., 0.],
[1., 0., 0., 0., 0.],
[1., 1., 0., 0., 0.],
[1., 1., 1., 0., 0.]])
其他测试
https://colab.research.google.com/drive/1CvkoJ1pZQDRWGPA-5IzJufvocBM-RVT2#scrollTo=UwkociF5ZF-d
详细参考
dev.md
Metadata
Release files for tkitAutoMask 0.0.0.116347453
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tkitAutoMask-0.0.0.116347453.tar.gz | 9.6 kB | Without provenance | Details for tkitAutoMask-0.0.0.116347453.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tkitAutoMask-0.0.0.116347453-py3-none-any.whl | Python 3 | none | any | Details for tkitAutoMask-0.0.0.116347453-py3-none-any.whl |
Total release size: 18.7 kB
Release files / tkitAutoMask-0.0.0.116347453.tar.gz
| Download URL | tkitAutoMask-0.0.0.116347453.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
daf7e88fbdc83b3c7d359f8fe76c445c298e2823950ce3a7c4bb83c6b98a4509
|
|
BLAKE2b-256 checksum How to use checksums |
ee2414d2bcb6b66c756a9306b170c395406d5dbac219b0fc9865ac061e400981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / tkitAutoMask-0.0.0.116347453-py3-none-any.whl
| Download URL | tkitAutoMask-0.0.0.116347453-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
852dbddc4ac102c176ab7b69d7b3e03b969e7f27e149095dd4e39615f14eef86
|
|
BLAKE2b-256 checksum How to use checksums |
260b67f65d1d1d1cf206108ad68025ec98938d531dbaf8569622aba7d81117ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Security for tkitAutoMask 0.0.0.116347453
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.