MCPcopy Create free account
hub / github.com/CERT-Lab/lora-sb / preprocess

Function preprocess

utils/data_utils.py:195–207  ·  view source on GitHub ↗

Preprocess the data by tokenizing.

(
        sources: Sequence[str],
        targets: Sequence[str],
        tokenizer: transformers.PreTrainedTokenizer,
)

Source from the content-addressed store, hash-verified

193 )
194
195def preprocess(
196 sources: Sequence[str],
197 targets: Sequence[str],
198 tokenizer: transformers.PreTrainedTokenizer,
199) -> Dict:
200 """Preprocess the data by tokenizing."""
201 examples = [s + t for s, t in zip(sources, targets)]
202 examples_tokenized, sources_tokenized = [_tokenize_fn(strings, tokenizer) for strings in (examples, sources)]
203 input_ids = examples_tokenized["input_ids"]
204 labels = copy.deepcopy(input_ids)
205 for label, source_len in zip(labels, sources_tokenized["input_ids_lens"]):
206 label[:source_len] = IGNORE_INDEX
207 return dict(input_ids=input_ids, labels=labels)
208
209def train_tokenize_function(examples, tokenizer, query, response):
210 sources = [PROMPT.format_map(dict(instruction=instruction)) for instruction in examples[query]]

Callers 1

train_tokenize_functionFunction · 0.85

Calls 1

_tokenize_fnFunction · 0.85

Tested by

no test coverage detected