def preprocessfunction(examples): Assuming examples is a dictionary with keys "context",…
- User
def preprocess_function(examples): # Assuming examples is a dictionary with keys "context", "answer", and "question"
# Check if "answer" or "context" is None, and handle accordingly if examples["answer"] is None or examples["context"] is None: return None # Ensure that "answer" is a list if not isinstance(examples["answer"], list): return None # Define the context_text using the provided format context_text = f"context: {examples['context']} answer: {examples['answer']} "
# Convert answers to a single string answers = " ".join([q.strip() if q is not None else "" for q in examples["answer"]]) inputs = tokenizer( context_text, max_length=1000, truncation=True, padding="max_length", return_offsets_mapping=True, )
# Check if "question" is None, and handle accordingly if examples["question"] is None: return None targets = tokenizer( examples["question"], max_length=64, # Adjust as needed truncation=True, padding="max_length", return_offsets_mapping=True, ) inputs["labels"] = targets["input_ids"] inputs["decoder_attention_mask"] = targets["attention_mask"] return inputs add Codeadd Markdown tokenized_train_dataset = train_dataset.map(preprocess_function, batched=True) tokenized_val_dataset = val_dataset.map(preprocess_function, batched=True) tokenized_test_dataset = test_dataset.map(preprocess_function, batched=True) 98% 41/42 [00:34<00:00, 1.27ba/s]
ArrowInvalid Traceback (most recent call last) Cell In[30], line 1 ----> 1 tokenized_train_dataset = train_dataset.map(preprocess_function, batched=True) 2 tokenized_val_dataset = val_dataset.map(preprocess_function, batched=True) 3 tokenized_test_dataset = test_dataset.map(preprocess_function, batched=True)
File /opt/conda/lib/python3.10/site-packages/datasets/arrow_dataset.py:1955, in Dataset.map(self, function, with_indices, with_rank, input_columns, batched, batch_size, drop_last_batch, remove_columns, keep_in_memory, load_from_cache_file, cache_file_name, writer_batch_size, features, disable_nullable, fn_kwargs, num_proc, suffix_template, new_fingerprint, desc) 1952 disable_tqdm = not logging.is_progress_bar_enabled() 1954 if num_proc is None or num_proc == 1: -> 1955 return self._map_single( 1956 function=function, 1957 with_indices=with_indices, 1958 with_rank=with_rank, 1959 input_columns=input_columns, 1960 batched=batched, 1961 batch_size=batch_size, 1962 drop_last_batch=drop_last_batch, 1963 remove_columns=remove_columns, 1964 keep_in_memory=keep_in_memory, 1965 load_from_cache_file=load_from_cache_file, 1966 cache_file_name=cache_file_name, 1967 writer_batch_size=writer_batch_size, 1968 features=features, 1969 disable_nullable=disable_nullable, 1970 fn_kwargs=fn_kwargs, 1971 new_fingerprint=new_fingerprint, 1972 disable_tqdm=disable_tqdm, 1973 desc=desc, 1974 ) 1975 else: 1977 def format_cache_file_name(cache_file_name, rank):
- Assistant
- User
- Assistant
- User
another way to write process function like this def preprocess_function(examples): # Assuming examples is a dictionary with keys "context", "text", and "target_answer"
# Check if "text" is None, and handle accordingly if examples["text"] is None: return None # Concatenate the elements within the lists in "context" and "text" # concatenated_context = " ".join(examples["context"]) # concatenated_text = " ".join(examples["text"]) # Ensure that "text" is a list if not isinstance(examples["text"], list): return None answers = [q.strip() if q is not None else "" for q in examples["text"]] inputs = tokenizer( examples["context"], answers, max_length=128, truncation=True, padding="max_length", return_offsets_mapping=True, ) # Check if "question" is None, and handle accordingly if examples["question"] is None: return None targets = tokenizer( examples["question"], max_length=64, # Adjust as needed truncation=True, padding="max_length", return_offsets_mapping=True, ) inputs["labels"] = targets["input_ids"] inputs["decoder_attention_mask"] = targets["attention_mask"] return inputs - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.