A set of utilities to create and manage configuration
Project description
SMASHED
Sequential MAppers for Sequences of HEterogeneous Dictionaries is a set of Python interfaces designed to apply transformations to samples in datasets, which are often implemented as sequences of dictionaries.
Example of Usage
Mappers are initialized and then applied sequentially. In the following example, we create a mapper that is applied to a samples, each containing a sequence of strings. The mappers are responsible for the following operations.
- Tokenize each sequence, cropping it to a maximum length if necessary.
- Stride sequences together to a maximum length or number of samples.
- Add padding symbols to sequences and attention masks.
- Concatenate all sequences from a stride into a single sequence.
import transformers
from smashed.interfaces.simple import (
Dataset,
TokenizerMapper,
MultiSequenceStriderMapper,
TokensSequencesPaddingMapper,
AttentionMaskSequencePaddingMapper,
SequencesConcatenateMapper,
)
tokenizer = transformers.AutoTokenizer.from_pretrained(
pretrained_model_name_or_path='bert-base-uncased',
)
mappers = [
TokenizerMapper(
input_field='sentences',
tokenizer=tokenizer,
add_special_tokens=False,
truncation=True,
max_length=80
),
MultiSequenceStriderMapper(
max_stride_count=2,
max_length=512,
tokenizer=tokenizer,
length_reference_field='input_ids'
),
TokensSequencesPaddingMapper(
tokenizer=tokenizer,
input_field='input_ids'
),
AttentionMaskSequencePaddingMapper(
tokenizer=tokenizer,
input_field='attention_mask'
),
SequencesConcatenateMapper()
]
dataset = Dataset([
{
'sentences': [
'This is a sentence.',
'This is another sentence.',
'Together, they make a paragraph.',
]
},
{
'sentences': [
'This sentence belongs to another sample',
'Overall, the dataset is made of multiple samples.',
'Each sample is made of multiple sentences.',
'Samples might have a different number of sentences.',
'And that is the story!',
]
}
])
for mapper in mappers:
dataset = mapper.map(dataset)
print(len(dataset))
# >>> 5
print(dataset[0])
# >>> {'input_ids': [101, 2023, 2003, 1037, 6251, 1012, 102, 2023, 2003, 2178, 6251, 1012, 102], 'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
Dataset Interfaces Available
The initial version of SMASHED supports two interfaces for dataset:
interfaces.simple.Dataset
: A simple dataset representation that is just a list of python dictionaries with some extra convenience methods to make it work with SMASHED. You can crate a simple dataset by passing a list of dictionaries tointerfaces.simple.Dataset
.- HuggingFace
datasets
library. SMASHED mappers work with any datasets from HuggingFace, whether it is a regular or iterable dataset.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file smashed-0.1.1.tar.gz
.
File metadata
- Download URL: smashed-0.1.1.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2594f3d824c63a83891272e67731d44fc73fd65b3f8b3cb794cad1bd5f27a73f |
|
MD5 | 54e4f371e7fc76cfd333d80c2e0e41d1 |
|
BLAKE2b-256 | 43196a187b5be687e0eb1e66631c3fdfc56d6ec63a8ff029a4f911d6c18ed667 |
File details
Details for the file smashed-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: smashed-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c6004e5716e83522e18eeb93c76f7d43313184d9a1fdee780406593a8ab9522 |
|
MD5 | 5f4e62c106fe0989d32a9d6065c0ce03 |
|
BLAKE2b-256 | 56597609ceed13f373d4ba4f2697b3195bb1b602b298f2c89c9fb9f05860dfe2 |